diff options
author | Jason Mitchell <mitchej@gmail.com> | 2022-07-17 12:57:04 -0700 |
---|---|---|
committer | Jason Mitchell <mitchej+github@gmail.com> | 2022-07-22 12:57:20 -0700 |
commit | 8c4dd7de80e06875b942b1343f2ca4895ce2d758 (patch) | |
tree | 82f9185d76899d581950cc71f2406b9bc702bcbf /src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java | |
parent | 48e6a5fde81f33d3ff4cb2ef610c39abd33a5821 (diff) | |
download | GT5-Unofficial-8c4dd7de80e06875b942b1343f2ca4895ce2d758.tar.gz GT5-Unofficial-8c4dd7de80e06875b942b1343f2ca4895ce2d758.tar.bz2 GT5-Unofficial-8c4dd7de80e06875b942b1343f2ca4895ce2d758.zip |
MultiTileEntity
Diffstat (limited to 'src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java')
-rw-r--r-- | src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java new file mode 100644 index 0000000000..feb2a0a0f5 --- /dev/null +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java @@ -0,0 +1,134 @@ +package gregtech.api.multitileentity; + +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.ITexture; +import gregtech.api.multitileentity.interfaces.IMultiTileEntity; +import gregtech.api.multitileentity.interfaces.IMultiTileEntity.IMTE_HasMultiBlockMachineRelevantData; +import gregtech.common.render.GT_Renderer_Block; +import gregtech.common.render.IRenderedBlock; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.StatCollector; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.util.GT_Util.setTileEntity; + +public class MultiTileEntityBlockInternal extends Block implements IRenderedBlock { + public MultiTileEntityRegistry mMultiTileEntityRegistry; + + public MultiTileEntityBlockInternal() { + super(Material.anvil); + } + + @Override + public void registerBlockIcons(IIconRegister aIconRegister) { /* Do Nothing */ } + + @Override + public int getRenderType() { + return GT_Renderer_Block.INSTANCE == null ? super.getRenderType() : GT_Renderer_Block.INSTANCE.mRenderID; + } + @Override public final String getUnlocalizedName() {return mMultiTileEntityRegistry.mNameInternal;} + @Override public final String getLocalizedName() {return StatCollector.translateToLocal(mMultiTileEntityRegistry.mNameInternal + ".name");} + + public boolean placeBlock(World aWorld, int aX, int aY, int aZ, byte aSide, short aMetaData, NBTTagCompound aNBT, boolean aCauseBlockUpdates, boolean aForcePlacement) { + final MultiTileEntityContainer aMTEContainer = mMultiTileEntityRegistry.getNewTileEntityContainer(aWorld, aX, aY, aZ, aMetaData, aNBT); + if (aMTEContainer == null) return false; + + final Block tReplacedBlock = aWorld.getBlock(aX, aY, aZ); + + + // This is some complicated bullshit Greg had to do to make his MTEs work right. + // Set Block with reverse MetaData first. + aWorld.setBlock(aX, aY, aZ, aMTEContainer.mBlock, 15-aMTEContainer.mBlockMetaData, 2); + // Make sure the Block has been set, yes I know setBlock has a true/false return value, but guess what, it is not reliable in 0.0001% of cases! -Greg + if (aWorld.getBlock(aX, aY, aZ) != aMTEContainer.mBlock) {aWorld.setBlock(aX, aY, aZ, Blocks.air, 0, 0); return false;} + // TileEntity should not refresh yet! -Greg + ((IMultiTileEntity)aMTEContainer.mTileEntity).setShouldRefresh(false); + // Fake-Set the TileEntity first, bypassing a lot of checks. -Greg + setTileEntity(aWorld, aX, aY, aZ, (TileEntity) aMTEContainer.mTileEntity, false); + // Now set the Block with the REAL MetaData. -Greg + setTileEntity(aWorld, aX, aY, aZ, aMTEContainer.mBlock, aMTEContainer.mBlockMetaData, 0, false); + // When the TileEntity is set now it SHOULD refresh! -Greg + ((IMultiTileEntity)aMTEContainer.mTileEntity).setShouldRefresh(true); + // But make sure again that the Block we have set was actually set properly, because 0.0001%! -Greg + if (aWorld.getBlock(aX, aY, aZ) != aMTEContainer.mBlock) {aWorld.setBlock(aX, aY, aZ, Blocks.air, 0, 0); return false;} + // And finally properly set the TileEntity for real! -Greg + setTileEntity(aWorld, aX, aY, aZ, (TileEntity) aMTEContainer.mTileEntity, aCauseBlockUpdates); + // Yep, all this just to set one Block and its TileEntity properly... -Greg + + + try { + if (aMTEContainer.mTileEntity instanceof IMTE_HasMultiBlockMachineRelevantData) { + if (((IMTE_HasMultiBlockMachineRelevantData)aMTEContainer.mTileEntity).hasMultiBlockMachineRelevantData()) GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + } catch(Throwable e) { + GT_FML_LOGGER.error("causeMachineUpdate", e); + } + + try { + if (!aWorld.isRemote && aCauseBlockUpdates) { + aWorld.notifyBlockChange(aX, aY, aZ, tReplacedBlock); + aWorld.func_147453_f(aX, aY, aZ, aMTEContainer.mBlock); + } + } catch(Throwable e) { + GT_FML_LOGGER.error("aCauseBlockUpdates", e); + } + + try { + ((IMultiTileEntity)aMTEContainer.mTileEntity).onTileEntityPlaced(); + } catch(Throwable e) { + GT_FML_LOGGER.error("onTileEntityPlaced", e); + } + + + try { + aWorld.func_147451_t/*updateAllLightTypes*/(aX, aY, aZ); + } catch(Throwable e) { + GT_FML_LOGGER.error("updateAllLightTypes", e); + } + return true; + } + + @Override + public ITexture[] getTexture(Block aBlock, byte aSide, int aRenderPass, boolean[] aShouldSideBeRendered) { + return null; + } + + @Override + public ITexture[] getTexture(Block aBlock, byte aSide, boolean isActive, int aRenderPass) { + return null; + } + + @Override + public int getRenderPasses(Block aBlock) { + return 0; + } + + @Override + public boolean usesRenderPass(int aRenderPass) { + return true; + } + + @Override + public boolean setBlockBounds(Block aBlock, int aRenderPass) { + return false; + } + + @Override + public IRenderedBlock passRenderingToObject(ItemStack aStack) { + final TileEntity tTileEntity = mMultiTileEntityRegistry.getNewTileEntity(aStack); + return tTileEntity instanceof IRenderedBlock ? (IRenderedBlock)tTileEntity : null; + } + + @Override + public IRenderedBlock passRenderingToObject(IBlockAccess aWorld, int aX, int aY, int aZ) { + return null; + } +} |