From 957f9355b7aae40e8f63f8fcb8bbdba00669d63c Mon Sep 17 00:00:00 2001 From: Zelophed Date: Fri, 3 Jul 2020 23:56:50 +0200 Subject: [PATCH] Display Arm Interaction Points - placed mechanical arms will show their in/out puts if you look at them while holding a wrench --- .../ArmInteractionPointHandler.java | 61 ++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPointHandler.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPointHandler.java index 16dc97a97..b6a94e2b1 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPointHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInteractionPointHandler.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.Map.Entry; import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllItems; import com.simibubi.create.CreateClient; import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionPoint.Mode; import com.simibubi.create.foundation.networking.AllPackets; @@ -14,11 +15,15 @@ import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -29,6 +34,8 @@ public class ArmInteractionPointHandler { static Map currentSelection = new HashMap<>(); static ItemStack currentItem; + static long lastBlockPos = -1; + @SubscribeEvent public static void rightClickingBlocksSelectsThem(PlayerInteractEvent.RightClickBlock event) { if (currentItem == null) @@ -74,21 +81,61 @@ public class ArmInteractionPointHandler { public static void tick() { PlayerEntity player = Minecraft.getInstance().player; - World world = Minecraft.getInstance().world; + if (player == null) return; ItemStack heldItemMainhand = player.getHeldItemMainhand(); if (!AllBlocks.MECHANICAL_ARM.isIn(heldItemMainhand)) { currentItem = null; - return; - } - if (heldItemMainhand != currentItem) { - currentSelection.clear(); - currentItem = heldItemMainhand; + } else { + if (heldItemMainhand != currentItem) { + currentSelection.clear(); + currentItem = heldItemMainhand; + } + + drawOutlines(currentSelection); } - for (Iterator> iterator = currentSelection.entrySet() + checkForWrench(heldItemMainhand); + } + + private static void checkForWrench(ItemStack heldItem) { + if(!AllItems.WRENCH.isIn(heldItem)) { + return; + } + + RayTraceResult objectMouseOver = Minecraft.getInstance().objectMouseOver; + if (!(objectMouseOver instanceof BlockRayTraceResult)) { + return; + } + + BlockRayTraceResult result = (BlockRayTraceResult) objectMouseOver; + BlockPos pos = result.getPos(); + + TileEntity te = Minecraft.getInstance().world.getTileEntity(pos); + if (!(te instanceof ArmTileEntity)) { + lastBlockPos = -1; + currentSelection.clear(); + return; + } + + if (lastBlockPos == -1 || lastBlockPos != pos.toLong()) { + currentSelection.clear(); + ArmTileEntity arm = (ArmTileEntity) te; + arm.inputs.forEach(point -> currentSelection.put(point.pos, point)); + arm.outputs.forEach(point -> currentSelection.put(point.pos, point)); + lastBlockPos = pos.toLong(); + } + + if (lastBlockPos != -1) { + drawOutlines(currentSelection); + } + } + + private static void drawOutlines(Map selection) { + World world = Minecraft.getInstance().world; + for (Iterator> iterator = selection.entrySet() .iterator(); iterator.hasNext();) { Entry entry = iterator.next(); BlockPos pos = entry.getKey();