From 896b91d9608ba9cce0db7d4122fc49c6736c7206 Mon Sep 17 00:00:00 2001 From: Boblet Date: Thu, 15 Sep 2022 14:09:47 +0200 Subject: [PATCH] structure analysis wands --- src/main/java/com/hbm/blocks/ModBlocks.java | 3 + src/main/java/com/hbm/items/ModItems.java | 11 ++ .../hbm/items/tool/ItemStructurePattern.java | 56 +++++++++ .../hbm/items/tool/ItemStructureSingle.java | 37 ++++++ .../hbm/items/tool/ItemStructureSolid.java | 45 +++++++ .../com/hbm/items/tool/ItemStructureTool.java | 116 ++++++++++++++++++ .../com/hbm/main/ModEventHandlerClient.java | 10 +- .../hbm/textures/blocks/structure_anchor.png | Bin 0 -> 193 bytes .../hbm/textures/items/structure_pattern.png | Bin 0 -> 179 bytes .../hbm/textures/items/structure_single.png | Bin 0 -> 187 bytes .../hbm/textures/items/structure_solid.png | Bin 0 -> 187 bytes 11 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/hbm/items/tool/ItemStructurePattern.java create mode 100644 src/main/java/com/hbm/items/tool/ItemStructureSingle.java create mode 100644 src/main/java/com/hbm/items/tool/ItemStructureSolid.java create mode 100644 src/main/java/com/hbm/items/tool/ItemStructureTool.java create mode 100644 src/main/resources/assets/hbm/textures/blocks/structure_anchor.png create mode 100644 src/main/resources/assets/hbm/textures/items/structure_pattern.png create mode 100644 src/main/resources/assets/hbm/textures/items/structure_single.png create mode 100644 src/main/resources/assets/hbm/textures/items/structure_solid.png diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index 0a02fa292..58c2b2422 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -56,6 +56,7 @@ public class ModBlocks { public static Block test_rail; public static Block test_bb_bork; public static Block test_bb_inf; + public static Block structure_anchor; public static Block ore_uranium; public static Block ore_uranium_scorched; @@ -1310,6 +1311,7 @@ public class ModBlocks { test_rail = new TestRail(Material.iron).setBlockName("test_rail").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_rail"); test_bb_bork = new TestBB(Material.iron).setBlockName("test_bb_bork").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_bb_bork"); test_bb_inf = new TestBB(Material.iron).setBlockName("test_bb_inf").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":test_bb_inf"); + structure_anchor = new BlockGeneric(Material.iron).setBlockName("structure_anchor").setCreativeTab(null).setHardness(2.5F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":structure_anchor"); ore_uranium = new BlockOutgas(Material.rock, true, 5, true).setBlockName("ore_uranium").setCreativeTab(MainRegistry.blockTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":ore_uranium"); ore_uranium_scorched = new BlockOutgas(Material.rock, true, 5, true).setBlockName("ore_uranium_scorched").setCreativeTab(MainRegistry.blockTab).setHardness(5.0F).setResistance(10.0F).setBlockTextureName(RefStrings.MODID + ":ore_uranium_scorched"); @@ -2383,6 +2385,7 @@ public class ModBlocks { GameRegistry.registerBlock(test_rail, test_rail.getUnlocalizedName()); GameRegistry.registerBlock(test_bb_bork, test_bb_bork.getUnlocalizedName()); GameRegistry.registerBlock(test_bb_inf, test_bb_inf.getUnlocalizedName()); + GameRegistry.registerBlock(structure_anchor, structure_anchor.getUnlocalizedName()); //Ores GameRegistry.registerBlock(ore_uranium, ore_uranium.getUnlocalizedName()); diff --git a/src/main/java/com/hbm/items/ModItems.java b/src/main/java/com/hbm/items/ModItems.java index af622b770..0d6b682b9 100644 --- a/src/main/java/com/hbm/items/ModItems.java +++ b/src/main/java/com/hbm/items/ModItems.java @@ -2309,6 +2309,10 @@ public class ModItems { public static Item wand_s; public static Item wand_d; + public static Item structure_single; + public static Item structure_solid; + public static Item structure_pattern; + public static Item rod_of_discord; public static Item cape_test; @@ -4732,6 +4736,10 @@ public class ModItems { wand = new ItemWand().setUnlocalizedName("wand_k").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setFull3D().setTextureName(RefStrings.MODID + ":wand"); wand_s = new ItemWandS().setUnlocalizedName("wand_s").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setFull3D().setTextureName(RefStrings.MODID + ":wand_s"); wand_d = new ItemWandD().setUnlocalizedName("wand_d").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setFull3D().setTextureName(RefStrings.MODID + ":wand_d"); + + structure_single = new ItemStructureSingle().setUnlocalizedName("structure_single").setMaxStackSize(1).setCreativeTab(null).setFull3D().setTextureName(RefStrings.MODID + ":structure_single"); + structure_solid = new ItemStructureSolid().setUnlocalizedName("structure_solid").setMaxStackSize(1).setCreativeTab(null).setFull3D().setTextureName(RefStrings.MODID + ":structure_solid"); + structure_pattern = new ItemStructurePattern().setUnlocalizedName("structure_pattern").setMaxStackSize(1).setCreativeTab(null).setFull3D().setTextureName(RefStrings.MODID + ":structure_pattern"); rod_of_discord = new ItemDiscord().setUnlocalizedName("rod_of_discord").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setFull3D().setTextureName(RefStrings.MODID + ":rod_of_discord"); @@ -8097,6 +8105,9 @@ public class ModItems { GameRegistry.registerItem(wand, wand.getUnlocalizedName()); GameRegistry.registerItem(wand_s, wand_s.getUnlocalizedName()); GameRegistry.registerItem(wand_d, wand_d.getUnlocalizedName()); + GameRegistry.registerItem(structure_single, structure_single.getUnlocalizedName()); + GameRegistry.registerItem(structure_solid, structure_solid.getUnlocalizedName()); + GameRegistry.registerItem(structure_pattern, structure_pattern.getUnlocalizedName()); GameRegistry.registerItem(rod_of_discord, rod_of_discord.getUnlocalizedName()); //GameRegistry.registerItem(analyzer, analyzer.getUnlocalizedName()); //GameRegistry.registerItem(remote, remote.getUnlocalizedName()); diff --git a/src/main/java/com/hbm/items/tool/ItemStructurePattern.java b/src/main/java/com/hbm/items/tool/ItemStructurePattern.java new file mode 100644 index 000000000..9fa41ace7 --- /dev/null +++ b/src/main/java/com/hbm/items/tool/ItemStructurePattern.java @@ -0,0 +1,56 @@ +package com.hbm.items.tool; + +import java.util.List; + +import com.hbm.util.fauxpointtwelve.BlockPos; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class ItemStructurePattern extends ItemStructureTool { + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { + super.addInformation(stack, player, list, ext); + list.add(EnumChatFormatting.YELLOW + "Click to print all "); + list.add(EnumChatFormatting.YELLOW + "lines for the current selection with blocks and metadata."); + } + + @Override + protected boolean dualUse() { + return true; + } + + @Override + protected void doTheThing(ItemStack stack, World world, int x, int y, int z) { + + BlockPos pos = this.getAnchor(stack); + if(pos == null) return; + + int savedX = stack.stackTagCompound.getInteger("x"); + int savedY = stack.stackTagCompound.getInteger("y"); + int savedZ = stack.stackTagCompound.getInteger("z"); + + int minX = Math.min(savedX, x) - pos.getX(); + int minY = Math.min(savedY, y) - pos.getY(); + int minZ = Math.min(savedZ, z) - pos.getZ(); + int maxX = Math.max(savedX, x) - pos.getX(); + int maxY = Math.max(savedY, y) - pos.getY(); + int maxZ = Math.max(savedZ, z) - pos.getZ(); + + for(int ix = minX; ix <= maxX; ix++) { + for(int iy = minX; iy <= maxY; iy++) { + for(int iz = minX; iz <= maxZ; iz++) { + + Block b = world.getBlock(ix + pos.getX(), iy + pos.getY(), iz + pos.getZ()); + int meta = world.getBlockMetadata(ix + pos.getX(), iy + pos.getY(), iz + pos.getZ()); + + System.out.println("this.placeBlockAtCurrentPosition(world, " + b.getUnlocalizedName() + ", " + meta + ", " + ix + ", " + iy + ", " + iz + ", box)"); + } + } + } + } +} diff --git a/src/main/java/com/hbm/items/tool/ItemStructureSingle.java b/src/main/java/com/hbm/items/tool/ItemStructureSingle.java new file mode 100644 index 000000000..b35974d32 --- /dev/null +++ b/src/main/java/com/hbm/items/tool/ItemStructureSingle.java @@ -0,0 +1,37 @@ +package com.hbm.items.tool; + +import java.util.List; + +import com.hbm.util.fauxpointtwelve.BlockPos; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class ItemStructureSingle extends ItemStructureTool { + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { + super.addInformation(stack, player, list, ext); + list.add(EnumChatFormatting.YELLOW + "Click to print exactly one "); + list.add(EnumChatFormatting.YELLOW + "line with the targted block and metadata"); + } + + @Override + protected void doTheThing(ItemStack stack, World world, int x, int y, int z) { + + BlockPos pos = this.getAnchor(stack); + if(pos == null) return; + + int ix = x - pos.getX(); + int iy = y - pos.getX(); + int iz = z - pos.getX(); + + Block b = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + System.out.println("this.placeBlockAtCurrentPosition(world, " + b.getUnlocalizedName() + ", " + meta + ", " + x + ", " + y + ", " + z + ", box)"); + } +} diff --git a/src/main/java/com/hbm/items/tool/ItemStructureSolid.java b/src/main/java/com/hbm/items/tool/ItemStructureSolid.java new file mode 100644 index 000000000..8267f96b8 --- /dev/null +++ b/src/main/java/com/hbm/items/tool/ItemStructureSolid.java @@ -0,0 +1,45 @@ +package com.hbm.items.tool; + +import java.util.List; + +import com.hbm.util.fauxpointtwelve.BlockPos; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class ItemStructureSolid extends ItemStructureTool { + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { + super.addInformation(stack, player, list, ext); + list.add(EnumChatFormatting.YELLOW + "Click to print a "); + list.add(EnumChatFormatting.YELLOW + "line with wildcard block and metadata."); + } + + @Override + protected boolean dualUse() { + return true; + } + + @Override + protected void doTheThing(ItemStack stack, World world, int x, int y, int z) { + + BlockPos pos = this.getAnchor(stack); + if(pos == null) return; + + int savedX = stack.stackTagCompound.getInteger("x"); + int savedY = stack.stackTagCompound.getInteger("y"); + int savedZ = stack.stackTagCompound.getInteger("z"); + + int minX = Math.min(savedX, x) - pos.getX(); + int minY = Math.min(savedY, y) - pos.getY(); + int minZ = Math.min(savedZ, z) - pos.getZ(); + int maxX = Math.max(savedX, x) - pos.getX(); + int maxY = Math.max(savedY, y) - pos.getY(); + int maxZ = Math.max(savedZ, z) - pos.getZ(); + + System.out.println("this.fillWithMetadataBlocks(world, box, " + minX + ", " + minY + ", " + minZ + ", " + maxX + ", " + maxY + ", " + maxZ + ", , , Blocks.air, 0, false)"); + } +} diff --git a/src/main/java/com/hbm/items/tool/ItemStructureTool.java b/src/main/java/com/hbm/items/tool/ItemStructureTool.java new file mode 100644 index 000000000..c72f6a392 --- /dev/null +++ b/src/main/java/com/hbm/items/tool/ItemStructureTool.java @@ -0,0 +1,116 @@ +package com.hbm.items.tool; + +import java.util.ArrayList; +import java.util.List; + +import com.hbm.blocks.ILookOverlay; +import com.hbm.blocks.ModBlocks; +import com.hbm.util.fauxpointtwelve.BlockPos; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre; + +public abstract class ItemStructureTool extends Item implements ILookOverlay { + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { + BlockPos anchor = this.getAnchor(stack); + + if(anchor == null) { + list.add(EnumChatFormatting.RED + "No anchor set! Right click an anchor to get started."); + } + } + + public static BlockPos getAnchor(ItemStack stack) { + + if(!stack.hasTagCompound()) { + return null; + } + + return new BlockPos(stack.stackTagCompound.getInteger("anchorX"), stack.stackTagCompound.getInteger("anchorY"), stack.stackTagCompound.getInteger("anchorZ")); + } + + public static void setAnchor(ItemStack stack, int x, int y, int z) { + + if(stack.stackTagCompound == null) { + stack.stackTagCompound = new NBTTagCompound(); + } + + stack.stackTagCompound.setInteger("anchorX", x); + stack.stackTagCompound.setInteger("anchorY", y); + stack.stackTagCompound.setInteger("anchorZ", z); + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { + + Block b = world.getBlock(x, y, z); + + if(b == ModBlocks.structure_anchor) { + this.setAnchor(stack, x, y, z); + return true; + } + + if(this.getAnchor(stack) == null) { + return false; + } + + if(!this.dualUse()) { + this.doTheThing(stack, world, x, y, z); + } else { + + if(!stack.stackTagCompound.hasKey("x")) { + stack.stackTagCompound.setInteger("x", x); + stack.stackTagCompound.setInteger("y", y); + stack.stackTagCompound.setInteger("z", z); + } else { + this.doTheThing(stack, world, x, y, z); + stack.stackTagCompound.removeTag("x"); + stack.stackTagCompound.removeTag("y"); + stack.stackTagCompound.removeTag("z"); + } + } + + return true; + } + + protected boolean dualUse() { + return false; + } + + protected abstract void doTheThing(ItemStack stack, World world, int x, int y, int z); + + @Override + public void printHook(Pre event, World world, int x, int y, int z) { + ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItem(); + List text = new ArrayList(); + + BlockPos anchor = getAnchor(stack); + + if(anchor == null) { + text.add(EnumChatFormatting.RED + "No Anchor"); + } else { + + int dX = x - anchor.getX(); + int dY = y - anchor.getY(); + int dZ = z - anchor.getZ(); + text.add(EnumChatFormatting.YELLOW + "Position: " + dX + " / " + dY + " / " + dZ); + + if(this.dualUse() && stack.stackTagCompound.hasKey("x")) { + int sX = Math.abs(x - stack.stackTagCompound.getInteger("x")) + 1; + int sY = Math.abs(y - stack.stackTagCompound.getInteger("y")) + 1; + int sZ = Math.abs(z - stack.stackTagCompound.getInteger("z")) + 1; + text.add(EnumChatFormatting.GOLD + "Selection: " + sX + " / " + sY + " / " + sZ); + } + } + + ILookOverlay.printGeneric(event, this.getItemStackDisplayName(stack), 0xffff00, 0x404000, text); + } +} diff --git a/src/main/java/com/hbm/main/ModEventHandlerClient.java b/src/main/java/com/hbm/main/ModEventHandlerClient.java index faebbcd73..b984d3e1e 100644 --- a/src/main/java/com/hbm/main/ModEventHandlerClient.java +++ b/src/main/java/com/hbm/main/ModEventHandlerClient.java @@ -155,8 +155,14 @@ public class ModEventHandlerClient { World world = mc.theWorld; MovingObjectPosition mop = mc.objectMouseOver; - if(mop != null && mop.typeOfHit == mop.typeOfHit.BLOCK && world.getBlock(mop.blockX, mop.blockY, mop.blockZ) instanceof ILookOverlay) { - ((ILookOverlay) world.getBlock(mop.blockX, mop.blockY, mop.blockZ)).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ); + if(mop != null && mop.typeOfHit == mop.typeOfHit.BLOCK ) { + + if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ILookOverlay) { + ((ILookOverlay) player.getHeldItem().getItem()).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ); + + } else if(world.getBlock(mop.blockX, mop.blockY, mop.blockZ) instanceof ILookOverlay) { + ((ILookOverlay) world.getBlock(mop.blockX, mop.blockY, mop.blockZ)).printHook(event, world, mop.blockX, mop.blockY, mop.blockZ); + } } /*if(mop != null && mop.typeOfHit == mop.typeOfHit.BLOCK) { diff --git a/src/main/resources/assets/hbm/textures/blocks/structure_anchor.png b/src/main/resources/assets/hbm/textures/blocks/structure_anchor.png new file mode 100644 index 0000000000000000000000000000000000000000..b0de5a33b16c704cb3940d5eff622119a383b845 GIT binary patch literal 193 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#VfU$A8N|nw4C((&V^x=#=3vk3Sp?t_%GbF8s^iyhU1|GbV7d^6Le) zZ}nK;gh()cFtoEwcpcfpIAPoMi|dN{j86CzH=KFrqkaDngUy#0Iu-Ng?vdGWKtS%c o#5>sylR4%wg-PddcHRHUbj3v>U{}o~kQ*30UHx3vIVCg!09-Lg3jhEB literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/hbm/textures/items/structure_pattern.png b/src/main/resources/assets/hbm/textures/items/structure_pattern.png new file mode 100644 index 0000000000000000000000000000000000000000..f1fad870d3f35eeb3e6dea1b0cc0e90cc2bf6898 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf3}) zq3)Lq!Rxd0Uv}LwZoGNnJ`2yaslQh`iZ5dmj!=1@z)~-qBXO;H@4>>`i&4AYM1p!i$NjVeEGMTM+z)vwFzmR zdl1tYJ1K}Ma>DH+880Rt?3=~Uqhj5$p>)}Fp0xGO>>-I(3z(VT%Wiov!{Onh{u1U( jx!Z+864j*oKC$&rd?qVn{RNaxrWa|U8ox#)9&t;ucLK6UC?nC(i literal 0 HcmV?d00001