From fdde96ab6fef30064b67e28390008ee4ba455655 Mon Sep 17 00:00:00 2001 From: Maxim Date: Sat, 22 Apr 2023 17:38:49 +0200 Subject: MuTE overhaul and ACR (#1883) * complex controller start * Added methods to get input fluids and items * Added logic to complex parallel mute * Added ACR and fixed many, many, many, many bugs * Added void protection setting to checkRecipe * do not init nbt, if mteID and mteRegistry are the same * Improved GUI design * Force structure check when pressing power switch * ACR Textures * Added T1 structure * Added perfect OC * Added WAILA * fix mutes resetting their nbt * Fix ACR GUI * fix npe * Added void protection for MuTEs * Fixed ACR starting recipe while another one is ongoing * nbt saving * maybe fix structure breaking * Fix complex machine disabling on startup * correctly update input tanks * move casings over * Changed logic of casings to change mode and facing in one go by sneaking * Fixed the casing target not resetting * Added side only annotations * don't leave it empty * Added power logic and tiered blocks to ACR * Change facing to wrench side if casing mode is currently none * lasers anyone? * Added ACR item chaining * Remove unncessary item lists * Use HashSet for process whitelists * Optimize list capacities * Fix potential recipe voiding bug * Rename methods for consistancy * Fix NPE * Duct tape fix structure check * allow MuTEs to connect to cables * Added separate tank inventories for input separation (#1887) * Fixed unregistering tank function * Fixed input busses not being automatable * Added fluid chaining * Fixed saving of input tanks * Forbid inventory registering with empty name * Display all input tanks in controller GUI * Fixed fluid hatch GUI height * Reset casing lists when checking the structure * Make inventory GUI size consistant * Make use of the tooltip cache * rename thing clean up * Forgot to put tooltip into map * Added tooltip to ACR * Reset whitelists when one whitelist window was opened * Refined scanner string * Fixed progress times * Fixed MuTE not consuming fluids * Properly register controller inventories * switch to ForgeDirection * switch to new Renderer * Added missing contains check on registerInventory * Fixed output tanks not registering * Fixed upgrade tank loading * fix machines not having active/inactive textures * fix overlays not loading correctly * Don't register controller directly * Remove magic strings all * fix active not setting to inactive * allow glow * item renderer * fix glow * MuTE improved hatch GUI and fluid output locking (#1889) * Allow output hatches to be fluid locked * Reworked hatch GUI * Check target before trying to open GUI * Make ACR GUI easier to look at * fix covers not rendering on mutes * fix covers not displaying above the item/fluid in/out * new folder texture structure * Reduce network traffic caused by covers * Fixed WAILA fluid locking display * Don't save everything to the itemstack NBT * Added possibility to save NBT of MuTE to its itemstack * fix textures, but make sacrifices * mah textures * Removed the need for all textures to be present * Added glow texture for active coke oven * Removed unncesssary upgrade casing textures * shorten nbt tags --------- Co-authored-by: BlueWeabo <76872108+BlueWeabo@users.noreply.github.com> Co-authored-by: Martin Robertz Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../api/multitileentity/MultiTileEntityBlock.java | 47 +- .../MultiTileEntityBlockInternal.java | 49 +- .../MultiTileEntityClassContainer.java | 28 +- .../api/multitileentity/base/MultiTileEntity.java | 273 ++- .../base/TickableMultiTileEntity.java | 3 +- .../multitileentity/enums/GT_MultiTileCasing.java | 7 +- .../enums/GT_MultiTileComponentCasing.java | 130 ++ .../multitileentity/enums/GT_MultiTileMachine.java | 6 +- .../interfaces/IMultiBlockController.java | 10 +- .../interfaces/IMultiBlockFluidHandler.java | 6 + .../interfaces/IMultiTileEntity.java | 2 +- .../machine/MultiTileBasicMachine.java | 300 ++- .../multiblock/base/ComplexParallelController.java | 244 +++ .../multiblock/base/Controller.java | 2187 ++++++++++++++++++++ .../multiblock/base/MultiBlockController.java | 1709 --------------- .../multiblock/base/MultiBlockPart.java | 301 ++- .../multiblock/base/MultiBlockPowerController.java | 44 - .../multiblock/base/MultiBlock_Stackable.java | 111 - .../multiblock/base/PowerController.java | 89 + .../multiblock/base/StackableController.java | 111 + .../multiblock/casing/FunctionalCasing.java | 2 + 21 files changed, 3411 insertions(+), 2248 deletions(-) create mode 100644 src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileComponentCasing.java create mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/ComplexParallelController.java create mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/Controller.java delete mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockController.java delete mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlockPowerController.java delete mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/MultiBlock_Stackable.java create mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/PowerController.java create mode 100644 src/main/java/gregtech/api/multitileentity/multiblock/base/StackableController.java (limited to 'src/main/java/gregtech/api/multitileentity') diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java index 55edf332bd..b81961af95 100644 --- a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlock.java @@ -50,7 +50,6 @@ import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Textures; import gregtech.api.interfaces.IDebugableBlock; -import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IDebugableTileEntity; import gregtech.api.metatileentity.BaseTileEntity; import gregtech.api.metatileentity.CoverableTileEntity; @@ -69,15 +68,13 @@ import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; import gregtech.common.covers.CoverInfo; -import gregtech.common.render.GT_Renderer_Block; -import gregtech.common.render.IRenderedBlock; +import gregtech.common.render.GT_MultiTile_Renderer; /* * MultiTileEntityBlock ported from GT6 */ @Optional.Interface(iface = "com.cricketcraft.chisel.api.IFacade", modid = "ChiselAPI") -public class MultiTileEntityBlock extends Block - implements IDebugableBlock, ITileEntityProvider, IRenderedBlock, IFacade { +public class MultiTileEntityBlock extends Block implements IDebugableBlock, ITileEntityProvider, IFacade { protected static final Map MULTI_BLOCK_MAP = new HashMap<>(); private static boolean LOCK = false; @@ -219,7 +216,8 @@ public class MultiTileEntityBlock extends Block @Override public int getRenderType() { - return GT_Renderer_Block.INSTANCE == null ? super.getRenderType() : GT_Renderer_Block.INSTANCE.mRenderID; + return GT_MultiTile_Renderer.INSTANCE == null ? super.getRenderType() + : GT_MultiTile_Renderer.INSTANCE.getRenderId(); } @Override @@ -386,43 +384,6 @@ public class MultiTileEntityBlock extends Block } } - @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) { - // TODO: MTE(Texture) - 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) { - return null; - } - - @Override - public IRenderedBlock passRenderingToObject(IBlockAccess aWorld, int aX, int aY, int aZ) { - final TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); - return tTileEntity instanceof IRenderedBlock ? (IRenderedBlock) tTileEntity : null; - } - @Override public final boolean shouldSideBeRendered(IBlockAccess aWorld, int aX, int aY, int aZ, int aSide) { final TileEntity aTileEntity = aWorld.getTileEntity(aX - OFFX[aSide], aY - OFFY[aSide], aZ - OFFZ[aSide]); diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java index ec24654a1c..a3637e4626 100644 --- a/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityBlockInternal.java @@ -7,21 +7,16 @@ 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 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 gregtech.common.render.GT_MultiTile_Renderer; -public class MultiTileEntityBlockInternal extends Block implements IRenderedBlock { +public class MultiTileEntityBlockInternal extends Block { public MultiTileEntityRegistry mMultiTileEntityRegistry; @@ -36,7 +31,8 @@ public class MultiTileEntityBlockInternal extends Block implements IRenderedBloc @Override public int getRenderType() { - return GT_Renderer_Block.INSTANCE == null ? super.getRenderType() : GT_Renderer_Block.INSTANCE.mRenderID; + return GT_MultiTile_Renderer.INSTANCE == null ? super.getRenderType() + : GT_MultiTile_Renderer.INSTANCE.getRenderId(); } @Override @@ -115,40 +111,7 @@ public class MultiTileEntityBlockInternal extends Block implements IRenderedBloc 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) { - // TODO: MTE(Texture) - 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; + public MultiTileEntityRegistry getRegistry() { + return mMultiTileEntityRegistry; } } diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java index 4e4be793b1..3eae75f934 100644 --- a/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java @@ -12,7 +12,7 @@ import gregtech.api.multitileentity.base.MultiTileEntity; import gregtech.api.multitileentity.multiblock.casing.FunctionalCasing; import gregtech.api.multitileentity.multiblock.casing.UpgradeCasing; import gregtech.api.util.GT_Util; -import gregtech.common.tileentities.casings.upgrade.InventoryUpgrade; +import gregtech.common.tileentities.casings.upgrade.Inventory; public class MultiTileEntityClassContainer { @@ -94,25 +94,25 @@ public class MultiTileEntityClassContainer { // Need a base texture for the MTE machine, and then a separate texture set for the machine/active overlays - public MultiTileEntityClassContainer material(Materials aMaterial) { + public MultiTileEntityClassContainer material(Materials material) { // Sets the material, and the color from the material, if not already set - mParameters.setString(NBT.MATERIAL, aMaterial.toString()); - if (!mParameters.hasKey(NBT.COLOR)) mParameters.setInteger(NBT.COLOR, GT_Util.getRGBInt(aMaterial.getRGBA())); + mParameters.setString(NBT.MATERIAL, material.toString()); + if (!mParameters.hasKey(NBT.COLOR)) mParameters.setInteger(NBT.COLOR, GT_Util.getRGBInt(material.getRGBA())); return this; } - public MultiTileEntityClassContainer color(int aRPG) { - mParameters.setInteger(NBT.COLOR, aRPG); + public MultiTileEntityClassContainer color(int rbg) { + mParameters.setInteger(NBT.COLOR, rbg); return this; } - public MultiTileEntityClassContainer color(short[] aRPGA) { - mParameters.setInteger(NBT.COLOR, GT_Util.getRGBInt(aRPGA)); + public MultiTileEntityClassContainer color(short[] rgba) { + mParameters.setInteger(NBT.COLOR, GT_Util.getRGBInt(rgba)); return this; } - public MultiTileEntityClassContainer texture(String aTexture) { - mParameters.setString(NBT.TEXTURE, aTexture); + public MultiTileEntityClassContainer textureFolder(String texture) { + mParameters.setString(NBT.TEXTURE_FOLDER, texture); return this; } @@ -138,7 +138,7 @@ public class MultiTileEntityClassContainer { } public MultiTileEntityClassContainer upgradeInventorySize(int aSize) { - verifyDescendentOf(InventoryUpgrade.class); + verifyDescendentOf(Inventory.class); mParameters.setInteger(NBT.UPGRADE_INVENTORY_SIZE, aSize); return this; @@ -174,10 +174,8 @@ public class MultiTileEntityClassContainer { if (!onlyOne) { verifyDescendentOf(cls); atLeastOne = true; - } else { - if (cls.isAssignableFrom(mClass)) { - atLeastOne = true; - } + } else if (cls.isAssignableFrom(mClass)) { + atLeastOne = true; } } diff --git a/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java index 2ef1042a01..4312f99ce7 100644 --- a/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java +++ b/src/main/java/gregtech/api/multitileentity/base/MultiTileEntity.java @@ -1,12 +1,10 @@ package gregtech.api.multitileentity.base; import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.NBT; import static gregtech.api.enums.GT_Values.OPOS; -import static gregtech.api.enums.GT_Values.SIDE_WEST; import static gregtech.api.enums.GT_Values.VALID_SIDES; -import static gregtech.api.enums.GT_Values.emptyIconContainerArray; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -15,7 +13,7 @@ import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.block.Block; -import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -29,8 +27,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.Explosion; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; @@ -38,16 +36,14 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidTank; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; + import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.Materials; -import gregtech.api.enums.SoundResource; -import gregtech.api.enums.Textures; +import gregtech.api.enums.*; +import gregtech.api.enums.GT_Values.NBT; +import gregtech.api.enums.Textures.BlockIcons.CustomIcon; import gregtech.api.gui.modularui.GT_UIInfos; -import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; import gregtech.api.metatileentity.CoverableTileEntity; import gregtech.api.metatileentity.GregTechTileClientEvents; @@ -64,13 +60,18 @@ import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; -import gregtech.common.render.GT_MultiTexture; -import gregtech.common.render.IRenderedBlock; +import gregtech.common.render.MultiTileBasicRender; -public abstract class MultiTileEntity extends CoverableTileEntity implements IMultiTileEntity, IRenderedBlock { +public abstract class MultiTileEntity extends CoverableTileEntity + implements IMultiTileEntity.IMTE_BreakBlock, MultiTileBasicRender { - public IIconContainer[] textures = emptyIconContainerArray; - // public IIconContainer[] mTexturesFront = emptyIconContainerArray; + private ITexture baseTexture = null; + private ITexture topOverlayTexture = null; + private ITexture bottomOverlayTexture = null; + private ITexture leftOverlayTexture = null; + private ITexture rightOverlayTexture = null; + private ITexture backOverlayTexture = null; + private ITexture frontOverlayTexture = null; // Makes a Bounding Box without having to constantly specify the Offset Coordinates. protected static final float[] PX_BOX = { 0, 0, 0, 1, 1, 1 }; @@ -87,7 +88,8 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu protected boolean needsUpdate = false; protected boolean hasInventoryChanged = false; protected boolean isPainted = false; - protected byte facing = SIDE_WEST; // Default to WEST, so it renders facing Left in the inventory + protected ForgeDirection facing = ForgeDirection.WEST; // Default to WEST, so it renders facing Left in the + // inventory protected byte color; protected int rgba = GT_Values.UNCOLORED; private short mteID = GT_Values.W, mteRegistry = GT_Values.W; @@ -117,6 +119,9 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu @Override public void initFromNBT(NBTTagCompound nbt, short mteID, short mteRegistry) { + if (this.mteID == mteID && this.mteRegistry == mteRegistry) { + return; + } // Set ID and Registry ID. this.mteID = mteID; this.mteRegistry = mteRegistry; @@ -125,13 +130,31 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu } @Override - public void loadTextureNBT(NBTTagCompound nbt) { + public void loadTextures(String folder) { // Loading the registry - final String textureName = nbt.getString(NBT.TEXTURE); - textures = new IIconContainer[] { - new Textures.BlockIcons.CustomIcon("multitileentity/base/" + textureName + "/bottom"), - new Textures.BlockIcons.CustomIcon("multitileentity/base/" + textureName + "/top"), - new Textures.BlockIcons.CustomIcon("multitileentity/base/" + textureName + "/side"), }; + for (SidedTextureNames textureName : SidedTextureNames.TEXTURES) { + ITexture texture; + try { + Minecraft.getMinecraft() + .getResourceManager() + .getResource( + new ResourceLocation( + Mods.GregTech.ID, + "textures/blocks/multitileentity/" + folder + "/" + textureName.getName() + ".png")); + texture = TextureFactory.of(new CustomIcon("multitileentity/" + folder + "/" + textureName.getName())); + } catch (IOException ignored) { + texture = TextureFactory.of(Textures.BlockIcons.VOID); + } + switch (textureName) { + case Top -> topOverlayTexture = texture; + case Bottom -> bottomOverlayTexture = texture; + case Back -> backOverlayTexture = texture; + case Front -> frontOverlayTexture = texture; + case Left -> leftOverlayTexture = texture; + case Right -> rightOverlayTexture = texture; + case Base -> baseTexture = texture; + } + } } @Override @@ -139,8 +162,48 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu // Loading an instance final TileEntity tCanonicalTileEntity = MultiTileEntityRegistry .getCanonicalTileEntity(getMultiTileEntityRegistryID(), getMultiTileEntityID()); - if (tCanonicalTileEntity instanceof MultiTileEntity) - textures = ((MultiTileEntity) tCanonicalTileEntity).textures; + if (!(tCanonicalTileEntity instanceof MultiTileEntity)) { + return; + } + final MultiTileEntity canonicalEntity = (MultiTileEntity) tCanonicalTileEntity; + baseTexture = canonicalEntity.baseTexture; + topOverlayTexture = canonicalEntity.topOverlayTexture; + bottomOverlayTexture = canonicalEntity.bottomOverlayTexture; + leftOverlayTexture = canonicalEntity.leftOverlayTexture; + rightOverlayTexture = canonicalEntity.rightOverlayTexture; + backOverlayTexture = canonicalEntity.backOverlayTexture; + frontOverlayTexture = canonicalEntity.frontOverlayTexture; + } + + @Override + public ITexture getTexture(ForgeDirection side) { + if (facing == side) { + return TextureFactory.of(baseTexture, frontOverlayTexture); + } + + if (facing.getOpposite() == side) { + return TextureFactory.of(baseTexture, backOverlayTexture); + } + + if (side == ForgeDirection.UP) { + return TextureFactory.of(baseTexture, topOverlayTexture); + } + + if (side == ForgeDirection.DOWN) { + return TextureFactory.of(baseTexture, bottomOverlayTexture); + } + + if (facing.getRotation(ForgeDirection.DOWN) == side) { + return TextureFactory.of(baseTexture, rightOverlayTexture); + } else { + return TextureFactory.of(baseTexture, leftOverlayTexture); + } + } + + @Override + public ITexture[] getTexture(Block ignoredBlock, byte ignoredSide) { + // We are not going to be using this + return null; } @Override @@ -181,15 +244,17 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu ownerUUID = null; } if (nbt.hasKey(NBT.LOCK_UPGRADE)) lockUpgrade = nbt.getBoolean(NBT.LOCK_UPGRADE); - if (nbt.hasKey(NBT.FACING)) facing = nbt.getByte(NBT.FACING); + if (nbt.hasKey(NBT.FACING)) facing = ForgeDirection.getOrientation(nbt.getInteger(NBT.FACING)); readCoverNBT(nbt); readMultiTileNBT(nbt); - if (GregTech_API.sBlockIcons == null && nbt.hasKey(NBT.TEXTURE)) { - loadTextureNBT(nbt); - } else { - copyTextures(); + if (NetworkUtils.isDedicatedClient()) { + if (GregTech_API.sBlockIcons == null && nbt.hasKey(NBT.TEXTURE_FOLDER)) { + loadTextures(nbt.getString(NBT.TEXTURE_FOLDER)); + } else { + copyTextures(); + } } if (mSidedRedstone.length != 6) mSidedRedstone = new byte[] { 15, 15, 15, 15, 15, 15 }; @@ -228,7 +293,7 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu aNBT.setString(NBT.OWNER, ownerName); aNBT.setString(NBT.OWNER_UUID, ownerUUID == null ? "" : ownerUUID.toString()); aNBT.setBoolean(NBT.LOCK_UPGRADE, lockUpgrade); - aNBT.setByte(NBT.FACING, facing); + aNBT.setInteger(NBT.FACING, facing.ordinal()); writeCoverNBT(aNBT, false); writeMultiTileNBT(aNBT); @@ -244,10 +309,16 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu @Override public NBTTagCompound writeItemNBT(NBTTagCompound aNBT) { writeCoverNBT(aNBT, true); - + if (shouldSaveNBTToItemStack()) { + writeMultiTileNBT(aNBT); + } return aNBT; } + protected boolean shouldSaveNBTToItemStack() { + return false; + } + @Override public boolean useModularUI() { return false; @@ -321,69 +392,6 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu return true; } - @Override - @SideOnly(Side.CLIENT) - public final IRenderedBlock passRenderingToObject(ItemStack aStack) { - return this; - } - - @Override - @SideOnly(Side.CLIENT) - public final IRenderedBlock passRenderingToObject(IBlockAccess aWorld, int aX, int aY, int aZ) { - return this; - } - - @Override - public int getRenderPasses(Block aBlock) { - return 1; - } - - @Override - public boolean usesRenderPass(int aRenderPass) { - return true; - } - - @Override - public boolean setBlockBounds(Block aBlock, int aRenderPass) { - return false; - } - - @Override - public boolean renderItem(Block aBlock, RenderBlocks aRenderer) { - return false; - } - - @Override - public boolean renderBlock(Block aBlock, RenderBlocks aRenderer, IBlockAccess aWorld, int aX, int aY, int aZ) { - return false; - } - - @Override - public ITexture[] getTexture(Block aBlock, byte aSide) { - return getTexture(aBlock, aSide, 1, VALID_SIDES); - } - - @Override - public final ITexture[] getTexture(Block aBlock, byte aSide, int aRenderPass, boolean[] aShouldSideBeRendered) { - if (!aShouldSideBeRendered[aSide]) return null; - - final ITexture coverTexture = getCoverTexture(aSide); - final ITexture[] textureUncovered = getTexture(aBlock, aSide, true, aRenderPass); - - if (coverTexture != null) { - return new ITexture[] { GT_MultiTexture.get(textureUncovered), coverTexture }; - } else { - return textureUncovered; - } - } - - @Override - public ITexture[] getTexture(Block aBlock, byte aSide, boolean isActive, int aRenderPass) { - // Top, bottom or side - aSide = (byte) Math.min(aSide, 2); - return new ITexture[] { TextureFactory.of(textures[aSide], GT_Util.getRGBaArray(rgba)) }; - } - @Override public void setCustomName(String aName) { customName = aName; @@ -428,18 +436,18 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu @Override public byte getFrontFacing() { - return facing; + return (byte) facing.ordinal(); } /** * Sets the main facing to {aSide} and update as appropriately - * + * * @return Whether the facing was changed */ @Override public boolean setMainFacing(byte aSide) { if (!isValidFacing(aSide)) return false; - facing = aSide; + facing = ForgeDirection.getOrientation(aSide); issueClientUpdate(); issueBlockUpdate(); @@ -464,7 +472,8 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu @Override public byte getBackFacing() { - return GT_Utility.getOppositeSide(facing); + return (byte) facing.getOpposite() + .ordinal(); } @Override @@ -700,7 +709,8 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu @Override public boolean onPlaced(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, byte aSide, float aHitX, float aHitY, float aHitZ) { - facing = getSideForPlayerPlacing(aPlayer, facing, getValidFacings()); + facing = ForgeDirection + .getOrientation(getSideForPlayerPlacing(aPlayer, (byte) facing.ordinal(), getValidFacings())); onFacingChange(); return true; } @@ -922,9 +932,14 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu final ArrayList rList = new ArrayList<>(); final MultiTileEntityRegistry tRegistry = MultiTileEntityRegistry.getRegistry(getMultiTileEntityRegistryID()); if (tRegistry != null) rList.add(tRegistry.getItem(getMultiTileEntityID(), writeItemNBT(new NBTTagCompound()))); + return rList; + } + @Override + public boolean breakBlock() { + isDead = true; onBaseTEDestroyed(); - return rList; + return false; } @Override @@ -975,7 +990,7 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu zCoord, getMultiTileEntityRegistryID(), getMultiTileEntityID(), - (byte) ((facing & 7) | (mRedstone ? 16 : 0)), + (byte) ((facing.ordinal() & 7) | (mRedstone ? 16 : 0)), color); packet.setCoverData( @@ -1014,7 +1029,7 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu issueTextureUpdate(); switch (aEventID) { case GregTechTileClientEvents.CHANGE_COMMON_DATA: - facing = (byte) (aValue & 7); + facing = ForgeDirection.getOrientation(aValue & 7); // mActive = ((aValue & 8) != 0); mRedstone = ((aValue & 16) != 0); // mLockUpgrade = ((aValue&32) != 0); @@ -1096,9 +1111,6 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu + mteID + EnumChatFormatting.RESET); } - if (joinedIc2Enet) tList.add("Joined IC2 ENet"); - - tList.add("Energy: " + getUniversalEnergyStored() + "/" + getUniversalEnergyCapacity()); addDebugInfo(aPlayer, aLogLevel, tList); @@ -1395,4 +1407,51 @@ public abstract class MultiTileEntity extends CoverableTileEntity implements IMu public ItemStack getStackForm(long aAmount) { return new ItemStack(Item.getItemById(getMultiTileEntityRegistryID()), (int) aAmount, getMultiTileEntityID()); } + + protected enum SidedTextureNames { + + Base("base"), + Left("left"), + Right("right"), + Top("top"), + Bottom("bottom"), + Back("back"), + Front("front"); + + private final String name; + public static final SidedTextureNames[] TEXTURES = { Base, Left, Right, Top, Bottom, Back, Front }; + + SidedTextureNames(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + protected enum StatusTextures { + + Active("active", false), + ActiveWithGlow("active_glow", true), + Inactive("inactive", false), + InactiveWithGlow("inactive_glow", true); + + private final String name; + private final boolean hasGlow; + public static final StatusTextures[] TEXTURES = { Active, ActiveWithGlow, Inactive, InactiveWithGlow }; + + StatusTextures(String name, boolean hasGlow) { + this.name = name; + this.hasGlow = hasGlow; + } + + public String getName() { + return name; + } + + public boolean hasGlow() { + return hasGlow; + } + } } diff --git a/src/main/java/gregtech/api/multitileentity/base/TickableMultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/base/TickableMultiTileEntity.java index 25a9edd9ac..4fa06ff6b4 100644 --- a/src/main/java/gregtech/api/multitileentity/base/TickableMultiTileEntity.java +++ b/src/main/java/gregtech/api/multitileentity/base/TickableMultiTileEntity.java @@ -39,7 +39,6 @@ public abstract class TickableMultiTileEntity extends MultiTileEntity implements return; } onPreTick(timer, isServerSide); - timer++; super.updateEntity(); if (!isServerSide && needsUpdate) { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); @@ -67,7 +66,7 @@ public abstract class TickableMultiTileEntity extends MultiTileEntity implements @Override public void sendClientData(EntityPlayerMP aPlayer) { if (sendClientData) { - GT_FML_LOGGER.info("Sending client data"); + // GT_FML_LOGGER.info("Sending client data"); super.sendClientData(aPlayer); sendClientData = false; } diff --git a/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileCasing.java b/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileCasing.java index be74ca3ef2..baa235ccf1 100644 --- a/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileCasing.java +++ b/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileCasing.java @@ -5,15 +5,16 @@ import gregtech.api.enums.GT_Values; public enum GT_MultiTileCasing { CokeOven(0), + Chemical(1), NONE(GT_Values.W); - private final short meta; + private final int meta; GT_MultiTileCasing(int meta) { - this.meta = (short) meta; + this.meta = meta; } - public short getId() { + public int getId() { return meta; } } diff --git a/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileComponentCasing.java b/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileComponentCasing.java new file mode 100644 index 0000000000..e062ecc705 --- /dev/null +++ b/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileComponentCasing.java @@ -0,0 +1,130 @@ +package gregtech.api.multitileentity.enums; + +import gregtech.api.enums.GT_Values; + +public enum GT_MultiTileComponentCasing { + + LV_Motor(0), + MV_Motor(1), + HV_Motor(2), + EV_Motor(3), + IV_Motor(4), + LuV_Motor(5), + ZPM_Motor(6), + UV_Motor(7), + UHV_Motor(8), + UEV_Motor(9), + UIV_Motor(10), + UMV_Motor(11), + UXV_Motor(12), + MAX_Motor(13), + LV_Pump(14), + MV_Pump(15), + HV_Pump(16), + EV_Pump(17), + IV_Pump(18), + LuV_Pump(19), + ZPM_Pump(20), + UV_Pump(21), + UHV_Pump(22), + UEV_Pump(23), + UIV_Pump(24), + UMV_Pump(25), + UXV_Pump(26), + MAX_Pump(27), + LV_Conveyor(28), + MV_Conveyor(29), + HV_Conveyor(30), + EV_Conveyor(31), + IV_Conveyor(32), + LuV_Conveyor(33), + ZPM_Conveyor(34), + UV_Conveyor(35), + UHV_Conveyor(36), + UEV_Conveyor(37), + UIV_Conveyor(38), + UMV_Conveyor(39), + UXV_Conveyor(40), + MAX_Conveyor(41), + LV_Piston(42), + MV_Piston(43), + HV_Piston(44), + EV_Piston(45), + IV_Piston(46), + LuV_Piston(47), + ZPM_Piston(48), + UV_Piston(49), + UHV_Piston(50), + UEV_Piston(51), + UIV_Piston(52), + UMV_Piston(53), + UXV_Piston(54), + MAX_Piston(55), + LV_RobotArm(56), + MV_RobotArm(57), + HV_RobotArm(58), + EV_RobotArm(59), + IV_RobotArm(60), + LuV_RobotArm(61), + ZPM_RobotArm(62), + UV_RobotArm(63), + UHV_RobotArm(64), + UEV_RobotArm(65), + UIV_RobotArm(66), + UMV_RobotArm(67), + UXV_RobotArm(68), + MAX_RobotArm(69), + LV_Emitter(70), + MV_Emitter(71), + HV_Emitter(72), + EV_Emitter(73), + IV_Emitter(74), + LuV_Emitter(75), + ZPM_Emitter(76), + UV_Emitter(77), + UHV_Emitter(78), + UEV_Emitter(79), + UIV_Emitter(80), + UMV_Emitter(81), + UXV_Emitter(82), + MAX_Emitter(83), + LV_Sensor(84), + MV_Sensor(85), + HV_Sensor(86), + EV_Sensor(87), + IV_Sensor(88), + LuV_Sensor(89), + ZPM_Sensor(90), + UV_Sensor(91), + UHV_Sensor(92), + UEV_Sensor(93), + UIV_Sensor(94), + UMV_Sensor(95), + UXV_Sensor(96), + MAX_Sensor(97), + LV_FieldGenerator(98), + MV_FieldGenerator(99), + HV_FieldGenerator(100), + EV_FieldGenerator(101), + IV_FieldGenerator(102), + LuV_FieldGenerator(103), + ZPM_FieldGenerator(104), + UV_FieldGenerator(105), + UHV_FieldGenerator(106), + UEV_FieldGenerator(107), + UIV_FieldGenerator(108), + UMV_FieldGenerator(109), + UXV_FieldGenerator(110), + MAX_FieldGenerator(111), + NONE(GT_Values.W); + + private final int meta; + + GT_MultiTileComponentCasing(int meta) { + this.meta = meta; + } + + public int getId() { + return meta; + } +} diff --git a/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileMachine.java b/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileMachine.java index 0fc8f3dafd..7cdde78986 100644 --- a/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileMachine.java +++ b/src/main/java/gregtech/api/multitileentity/enums/GT_MultiTileMachine.java @@ -7,13 +7,13 @@ public enum GT_MultiTileMachine { CokeOven(0), NONE(GT_Values.W); - private final short meta; + private final int meta; GT_MultiTileMachine(int meta) { - this.meta = (short) meta; + this.meta = meta; } - public short getId() { + public int getId() { return meta; } } diff --git a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java index 21e1328d27..1168f8e7ce 100644 --- a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java +++ b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockController.java @@ -1,8 +1,12 @@ package gregtech.api.multitileentity.interfaces; import net.minecraft.util.ChunkCoordinates; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.api.logic.PowerLogic; public interface IMultiBlockController extends IMultiTileEntity, IMultiBlockFluidHandler, IMultiBlockInventory { @@ -17,6 +21,8 @@ public interface IMultiBlockController extends IMultiTileEntity, IMultiBlockFlui FluidStack getDrainableFluid(byte aSide); + FluidStack getDrainableFluid(byte aSide, Fluid fluid); + boolean isLiquidInput(byte aSide); boolean isLiquidOutput(byte aSide); @@ -31,5 +37,7 @@ public interface IMultiBlockController extends IMultiTileEntity, IMultiBlockFlui void changeInventoryName(String aName, String aID, int aType); - PowerLogic getPowerLogic(IMultiBlockPart part, byte side); + PowerLogic getPowerLogic(IMultiBlockPart part, ForgeDirection side); + + ModularWindow createWindowGUI(UIBuildContext buildContext); } diff --git a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockFluidHandler.java b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockFluidHandler.java index 045a173e94..b513f51324 100644 --- a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockFluidHandler.java +++ b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiBlockFluidHandler.java @@ -1,5 +1,7 @@ package gregtech.api.multitileentity.interfaces; +import java.util.List; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -23,4 +25,8 @@ public interface IMultiBlockFluidHandler { FluidTankInfo[] getTankInfo(MultiBlockPart aPart, ForgeDirection aDirection); IFluidTank[] getFluidTanksForGUI(MultiBlockPart aPart); + + List getTankArrayNames(MultiBlockPart aPart); + + List getTankArrayIDs(MultiBlockPart aPart); } diff --git a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiTileEntity.java index b42aa35195..cafde57de5 100644 --- a/src/main/java/gregtech/api/multitileentity/interfaces/IMultiTileEntity.java +++ b/src/main/java/gregtech/api/multitileentity/interfaces/IMultiTileEntity.java @@ -71,7 +71,7 @@ public interface IMultiTileEntity @Override boolean isDead(); - void loadTextureNBT(NBTTagCompound aNBT); + void loadTextures(String folder); void copyTextures(); diff --git a/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java b/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java index e50236c93b..f3cc00692c 100644 --- a/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java +++ b/src/main/java/gregtech/api/multitileentity/machine/MultiTileBasicMachine.java @@ -1,12 +1,12 @@ package gregtech.api.multitileentity.machine; import static com.google.common.primitives.Ints.saturatedCast; -import static gregtech.api.enums.GT_Values.B; -import static gregtech.api.enums.GT_Values.emptyIconContainerArray; +import static gregtech.api.enums.GT_Values.*; +import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; -import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -16,6 +16,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; @@ -24,13 +26,10 @@ import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.enums.GT_Values; +import gregtech.api.enums.*; import gregtech.api.enums.GT_Values.NBT; -import gregtech.api.enums.SoundResource; -import gregtech.api.enums.Textures; -import gregtech.api.enums.TickTime; +import gregtech.api.enums.Textures.BlockIcons.CustomIcon; import gregtech.api.fluid.FluidTankGT; -import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; import gregtech.api.logic.PollutionLogic; import gregtech.api.logic.PowerLogic; @@ -44,7 +43,6 @@ import gregtech.api.multitileentity.base.TickableMultiTileEntity; import gregtech.api.multitileentity.interfaces.IMultiTileMachine; import gregtech.api.net.GT_Packet_MultiTileEntity; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; import gregtech.client.GT_SoundLoop; import gregtech.common.GT_Pollution; @@ -59,9 +57,10 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl protected static final IItemHandlerModifiable EMPTY_INVENTORY = new ItemStackHandler(0); - private static final String TEXTURE_LOCATION = "multitileentity/machines/"; - public IIconContainer[] texturesInactive = emptyIconContainerArray; - public IIconContainer[] texturesActive = emptyIconContainerArray; + public ITexture activeOverlayTexture = null; + public ITexture activeOverlayGlowTexture = null; + public ITexture inactiveOverlayTexture = null; + public ITexture inactiveOverlayGlowTexture = null; protected int maxParallel = 1; protected boolean active = false; @@ -82,15 +81,15 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl protected IItemHandlerModifiable inputInventory = EMPTY_INVENTORY; protected IItemHandlerModifiable outputInventory = EMPTY_INVENTORY; protected boolean outputInventoryChanged = false; - private boolean powerShutDown = false; - private boolean wasEnabled = false; - private boolean canWork = true; - private boolean isElectric = true; - private boolean isSteam = false; - private boolean acceptsFuel = false; - private boolean isWireless = false; - private byte soundEvent = 0; - private int soundEventValue = 0; + protected boolean powerShutDown = false; + protected boolean wasEnabled = false; + protected boolean canWork = true; + protected boolean isElectric = true; + protected boolean isSteam = false; + protected boolean acceptsFuel = false; + protected boolean isWireless = false; + protected byte soundEvent = 0; + protected int soundEventValue = 0; @SideOnly(Side.CLIENT) protected GT_SoundLoop activitySoundLoop; @@ -221,7 +220,8 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl .readFromNBT(nbt, NBT.TANK_IN + i); } for (int i = 0; i < outputTanks.length; i++) { - outputTanks[i] = new FluidTankGT().readFromNBT(nbt, NBT.TANK_OUT + i); + outputTanks[i] = new FluidTankGT(capacity).setCapacityMultiplier(maxParallel * 2L) + .readFromNBT(nbt, NBT.TANK_OUT + i); } for (int i = 0; i < fluidsToOutput.length; i++) { @@ -258,56 +258,67 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl } @Override - public void loadTextureNBT(NBTTagCompound aNBT) { - // Loading the registry - final String textureName = aNBT.getString(NBT.TEXTURE); - textures = new IIconContainer[] { - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/bottom"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/top"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/left"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/front"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/right"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/side") }; - texturesInactive = new IIconContainer[] { - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/inactive/bottom"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/inactive/top"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/inactive/left"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/inactive/front"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/inactive/right"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/inactive/back") }; - texturesActive = new IIconContainer[] { - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/active/bottom"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/active/top"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/active/left"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/active/front"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/active/right"), - new Textures.BlockIcons.CustomIcon(TEXTURE_LOCATION + textureName + "/overlay/active/back") }; + public void loadTextures(String folder) { + super.loadTextures(folder); + for (StatusTextures textureName : StatusTextures.TEXTURES) { + ITexture texture = null; + try { + Minecraft.getMinecraft() + .getResourceManager() + .getResource( + new ResourceLocation( + Mods.GregTech.ID, + "textures/blocks/multitileentity/" + folder + "/" + textureName.getName() + ".png")); + } catch (IOException ignored) { + texture = TextureFactory.of(Textures.BlockIcons.VOID); + } + if (texture == null) { + if (textureName.hasGlow()) { + texture = TextureFactory.builder() + .addIcon(new CustomIcon("multitileentity/" + folder + "/" + textureName.getName())) + .glow() + .build(); + } else { + texture = TextureFactory + .of(new CustomIcon("multitileentity/" + folder + "/" + textureName.getName())); + } + } + switch (textureName) { + case Active -> activeOverlayTexture = texture; + case ActiveWithGlow -> activeOverlayGlowTexture = texture; + case Inactive -> inactiveOverlayTexture = texture; + case InactiveWithGlow -> inactiveOverlayGlowTexture = texture; + } + } } @Override public void copyTextures() { - // Loading an instance + super.copyTextures(); final TileEntity tCanonicalTileEntity = MultiTileEntityRegistry .getCanonicalTileEntity(getMultiTileEntityRegistryID(), getMultiTileEntityID()); - if (tCanonicalTileEntity instanceof MultiTileBasicMachine) { - textures = ((MultiTileBasicMachine) tCanonicalTileEntity).textures; - texturesInactive = ((MultiTileBasicMachine) tCanonicalTileEntity).texturesInactive; - texturesActive = ((MultiTileBasicMachine) tCanonicalTileEntity).texturesActive; - } else { - textures = texturesInactive = texturesActive = emptyIconContainerArray; + if (!(tCanonicalTileEntity instanceof MultiTileBasicMachine)) { + return; } + final MultiTileBasicMachine canonicalEntity = (MultiTileBasicMachine) tCanonicalTileEntity; + activeOverlayTexture = canonicalEntity.activeOverlayTexture; + activeOverlayGlowTexture = canonicalEntity.activeOverlayGlowTexture; + inactiveOverlayTexture = canonicalEntity.inactiveOverlayTexture; + inactiveOverlayGlowTexture = canonicalEntity.inactiveOverlayGlowTexture; } @Override - public ITexture[] getTexture(Block aBlock, byte aSide, boolean isActive, int aRenderPass) { - if (aSide != facing) { - return new ITexture[] { - TextureFactory.of(textures[GT_Values.FACING_ROTATIONS[facing][aSide]], GT_Util.getRGBaArray(rgba)) }; + public ITexture getTexture(ForgeDirection side) { + ITexture texture = super.getTexture(side); + if (side == facing) { + if (isActive()) { + return TextureFactory.of(texture, activeOverlayTexture, activeOverlayGlowTexture); + } + + return TextureFactory.of(texture, inactiveOverlayTexture, inactiveOverlayGlowTexture); } - return new ITexture[] { - TextureFactory.of(textures[GT_Values.FACING_ROTATIONS[facing][aSide]], GT_Util.getRGBaArray(rgba)), - TextureFactory - .of((active ? texturesActive : texturesInactive)[GT_Values.FACING_ROTATIONS[facing][aSide]]) }; + + return TextureFactory.of(texture, getCoverTexture((byte) side.ordinal())); } @Override @@ -358,12 +369,12 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl @Override public boolean isLiquidInput(byte aSide) { - return aSide != facing; + return facing.compareTo(ForgeDirection.getOrientation(aSide)) != 0; } @Override public boolean isLiquidOutput(byte aSide) { - return aSide != facing; + return facing.compareTo(ForgeDirection.getOrientation(aSide)) != 0; } @Override @@ -386,8 +397,13 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl @Override public IFluidTank getFluidTankFillable(byte aSide, FluidStack aFluidToFill) { - if (!isLiquidInput(aSide)) return null; - for (FluidTankGT tankGT : inputTanks) if (tankGT.contains(aFluidToFill)) return tankGT; + return getFluidTankFillable((byte) facing.ordinal(), aSide, aFluidToFill); + } + + public IFluidTank getFluidTankFillable(byte sideSource, byte sideDestination, FluidStack fluidToFill) { + if (ForgeDirection.getOrientation(sideSource) + .compareTo(ForgeDirection.getOrientation(sideDestination)) != 0) return null; + for (FluidTankGT tankGT : inputTanks) if (tankGT.contains(fluidToFill)) return tankGT; // if (!mRecipes.containsInput(aFluidToFill, this, slot(mRecipes.mInputItemsCount + // mRecipes.mOutputItemsCount))) return null; for (FluidTankGT fluidTankGT : inputTanks) if (fluidTankGT.isEmpty()) return fluidTankGT; @@ -396,9 +412,14 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl @Override protected IFluidTank getFluidTankDrainable(byte aSide, FluidStack aFluidToDrain) { - if (!isLiquidOutput(aSide)) return null; + return getFluidTankDrainable((byte) facing.ordinal(), aSide, aFluidToDrain); + } + + protected IFluidTank getFluidTankDrainable(byte sideSource, byte sideDestination, FluidStack fluidToDrain) { + if (ForgeDirection.getOrientation(sideSource) + .compareTo(ForgeDirection.getOrientation(sideDestination)) != 0) return null; for (FluidTankGT fluidTankGT : outputTanks) - if (aFluidToDrain == null ? fluidTankGT.has() : fluidTankGT.contains(aFluidToDrain)) return fluidTankGT; + if (fluidToDrain == null ? fluidTankGT.has() : fluidTankGT.contains(fluidToDrain)) return fluidTankGT; return null; } @@ -428,7 +449,7 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl @Override public boolean isItemValidForSlot(int aSlot, ItemStack aStack) { - return false; + return true; } @Override @@ -518,9 +539,8 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl } ProcessingLogic logic = ((ProcessingLogicHost) this).getProcessingLogic(); logic.clear(); - boolean result = logic.setInputItems( - inputInventory.getStacks() - .toArray(new ItemStack[0])) + boolean result = logic.setInputItems(getInputItems()) + .setInputFluids(getInputFluids()) .setCurrentOutputItems( outputInventory.getStacks() .toArray(new ItemStack[0])) @@ -554,13 +574,13 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl * Runs only on server side */ protected void consumeEnergy() { - PowerLogic logic = ((PowerLogicHost) this).getPowerLogic(GT_Values.SIDE_UNKNOWN); + PowerLogic logic = ((PowerLogicHost) this).getPowerLogic(ForgeDirection.UNKNOWN); if (logic == null) { return; } - if (logic.removeEnergyUnsafe(eut)) { + if (!logic.removeEnergyUnsafe(eut)) { stopMachine(true); } } @@ -591,6 +611,7 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl return 100; } + @SideOnly(Side.CLIENT) protected void doActivitySound(ResourceLocation activitySound) { if (isActive() && activitySound != null) { if (activitySoundLoop == null) { @@ -606,36 +627,65 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl } } + @SideOnly(Side.CLIENT) protected ResourceLocation getActivitySoundLoop() { return null; } + protected ItemStack[] getInputItems() { + return inputInventory.getStacks() + .toArray(new ItemStack[0]); + } + + protected FluidStack[] getInputFluids() { + return Arrays.stream(inputTanks) + .map(FluidTankGT::get) + .toArray(FluidStack[]::new); + } + protected void outputItems() { - if (itemsToOutput == null) { + outputItems(itemsToOutput); + itemsToOutput = null; + } + + protected void outputItems(ItemStack... itemsToOutput) { + outputItems(outputInventory, itemsToOutput); + } + + protected void outputItems(IItemHandlerModifiable inventory, ItemStack... itemsToOutput) { + if (itemsToOutput == null || inventory == null) { return; } for (ItemStack item : itemsToOutput) { int index = 0; - while (item != null && item.stackSize > 0 && index < outputInventory.getSlots()) { - item = outputInventory.insertItem(index++, item.copy(), false); + while (item != null && item.stackSize > 0 && index < inventory.getSlots()) { + item = inventory.insertItem(index++, item.copy(), false); } } - itemsToOutput = null; } protected void outputFluids() { + outputFluids(fluidsToOutput); + fluidsToOutput = null; + } + + protected void outputFluids(FluidStack... fluidsToOutput) { + outputFluids(outputTanks, fluidsToOutput); + } + + protected void outputFluids(FluidTankGT[] tankArray, FluidStack... fluidsToOutput) { if (fluidsToOutput == null) { return; } for (FluidStack fluid : fluidsToOutput) { - tryToFillTanks(fluid, outputTanks); + tryToFillTanks(fluid, tankArray); } } protected void tryToFillTanks(FluidStack fluid, FluidTankGT... tanks) { for (FluidTankGT tank : tanks) { if (tank.canFillAll(fluid)) { - tank.add(fluid.amount, fluid); + fluid.amount -= tank.add(fluid.amount, fluid); } } } @@ -756,14 +806,77 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl @Override protected void addDebugInfo(EntityPlayer player, int logLevel, ArrayList list) { - if (isElectric()) { - list.add( - "Energy: " + EnumChatFormatting.GOLD + getUniversalEnergyStored() + "/" + getUniversalEnergyCapacity()); - } + list.add( + GT_Utility.trans("186", "Owned by: ") + EnumChatFormatting.BLUE + + getOwnerName() + + EnumChatFormatting.RESET + + " (" + + EnumChatFormatting.AQUA + + getOwnerUuid() + + EnumChatFormatting.RESET + + ")"); if (acceptsFuel()) { list.add("Fuel: " + EnumChatFormatting.GOLD + burnTime + "/" + totalBurnTime); } + + if (this instanceof PowerLogicHost powerLogicHost) { + PowerLogic logic = powerLogicHost.getPowerLogic(facing); + if (isElectric) { + list.add( + StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(logic.getStoredEnergy()) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(logic.getCapacity()) + + EnumChatFormatting.RESET + + " EU"); + list.add( + StatCollector.translateToLocal("GT5U.multiblock.usage") + ": " + + EnumChatFormatting.RED + + GT_Utility.formatNumbers(eut) + + EnumChatFormatting.RESET + + " EU/t"); + list.add( + StatCollector.translateToLocal("GT5U.multiblock.mei") + ": " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(logic.getVoltage()) + + EnumChatFormatting.RESET + // TODO: Put ampere getter here, once that's variable + + " EU/t(*2A) " + + StatCollector.translateToLocal("GT5U.machines.tier") + + ": " + + EnumChatFormatting.YELLOW + + VN[GT_Utility.getTier(logic.getVoltage())] + + EnumChatFormatting.RESET); + } + } + + addProgressStringToScanner(player, logLevel, list); + + // TODO: Add CPU load calculator + list.add( + "Average CPU load of ~" + GT_Utility.formatNumbers(0) + + "ns over " + + GT_Utility.formatNumbers(0) + + " ticks with worst time of " + + GT_Utility.formatNumbers(0) + + "ns."); + } + + protected void addProgressStringToScanner(EntityPlayer player, int logLevel, ArrayList list) { + list.add( + StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(progressTime > 20 ? progressTime / 20 : progressTime) + + EnumChatFormatting.RESET + + (progressTime > 20 ? " s / " : " ticks / ") + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(maxProgressTime > 20 ? maxProgressTime / 20 : maxProgressTime) + + EnumChatFormatting.RESET + + (maxProgressTime > 20 ? " s" : " ticks")); } protected void stopMachine(boolean powerShutDown) { @@ -783,6 +896,25 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl inputInventory.setStackInSlot(i, null); } } + + for (FluidTankGT inputTank : inputTanks) { + if (inputTank == null) { + continue; + } + + if (inputTank.get() != null && inputTank.get().amount <= 0) { + inputTank.setEmpty(); + continue; + } + + FluidStack afterRecipe = inputTank.get(); + FluidStack beforeRecipe = inputTank.get(Integer.MAX_VALUE); + if (afterRecipe == null || beforeRecipe == null) { + continue; + } + int difference = beforeRecipe.amount - afterRecipe.amount; + inputTank.remove(difference); + } } /** @@ -817,6 +949,8 @@ public abstract class MultiTileBasicMachine extends TickableMultiTileEntity impl public void setBooleans(int booleans) { if ((booleans & ACTIVE) == ACTIVE) { setActive(true); + } else { + setActive(false); } } diff --git a/src/main/java/gregtech/api/multitileentity/multiblock/base/ComplexParallelController.java b/src/main/java/gregtech/api/multitileentity/multiblock/base/ComplexParallelController.java new file mode 100644 index 0000000000..ecdeb2294d --- /dev/null +++ b/src/main/java/gregtech/api/multitileentity/multiblock/base/ComplexParallelController.java @@ -0,0 +1,244 @@ +package gregtech.api.multitilee