From 5f109b61ec67bec1911b30bd3f3e1cffeef253dc Mon Sep 17 00:00:00 2001 From: Bob Date: Wed, 5 Jul 2023 22:26:20 +0200 Subject: [PATCH] i can't feel my limbs --- .../hbm/blocks/machine/MachineAssembler.java | 283 +----------------- .../render/tileentity/RenderAssembler.java | 24 +- .../machine/TileEntityMachineAssembler.java | 26 +- 3 files changed, 46 insertions(+), 287 deletions(-) diff --git a/src/main/java/com/hbm/blocks/machine/MachineAssembler.java b/src/main/java/com/hbm/blocks/machine/MachineAssembler.java index 881768570..8f399a824 100644 --- a/src/main/java/com/hbm/blocks/machine/MachineAssembler.java +++ b/src/main/java/com/hbm/blocks/machine/MachineAssembler.java @@ -1,296 +1,31 @@ package com.hbm.blocks.machine; -import java.util.Random; - -import com.hbm.blocks.ModBlocks; -import com.hbm.handler.MultiblockHandler; -import com.hbm.interfaces.IMultiblock; -import com.hbm.tileentity.machine.TileEntityDummy; +import com.hbm.blocks.BlockDummyable; import com.hbm.tileentity.machine.TileEntityMachineAssembler; -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; -public class MachineAssembler extends BlockContainer implements IMultiblock { +public class MachineAssembler extends BlockDummyable { public MachineAssembler(Material p_i45386_1_) { super(p_i45386_1_); } @Override - public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { - return new TileEntityMachineAssembler(); - + public TileEntity createNewTileEntity(World world, int meta) { + if(meta >= 12) return new TileEntityMachineAssembler(); + return null; } @Override - public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { - return Item.getItemFromBlock(ModBlocks.machine_assembler); + public int[] getDimensions() { + return new int[] {1, 0, 2, 1, 2, 1}; } @Override - public int getRenderType() { - return -1; + public int getOffset() { + return 1; } - - @Override - public boolean isOpaqueCube() { - return false; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) { - int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; - - if (i == 0) { - world.setBlockMetadataWithNotify(x, y, z, 5, 2); - if(MultiblockHandler.checkSpace(world, x, y, z, MultiblockHandler.assemblerDimensionEast)) { - MultiblockHandler.fillUp(world, x, y, z, MultiblockHandler.assemblerDimensionEast, ModBlocks.dummy_block_assembler); - - // - DummyBlockAssembler.safeBreak = true; - world.setBlock(x - 1, y, z, ModBlocks.dummy_port_assembler); - TileEntity te = world.getTileEntity(x - 1, y, z); - if(te instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x - 1, y, z + 1, ModBlocks.dummy_port_assembler); - TileEntity te2 = world.getTileEntity(x - 1, y, z + 1); - if(te2 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te2; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x + 2, y, z, ModBlocks.dummy_port_assembler); - TileEntity te3 = world.getTileEntity(x + 2, y, z); - if(te3 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te3; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x + 2, y, z + 1, ModBlocks.dummy_port_assembler); - TileEntity te4 = world.getTileEntity(x + 2, y, z + 1); - if(te4 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te4; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - DummyBlockAssembler.safeBreak = false; - // - - } else - world.func_147480_a(x, y, z, true); - } - if (i == 1) { - world.setBlockMetadataWithNotify(x, y, z, 3, 2); - if(MultiblockHandler.checkSpace(world, x, y, z, MultiblockHandler.assemblerDimensionSouth)) { - MultiblockHandler.fillUp(world, x, y, z, MultiblockHandler.assemblerDimensionSouth, ModBlocks.dummy_block_assembler); - - // - DummyBlockAssembler.safeBreak = true; - world.setBlock(x, y, z - 1, ModBlocks.dummy_port_assembler); - TileEntity te = world.getTileEntity(x, y, z - 1); - if(te instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x - 1, y, z - 1, ModBlocks.dummy_port_assembler); - TileEntity te2 = world.getTileEntity(x - 1, y, z - 1); - if(te2 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te2; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x, y, z + 2, ModBlocks.dummy_port_assembler); - TileEntity te3 = world.getTileEntity(x, y, z + 2); - if(te3 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te3; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x - 1, y, z + 2, ModBlocks.dummy_port_assembler); - TileEntity te4 = world.getTileEntity(x - 1, y, z + 2); - if(te4 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te4; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - DummyBlockAssembler.safeBreak = false; - // - - } else - world.func_147480_a(x, y, z, true); - } - if (i == 2) { - world.setBlockMetadataWithNotify(x, y, z, 4, 2); - if(MultiblockHandler.checkSpace(world, x, y, z, MultiblockHandler.assemblerDimensionWest)) { - MultiblockHandler.fillUp(world, x, y, z, MultiblockHandler.assemblerDimensionWest, ModBlocks.dummy_block_assembler); - - // - DummyBlockAssembler.safeBreak = true; - world.setBlock(x + 1, y, z, ModBlocks.dummy_port_assembler); - TileEntity te = world.getTileEntity(x + 1, y, z); - if(te instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x + 1, y, z - 1, ModBlocks.dummy_port_assembler); - TileEntity te2 = world.getTileEntity(x + 1, y, z - 1); - if(te2 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te2; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x - 2, y, z, ModBlocks.dummy_port_assembler); - TileEntity te3 = world.getTileEntity(x - 2, y, z); - if(te3 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te3; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x - 2, y, z - 1, ModBlocks.dummy_port_assembler); - TileEntity te4 = world.getTileEntity(x - 2, y, z - 1); - if(te4 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te4; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - DummyBlockAssembler.safeBreak = false; - // - - } else - world.func_147480_a(x, y, z, true); - } - if (i == 3) { - world.setBlockMetadataWithNotify(x, y, z, 2, 2); - if(MultiblockHandler.checkSpace(world, x, y, z, MultiblockHandler.assemblerDimensionNorth)) { - MultiblockHandler.fillUp(world, x, y, z, MultiblockHandler.assemblerDimensionNorth, ModBlocks.dummy_block_assembler); - - // - DummyBlockAssembler.safeBreak = true; - world.setBlock(x, y, z + 1, ModBlocks.dummy_port_assembler); - TileEntity te = world.getTileEntity(x, y, z + 1); - if(te instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x + 1, y, z + 1, ModBlocks.dummy_port_assembler); - TileEntity te2 = world.getTileEntity(x + 1, y, z + 1); - if(te2 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te2; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x, y, z - 2, ModBlocks.dummy_port_assembler); - TileEntity te3 = world.getTileEntity(x, y, z - 2); - if(te3 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te3; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - world.setBlock(x + 1, y, z - 2, ModBlocks.dummy_port_assembler); - TileEntity te4 = world.getTileEntity(x + 1, y, z - 2); - if(te4 instanceof TileEntityDummy) { - TileEntityDummy dummy = (TileEntityDummy)te4; - dummy.targetX = x; - dummy.targetY = y; - dummy.targetZ = z; - } - DummyBlockAssembler.safeBreak = false; - // - - } else - world.func_147480_a(x, y, z, true); - } - } - - private final Random field_149933_a = new Random(); - private static boolean keepInventory; - - @Override - public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) - { - if (!keepInventory) - { - ISidedInventory tileentityfurnace = (ISidedInventory)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_); - - if (tileentityfurnace != null) - { - for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1) - { - ItemStack itemstack = tileentityfurnace.getStackInSlot(i1); - - if (itemstack != null) - { - float f = this.field_149933_a.nextFloat() * 0.8F + 0.1F; - float f1 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; - float f2 = this.field_149933_a.nextFloat() * 0.8F + 0.1F; - - while (itemstack.stackSize > 0) - { - int j1 = this.field_149933_a.nextInt(21) + 10; - - if (j1 > itemstack.stackSize) - { - j1 = itemstack.stackSize; - } - - itemstack.stackSize -= j1; - EntityItem entityitem = new EntityItem(p_149749_1_, p_149749_2_ + f, p_149749_3_ + f1, p_149749_4_ + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); - - if (itemstack.hasTagCompound()) - { - entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); - } - - float f3 = 0.05F; - entityitem.motionX = (float)this.field_149933_a.nextGaussian() * f3; - entityitem.motionY = (float)this.field_149933_a.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float)this.field_149933_a.nextGaussian() * f3; - p_149749_1_.spawnEntityInWorld(entityitem); - } - } - } - - p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_); - } - } - - super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); - } } diff --git a/src/main/java/com/hbm/render/tileentity/RenderAssembler.java b/src/main/java/com/hbm/render/tileentity/RenderAssembler.java index b03698a8b..7f9436fd9 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderAssembler.java +++ b/src/main/java/com/hbm/render/tileentity/RenderAssembler.java @@ -33,16 +33,16 @@ public class RenderAssembler extends TileEntitySpecialRenderer { GL11.glRotatef(180, 0F, 1F, 0F); switch(tileEntity.getBlockMetadata()) { - case 2: + case 14: GL11.glRotatef(180, 0F, 1F, 0F); GL11.glTranslated(0.5D, 0.0D, -0.5D); break; - case 4: + case 13: GL11.glRotatef(270, 0F, 1F, 0F); GL11.glTranslated(0.5D, 0.0D, -0.5D); break; - case 3: + case 15: GL11.glRotatef(0, 0F, 1F, 0F); GL11.glTranslated(0.5D, 0.0D, -0.5D); break; - case 5: + case 12: GL11.glRotatef(90, 0F, 1F, 0F); GL11.glTranslated(0.5D, 0.0D, -0.5D); break; } @@ -99,15 +99,15 @@ public class RenderAssembler extends TileEntitySpecialRenderer { GL11.glRotatef(180, 0F, 1F, 0F); switch(tileEntity.getBlockMetadata()) { - case 2: + case 14: GL11.glTranslated(-1, 0, 0); GL11.glRotatef(180, 0F, 1F, 0F); break; - case 4: + case 13: GL11.glRotatef(270, 0F, 1F, 0F); break; - case 3: + case 15: GL11.glTranslated(0, 0, -1); GL11.glRotatef(0, 0F, 1F, 0F); break; - case 5: + case 12: GL11.glTranslated(-1, 0, -1); GL11.glRotatef(90, 0F, 1F, 0F); break; } @@ -150,15 +150,15 @@ public class RenderAssembler extends TileEntitySpecialRenderer { GL11.glRotatef(180, 0F, 1F, 0F); switch(tileEntity.getBlockMetadata()) { - case 2: + case 14: GL11.glTranslated(-1, 0, 0); GL11.glRotatef(180, 0F, 1F, 0F); break; - case 4: + case 13: GL11.glRotatef(270, 0F, 1F, 0F); break; - case 3: + case 15: GL11.glTranslated(0, 0, -1); GL11.glRotatef(0, 0F, 1F, 0F); break; - case 5: + case 12: GL11.glTranslated(-1, 0, -1); GL11.glRotatef(90, 0F, 1F, 0F); break; } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineAssembler.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineAssembler.java index 33c973b89..76b2d2ebd 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineAssembler.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineAssembler.java @@ -4,7 +4,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.ModBlocks; +import com.hbm.handler.MultiblockHandlerXR; import com.hbm.inventory.RecipesCommon.AStack; import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.inventory.UpgradeManager; @@ -38,6 +40,7 @@ import net.minecraft.tileentity.TileEntityChest; import net.minecraft.tileentity.TileEntityHopper; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class TileEntityMachineAssembler extends TileEntityMachineBase implements IEnergyUser, IGUIProvider { @@ -51,7 +54,7 @@ public class TileEntityMachineAssembler extends TileEntityMachineBase implements int speed = 100; @SideOnly(Side.CLIENT) - public int recipe; + public int recipe = -1; private AudioWrapper audio; @@ -127,6 +130,27 @@ public class TileEntityMachineAssembler extends TileEntityMachineBase implements if(!worldObj.isRemote) { + //meta below 12 means that it's an old multiblock configuration + if(this.getBlockMetadata() < 12) { + int meta = this.getBlockMetadata(); + if(meta == 2 || meta == 14) meta = 4; + else if(meta == 4 || meta == 13) meta = 3; + else if(meta == 3 || meta == 15) meta = 5; + else if(meta == 5 || meta == 12) meta = 2; + //get old direction + ForgeDirection dir = ForgeDirection.getOrientation(meta); + //remove tile from the world to prevent inventory dropping + worldObj.removeTileEntity(xCoord, yCoord, zCoord); + //use fillspace to create a new multiblock configuration + worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.machine_assembler, dir.ordinal() + 10, 3); + MultiblockHandlerXR.fillSpace(worldObj, xCoord, yCoord, zCoord, ((BlockDummyable) ModBlocks.machine_assembler).getDimensions(), ModBlocks.machine_assembler, dir); + //load the tile data to restore the old values + NBTTagCompound data = new NBTTagCompound(); + this.writeToNBT(data); + worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data); + return; + } + this.updateConnections(); this.consumption = 100;