mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #2246 from abel1502/abel-tangible-presses
Turn burner & electric press into proper pseudomultiblocks
This commit is contained in:
commit
cac082a6e2
@ -77,27 +77,20 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
|
||||
|
||||
super.onNeighborBlockChange(world, x, y, z, block);
|
||||
|
||||
if(world.isRemote || safeRem)
|
||||
if(safeRem)
|
||||
return;
|
||||
|
||||
int metadata = world.getBlockMetadata(x, y, z);
|
||||
|
||||
// if it's an extra, remove the extra-ness
|
||||
if(metadata >= extra)
|
||||
metadata -= extra;
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(metadata).getOpposite();
|
||||
Block b = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
|
||||
|
||||
if(b != this) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
destroyIfOrphan(world, x, y, z);
|
||||
}
|
||||
|
||||
public void updateTick(World world, int x, int y, int z, Random rand) {
|
||||
|
||||
super.updateTick(world, x, y, z, rand);
|
||||
|
||||
destroyIfOrphan(world, x, y, z);
|
||||
}
|
||||
|
||||
private void destroyIfOrphan(World world, int x, int y, int z) {
|
||||
if(world.isRemote)
|
||||
return;
|
||||
|
||||
@ -110,10 +103,32 @@ public abstract class BlockDummyable extends BlockContainer implements ICustomBl
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(metadata).getOpposite();
|
||||
Block b = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
|
||||
|
||||
if(b != this) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
// An extra precaution against multiblocks on chunk borders being erroneously deleted.
|
||||
// Technically, this might be used to persist ghost dummy blocks by manipulating
|
||||
// loaded chunks and block destruction, but this gives no benefit to the player,
|
||||
// cannot be done accidentally, and is definitely preferable to multiblocks
|
||||
// just vanishing when their chunks are unloaded in an unlucky way.
|
||||
if(b != this && world.checkChunksExist(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1)) {
|
||||
if (isLegacyMonoblock(world, x, y, z)) {
|
||||
fixLegacyMonoblock(world, x, y, z);
|
||||
} else {
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Override this when turning a single block into a pseudo-multiblock.
|
||||
// If this returns true, instead of being deleted as an orphan, the block
|
||||
// will be promoted to a core of a dummyable, however without any dummies.
|
||||
// This is only called if the block is presumed an orphan, so you don't
|
||||
// need to check that here.
|
||||
protected boolean isLegacyMonoblock(World world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void fixLegacyMonoblock(World world, int x, int y, int z) {
|
||||
// Promote to a lone core block with the same effective rotation as before the change
|
||||
world.setBlockMetadataWithNotify(x, y, z, offset + world.getBlockMetadata(x, y, z), 3);
|
||||
}
|
||||
|
||||
public int[] findCore(World world, int x, int y, int z) {
|
||||
|
||||
@ -1,129 +1,80 @@
|
||||
package com.hbm.blocks.machine;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.tileentity.TileEntityProxyCombo;
|
||||
import com.hbm.tileentity.machine.TileEntityMachineEPress;
|
||||
import com.hbm.world.gen.INBTTransformable;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import api.hbm.block.IToolable;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
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 MachineEPress extends BlockContainer implements INBTTransformable {
|
||||
public class MachineEPress extends BlockDummyable implements IToolable {
|
||||
|
||||
private final Random field_149933_a = new Random();
|
||||
private static boolean keepInventory;
|
||||
|
||||
public MachineEPress(Material p_i45386_1_) {
|
||||
super(p_i45386_1_);
|
||||
public MachineEPress(Material mat) {
|
||||
super(mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return new TileEntityMachineEPress();
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
if(meta >= 12) return new TileEntityMachineEPress();
|
||||
if(meta >= 6) return new TileEntityProxyCombo(true, false, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return -1;
|
||||
public int[] getDimensions() {
|
||||
return new int[] {2, 0, 0, 0, 0, 0};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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_);
|
||||
protected boolean isLegacyMonoblock(World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
return te != null && te instanceof TileEntityMachineEPress;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return this.standardOpenBehavior(world, x, y, z, player, 0);
|
||||
}
|
||||
|
||||
// Un-multiblickable with a hand drill for schenanigans
|
||||
@Override
|
||||
public int transformMeta(int meta, int coordBaseMode) {
|
||||
return INBTTransformable.transformMetaDeco(meta, coordBaseMode);
|
||||
public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) {
|
||||
|
||||
if (tool != ToolType.HAND_DRILL)
|
||||
return false;
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (meta >= 12)
|
||||
return false;
|
||||
|
||||
safeRem = true;
|
||||
world.setBlockToAir(x, y, z);
|
||||
safeRem = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,105 +1,64 @@
|
||||
package com.hbm.blocks.machine;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.tileentity.TileEntityProxyCombo;
|
||||
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 api.hbm.block.IToolable;
|
||||
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 implements IToolable {
|
||||
|
||||
public MachinePress(Material p_i45386_1_) {
|
||||
super(p_i45386_1_);
|
||||
public MachinePress(Material mat) {
|
||||
super(mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return new TileEntityMachinePress();
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
if(meta >= 12) return new TileEntityMachinePress();
|
||||
if(meta >= 6) return new TileEntityProxyCombo(true, false, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return -1;
|
||||
public int[] getDimensions() {
|
||||
return new int[] {2, 0, 0, 0, 0, 0};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
return false;
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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_);
|
||||
protected boolean isLegacyMonoblock(World world, int x, int y, int z) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
return te != null && te instanceof TileEntityMachinePress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return this.standardOpenBehavior(world, x, y, z, player, 0);
|
||||
}
|
||||
|
||||
// Un-multiblickable with a hand drill for schenanigans
|
||||
@Override
|
||||
public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) {
|
||||
|
||||
if (tool != ToolType.HAND_DRILL)
|
||||
return false;
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (meta >= 12)
|
||||
return false;
|
||||
|
||||
safeRem = true;
|
||||
world.setBlockToAir(x, y, z);
|
||||
safeRem = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.hbm.render.tileentity;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.main.ResourceManager;
|
||||
import com.hbm.render.util.RenderDecoItem;
|
||||
import com.hbm.tileentity.machine.TileEntityMachineEPress;
|
||||
@ -28,7 +29,7 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glRotatef(180, 0F, 1F, 0F);
|
||||
|
||||
switch(tileentity.getBlockMetadata()) {
|
||||
switch(tileentity.getBlockMetadata() - BlockDummyable.offset) {
|
||||
case 2: GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4: GL11.glRotatef(0, 0F, 1F, 0F); break;
|
||||
case 3: GL11.glRotatef(90, 0F, 1F, 0F); break;
|
||||
@ -50,7 +51,7 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glRotatef(180, 0F, 1F, 0F);
|
||||
|
||||
switch(tileentity.getBlockMetadata()) {
|
||||
switch(tileentity.getBlockMetadata() - BlockDummyable.offset) {
|
||||
case 2: GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4: GL11.glRotatef(0, 0F, 1F, 0F); break;
|
||||
case 3: GL11.glRotatef(90, 0F, 1F, 0F); break;
|
||||
@ -78,7 +79,7 @@ public class RenderEPress extends TileEntitySpecialRenderer {
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glRotatef(180, 0F, 1F, 0F);
|
||||
|
||||
switch(tileentity.getBlockMetadata()) {
|
||||
switch(tileentity.getBlockMetadata() - BlockDummyable.offset) {
|
||||
case 2:
|
||||
GL11.glRotatef(270, 0F, 1F, 0F); break;
|
||||
case 4:
|
||||
|
||||
@ -64,6 +64,11 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
// Triggers the legacy monoblock fix
|
||||
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) < 12) {
|
||||
worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord), 1);
|
||||
}
|
||||
|
||||
this.updateConnections();
|
||||
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
|
||||
@ -53,6 +53,11 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
// Triggers the legacy monoblock fix
|
||||
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) < 12) {
|
||||
worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord), 1);
|
||||
}
|
||||
|
||||
boolean preheated = false;
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user