From f6f1c1c380e35c6acefeaf52677631210fb5ae59 Mon Sep 17 00:00:00 2001 From: abel1502 Date: Sat, 28 Jun 2025 23:50:45 +0300 Subject: [PATCH] Turn presses into pseudomultiblocks Affects burner and electrical press. They seem to have been implemented largely based on copy-pasted furnace code, and seemingly predate BlockDummyable. That meant the top two blocks of a press were intangible. Now they're in line with the rest of the machines, including the conveyor press. --- .../com/hbm/blocks/machine/MachineEPress.java | 91 +++++-------------- .../com/hbm/blocks/machine/MachinePress.java | 81 +++-------------- 2 files changed, 38 insertions(+), 134 deletions(-) diff --git a/src/main/java/com/hbm/blocks/machine/MachineEPress.java b/src/main/java/com/hbm/blocks/machine/MachineEPress.java index 465ea6c69..42cb7713f 100644 --- a/src/main/java/com/hbm/blocks/machine/MachineEPress.java +++ b/src/main/java/com/hbm/blocks/machine/MachineEPress.java @@ -2,6 +2,7 @@ package com.hbm.blocks.machine; import java.util.Random; +import com.hbm.blocks.BlockDummyable; import com.hbm.main.MainRegistry; import com.hbm.tileentity.machine.TileEntityMachineEPress; import com.hbm.world.gen.INBTTransformable; @@ -20,10 +21,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -public class MachineEPress extends BlockContainer implements INBTTransformable { - - private final Random field_149933_a = new Random(); - private static boolean keepInventory; +public class MachineEPress extends BlockDummyable implements INBTTransformable { public MachineEPress(Material p_i45386_1_) { super(p_i45386_1_); @@ -35,75 +33,27 @@ public class MachineEPress extends BlockContainer implements INBTTransformable { } @Override - public int getRenderType() { - return -1; + public int[] getDimensions() { + return new int[] {2, 0, 0, 0, 0, 0}; } @Override - public boolean isOpaqueCube() { - return false; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @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_); + public int getOffset() { + return 0; } @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, 2, 2); - if(i == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2); - if(i == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2); - if(i == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2); + super.onBlockPlacedBy(world, x, y, z, player, itemStack); if(itemStack.hasDisplayName()) { - ((TileEntityMachineEPress) world.getTileEntity(x, y, z)).setCustomName(itemStack.getDisplayName()); + int[] pos = this.findCore(world, x, y, z); + if(pos != null) { + TileEntityMachineEPress entity = (TileEntityMachineEPress) world.getTileEntity(pos[0], pos[1], pos[2]); + if(entity != null) { + entity.setCustomName(itemStack.getDisplayName()); + } + } } } @@ -112,10 +62,15 @@ public class MachineEPress extends BlockContainer implements INBTTransformable { if(world.isRemote) { return true; } else if(!player.isSneaking()) { - TileEntityMachineEPress entity = (TileEntityMachineEPress) world.getTileEntity(x, y, z); - if(entity != null) { - FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); - } + int[] pos = this.findCore(world, x, y, z); + if(pos == null) + return false; + + TileEntityMachineEPress entity = (TileEntityMachineEPress) world.getTileEntity(pos[0], pos[1], pos[2]); + if(entity == null) + return false; + + FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); return true; } else { return false; diff --git a/src/main/java/com/hbm/blocks/machine/MachinePress.java b/src/main/java/com/hbm/blocks/machine/MachinePress.java index a28d22172..ddf7782b7 100644 --- a/src/main/java/com/hbm/blocks/machine/MachinePress.java +++ b/src/main/java/com/hbm/blocks/machine/MachinePress.java @@ -2,23 +2,16 @@ package com.hbm.blocks.machine; import java.util.Random; +import com.hbm.blocks.BlockDummyable; import com.hbm.main.MainRegistry; import com.hbm.tileentity.machine.TileEntityMachinePress; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -public class MachinePress extends BlockContainer { - - private final Random field_149933_a = new Random(); - private static boolean keepInventory; +public class MachinePress extends BlockDummyable { public MachinePress(Material p_i45386_1_) { super(p_i45386_1_); @@ -30,62 +23,13 @@ public class MachinePress extends BlockContainer { } @Override - public int getRenderType() { - return -1; + public int[] getDimensions() { + return new int[] {2, 0, 0, 0, 0, 0}; } @Override - public boolean isOpaqueCube() { - return false; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @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) { - TileEntityMachinePress tileentityfurnace = (TileEntityMachinePress) 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_); + public int getOffset() { + return 0; } @Override @@ -93,10 +37,15 @@ public class MachinePress extends BlockContainer { if(world.isRemote) { return true; } else if(!player.isSneaking()) { - TileEntityMachinePress entity = (TileEntityMachinePress) world.getTileEntity(x, y, z); - if(entity != null) { - FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); - } + int[] pos = this.findCore(world, x, y, z); + if(pos == null) + return false; + + TileEntityMachinePress entity = (TileEntityMachinePress) world.getTileEntity(pos[0], pos[1], pos[2]); + if(entity == null) + return false; + + FMLNetworkHandler.openGui(player, MainRegistry.instance, 0, world, x, y, z); return true; } else { return false;