funnel extraction

- allow funnels to extract items when part of a contraption
- also include a little animation for the new backtrack button
This commit is contained in:
zelophed 2021-03-16 17:21:32 +01:00
parent e3394a8907
commit 13a4d0ca62
2 changed files with 88 additions and 18 deletions

View file

@ -1,19 +1,23 @@
package com.simibubi.create.content.logistics.block.funnel; package com.simibubi.create.content.logistics.block.funnel;
import java.util.List;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.logistics.item.filter.FilterItem;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.item.ItemHelper;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import java.util.List;
public class FunnelMovementBehaviour extends MovementBehaviour { public class FunnelMovementBehaviour extends MovementBehaviour {
private final boolean hasFilter; private final boolean hasFilter;
@ -32,14 +36,67 @@ public class FunnelMovementBehaviour extends MovementBehaviour {
@Override @Override
public Vec3d getActiveAreaOffset(MovementContext context) { public Vec3d getActiveAreaOffset(MovementContext context) {
return new Vec3d(FunnelBlock.getFunnelFacing(context.state) Direction facing = FunnelBlock.getFunnelFacing(context.state);
.getDirectionVec()).scale(.65); Vec3d vec = new Vec3d(facing.getDirectionVec());
if (facing != Direction.UP)
return vec.scale(context.state.get(FunnelBlock.EXTRACTING) ? .15 : .65);
return vec.scale(.65);
} }
@Override @Override
public void visitNewPosition(MovementContext context, BlockPos pos) { public void visitNewPosition(MovementContext context, BlockPos pos) {
super.visitNewPosition(context, pos); super.visitNewPosition(context, pos);
if (context.state.get(FunnelBlock.EXTRACTING))
extract(context, pos);
else
succ(context, pos);
}
private void extract(MovementContext context, BlockPos pos) {
World world = context.world;
Vec3d entityPos = context.position;
if (context.state.get(FunnelBlock.FACING) != Direction.DOWN)
entityPos = entityPos.add(0, -.5f, 0);
if (!world.getBlockState(pos).getCollisionShape(world, pos).isEmpty())
return;//only drop items if the target block is a empty space
if (!world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(new BlockPos(entityPos))).isEmpty())
return;//don't drop items if there already are any in the target block space
ItemStack filter = getFilter(context);
int filterAmount = context.tileData.getInt("FilterAmount");
if (filterAmount <= 0)
filterAmount = hasFilter ? AllConfigs.SERVER.logistics.defaultExtractionLimit.get() : 1;
ItemStack extract = ItemHelper.extract(
context.contraption.inventory,
s -> FilterItem.test(world, s, filter),
ItemHelper.ExtractionCountMode.UPTO,
filterAmount,
false);
if (extract.isEmpty())
return;
if (world.isRemote)
return;
ItemEntity entity = new ItemEntity(world, entityPos.x, entityPos.y, entityPos.z, extract);
entity.setMotion(Vec3d.ZERO);
entity.setPickupDelay(5);
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 1/16f, .1f);
world.addEntity(entity);
}
private void succ(MovementContext context, BlockPos pos) {
World world = context.world; World world = context.world;
List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(pos)); List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(pos));
ItemStack filter = getFilter(context); ItemStack filter = getFilter(context);
@ -61,7 +118,6 @@ public class FunnelMovementBehaviour extends MovementBehaviour {
item.setItem(remainder); item.setItem(remainder);
} }
} }
private ItemStack getFilter(MovementContext context) { private ItemStack getFilter(MovementContext context) {

View file

@ -1,13 +1,5 @@
package com.simibubi.create.foundation.ponder; package com.simibubi.create.foundation.ponder;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.mutable.MutableInt;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen;
import com.simibubi.create.foundation.gui.IScreenRenderable; import com.simibubi.create.foundation.gui.IScreenRenderable;
@ -17,11 +9,18 @@ import com.simibubi.create.foundation.ponder.content.PonderTagScreen;
import com.simibubi.create.foundation.ponder.ui.PonderButton; import com.simibubi.create.foundation.ponder.ui.PonderButton;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.animation.LerpedFloat; import com.simibubi.create.foundation.utility.animation.LerpedFloat;
import net.minecraft.client.MainWindow; import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.mutable.MutableInt;
import org.lwjgl.glfw.GLFW;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public abstract class NavigatableSimiScreen extends AbstractSimiScreen { public abstract class NavigatableSimiScreen extends AbstractSimiScreen {
@ -31,6 +30,9 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen {
public final LerpedFloat transition = LerpedFloat.linear() public final LerpedFloat transition = LerpedFloat.linear()
.startWithValue(0) .startWithValue(0)
.chase(0, .1f, LerpedFloat.Chaser.LINEAR); .chase(0, .1f, LerpedFloat.Chaser.LINEAR);
protected final LerpedFloat arrowAnimation = LerpedFloat.linear()
.startWithValue(0)
.chase(0, 0.075f, LerpedFloat.Chaser.LINEAR);
protected PonderButton backTrack; protected PonderButton backTrack;
public NavigatableSimiScreen() { public NavigatableSimiScreen() {
@ -50,6 +52,7 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen {
public void tick() { public void tick() {
super.tick(); super.tick();
transition.tickChaser(); transition.tickChaser();
arrowAnimation.tickChaser();
} }
@Override @Override
@ -90,8 +93,13 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translated(0, 0, 500); RenderSystem.translated(0, 0, 500);
if (backTrack.isHovered()) if (backTrack.isHovered()) {
drawString(font, Lang.translate(THINK_BACK), 15, height - 16, 0xffa3a3a3); drawString(font, Lang.translate(THINK_BACK), 15, height - 16, 0xffa3a3a3);
if (MathHelper.epsilonEquals(arrowAnimation.getValue(), arrowAnimation.getChaseTarget())) {
arrowAnimation.setValue(1);
arrowAnimation.setValue(1);//called twice to also set the previous value to 1
}
}
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
@ -149,8 +157,14 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen {
RenderSystem.translated(-depthPointX, -depthPointY, 0); RenderSystem.translated(-depthPointX, -depthPointY, 0);
if (backTrack != null) { if (backTrack != null) {
UIRenderHelper.breadcrumbArrow(21, height - 51, 30, 20, 5, 0x40aa9999, 0x10aa9999); int x = (int) MathHelper.lerp(arrowAnimation.getValue(partialTicks), -9, 21);
UIRenderHelper.breadcrumbArrow(-19, height - 51, 40, 20, 5, 0x40aa9999, 0x10aa9999); int maxX = backTrack.x + backTrack.getWidth();
if (x + 30 < backTrack.x)
UIRenderHelper.breadcrumbArrow(x + 30, height - 51, maxX - (x + 30), 20, 5, 0x40aa9999, 0x10aa9999);
UIRenderHelper.breadcrumbArrow(x, height - 51, 30, 20, 5, 0x40aa9999, 0x10aa9999);
UIRenderHelper.breadcrumbArrow(x - 30, height - 51, 30, 20, 5, 0x40aa9999, 0x10aa9999);
} }
} }