diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java index f6a4ceaf8..52ab6fb44 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelMovementBehaviour.java @@ -1,19 +1,23 @@ 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.MovementContext; 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.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.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.items.ItemHandlerHelper; +import java.util.List; + public class FunnelMovementBehaviour extends MovementBehaviour { private final boolean hasFilter; @@ -32,14 +36,67 @@ public class FunnelMovementBehaviour extends MovementBehaviour { @Override public Vec3d getActiveAreaOffset(MovementContext context) { - return new Vec3d(FunnelBlock.getFunnelFacing(context.state) - .getDirectionVec()).scale(.65); + Direction facing = FunnelBlock.getFunnelFacing(context.state); + 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 public void visitNewPosition(MovementContext context, BlockPos 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; List items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(pos)); ItemStack filter = getFilter(context); @@ -61,7 +118,6 @@ public class FunnelMovementBehaviour extends MovementBehaviour { item.setItem(remainder); } - } private ItemStack getFilter(MovementContext context) { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java index 4226aded7..d99d115b1 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java @@ -1,13 +1,5 @@ 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.simibubi.create.foundation.gui.AbstractSimiScreen; 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.utility.Lang; import com.simibubi.create.foundation.utility.animation.LerpedFloat; - import net.minecraft.client.MainWindow; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; 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 { @@ -31,6 +30,9 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { public final LerpedFloat transition = LerpedFloat.linear() .startWithValue(0) .chase(0, .1f, LerpedFloat.Chaser.LINEAR); + protected final LerpedFloat arrowAnimation = LerpedFloat.linear() + .startWithValue(0) + .chase(0, 0.075f, LerpedFloat.Chaser.LINEAR); protected PonderButton backTrack; public NavigatableSimiScreen() { @@ -50,6 +52,7 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { public void tick() { super.tick(); transition.tickChaser(); + arrowAnimation.tickChaser(); } @Override @@ -90,8 +93,13 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { RenderSystem.pushMatrix(); RenderSystem.translated(0, 0, 500); - if (backTrack.isHovered()) + if (backTrack.isHovered()) { 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(); } @@ -149,8 +157,14 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { RenderSystem.translated(-depthPointX, -depthPointY, 0); if (backTrack != null) { - UIRenderHelper.breadcrumbArrow(21, height - 51, 30, 20, 5, 0x40aa9999, 0x10aa9999); - UIRenderHelper.breadcrumbArrow(-19, height - 51, 40, 20, 5, 0x40aa9999, 0x10aa9999); + int x = (int) MathHelper.lerp(arrowAnimation.getValue(partialTicks), -9, 21); + 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); } }