From 546b42d7440839477455b818133d80221c70c582 Mon Sep 17 00:00:00 2001
From: Glease <4586901+Glease@users.noreply.github.com>
Date: Sat, 29 May 2021 23:52:15 +0800
Subject: Initial StructureLib integration
---
src/main/java/gregtech/GT_Mod.java | 1 +
.../api/metatileentity/BaseMetaTileEntity.java | 35 ++++-
.../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 122 +++++++++++++++++
.../GT_MetaTileEntity_MultiBlockBase.java | 9 +-
.../gregtech/api/util/GT_StructureUtility.java | 71 ++++++++++
.../java/gregtech/api/util/IGT_HatchAdder.java | 14 ++
.../GT_MetaTileEntity_AbstractMultiFurnace.java | 72 ++++------
.../GT_MetaTileEntity_ElectricBlastFurnace.java | 146 +++++++++------------
.../multi/GT_MetaTileEntity_MultiFurnace.java | 82 +++++-------
src/main/resources/mcmod.info | 3 +-
10 files changed, 361 insertions(+), 194 deletions(-)
create mode 100644 src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
create mode 100644 src/main/java/gregtech/api/util/GT_StructureUtility.java
create mode 100644 src/main/java/gregtech/api/util/IGT_HatchAdder.java
(limited to 'src')
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index c601130ab9..d9a8d72ecd 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -74,6 +74,7 @@ import static gregtech.api.enums.GT_Values.MOD_ID_FR;
@SuppressWarnings("ALL")
@Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false,
dependencies = " required-after:IC2;" +
+ " required-after:structurelib;" +
" after:dreamcraft;" +
" after:Forestry;" +
" after:PFAAGeologica;" +
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index 6c43799638..d108236a39 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -8,6 +8,10 @@ import appeng.me.helpers.AENetworkProxy;
import appeng.me.helpers.IGridProxyable;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
+import com.gtnewhorizon.structurelib.alignment.IAlignment;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
+import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import cpw.mods.fml.common.Optional;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
@@ -25,11 +29,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch;
import gregtech.api.net.GT_Packet_TileEntity;
import gregtech.api.objects.GT_ItemStack;
-import gregtech.api.util.GT_CoverBehavior;
-import gregtech.api.util.GT_Log;
-import gregtech.api.util.GT_ModHandler;
-import gregtech.api.util.GT_OreDictUnificator;
-import gregtech.api.util.GT_Utility;
+import gregtech.api.util.*;
import gregtech.common.GT_Client;
import gregtech.common.GT_Pollution;
import ic2.api.Direction;
@@ -73,7 +73,7 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE;
@Optional.InterfaceList(value = {
@Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true),
@Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)})
-public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable {
+public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider {
private final GT_CoverBehavior[] mCoverBehaviors = new GT_CoverBehavior[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior};
protected MetaTileEntity mMetaTileEntity;
protected long mStoredEnergy = 0, mStoredSteam = 0;
@@ -2368,4 +2368,27 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
public void setShutdownStatus(boolean newStatus) {
mWasShutdown = newStatus;
}
+
+ @Override
+ public IAlignment getAlignment() {
+ return getMetaTileEntity() instanceof IAlignmentProvider ? ((IAlignmentProvider) getMetaTileEntity()).getAlignment() : new BasicAlignment();
+ }
+
+ private class BasicAlignment implements IAlignment {
+
+ @Override
+ public ExtendedFacing getExtendedFacing() {
+ return ExtendedFacing.of(ForgeDirection.getOrientation(getFrontFacing()));
+ }
+
+ @Override
+ public void setExtendedFacing(ExtendedFacing alignment) {
+ setFrontFacing((byte) Math.max(alignment.getDirection().ordinal(), 5));
+ }
+
+ @Override
+ public IAlignmentLimits getAlignmentLimits() {
+ return (direction, rotation, flip) -> rotation.isNotRotated() && flip.isNotFlipped();
+ }
+ }
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
new file mode 100644
index 0000000000..7d06378ce1
--- /dev/null
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
@@ -0,0 +1,122 @@
+package gregtech.api.metatileentity.implementations;
+
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.alignment.IAlignment;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
+import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
+import com.gtnewhorizon.structurelib.alignment.enumerable.Flip;
+import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation;
+import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
+import cpw.mods.fml.common.network.NetworkRegistry;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraftforge.common.util.ForgeDirection;
+
+/**
+ * Enhanced multiblock base class, featuring following improvement over {@link GT_MetaTileEntity_MultiBlockBase}
+ *
+ * 1. TecTech style declarative structure check utilizing StructureLib.
+ * 2. Arbitrarily rotating the whole structure, if allowed to.
+ *
+ * @param type of this
+ */
+public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment {
+ private ExtendedFacing mExtendedFacing;
+ private final IAlignmentLimits mLimits;
+
+ protected GT_MetaTileEntity_EnhancedMultiBlockBase(int aID, String aName, String aNameRegional) {
+ super(aID, aName, aNameRegional);
+ mLimits = getInitialAlignmentLimits();
+ }
+
+ protected GT_MetaTileEntity_EnhancedMultiBlockBase(String aName) {
+ super(aName);
+ mLimits = getInitialAlignmentLimits();
+ }
+
+ @Override
+ public ExtendedFacing getExtendedFacing() {
+ return mExtendedFacing;
+ }
+
+ @Override
+ public void setExtendedFacing(ExtendedFacing newExtendedFacing) {
+ if (mExtendedFacing != newExtendedFacing) {
+ stopMachine();
+ mExtendedFacing = newExtendedFacing;
+ IGregTechTileEntity base = getBaseMetaTileEntity();
+ mMachine = false;
+ mUpdate = 100;
+ if (getBaseMetaTileEntity().isServerSide()) {
+ StructureLibAPI.sendAlignment((IAlignmentProvider) base,
+ new NetworkRegistry.TargetPoint(base.getWorld().provider.dimensionId,
+ base.getXCoord(), base.getYCoord(), base.getZCoord(), 512));
+ } else {
+ base.issueTextureUpdate();
+ }
+ }
+ }
+
+ @Override
+ public final boolean isFacingValid(byte aFacing) {
+ return canSetToDirectionAny(ForgeDirection.getOrientation(aFacing));
+ }
+
+ @Override
+ public void onFacingChange() {
+ toolSetDirection(ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()));
+ }
+
+ @Override
+ public IAlignmentLimits getAlignmentLimits() {
+ return mLimits;
+ }
+
+ public abstract IStructureDefinition getStructureDefinition();
+
+ protected IAlignmentLimits getInitialAlignmentLimits() {
+ return UNLIMITED;
+ }
+
+ @Override
+ public void saveNBTData(NBTTagCompound aNBT) {
+ super.saveNBTData(aNBT);
+ aNBT.setByte("mRotation", (byte) mExtendedFacing.getRotation().getIndex());
+ aNBT.setByte("mFlip", (byte) mExtendedFacing.getFlip().getIndex());
+ }
+
+ @Override
+ public void loadNBTData(NBTTagCompound aNBT) {
+ super.loadNBTData(aNBT);
+ mExtendedFacing = ExtendedFacing.of(ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()),
+ Rotation.byIndex(aNBT.getByte("mRotation")),
+ Flip.byIndex(aNBT.getByte("mFlip")));
+ }
+
+ @Override
+ public abstract GT_MetaTileEntity_EnhancedMultiBlockBase newMetaEntity(IGregTechTileEntity aTileEntity);
+
+ @SuppressWarnings("unchecked")
+ private IStructureDefinition> getCastedStructureDefinition() {
+ return (IStructureDefinition>) getStructureDefinition();
+ }
+
+ protected final boolean checkPiece(String piece, int horizontalOffset, int verticalOffset, int depthOffset) {
+ IGregTechTileEntity tTile = getBaseMetaTileEntity();
+ return getCastedStructureDefinition().check(this, piece, tTile.getWorld(), getExtendedFacing(), tTile.getXCoord(), tTile.getYCoord(), tTile.getZCoord(), horizontalOffset, verticalOffset, depthOffset, !mMachine);
+ }
+
+ protected final boolean buildPiece(String piece, ItemStack trigger, boolean hintOnly, int horizontalOffset, int verticalOffset, int depthOffset) {
+ IGregTechTileEntity tTile = getBaseMetaTileEntity();
+ return getCastedStructureDefinition().buildOrHints(this, trigger, piece, tTile.getWorld(), getExtendedFacing(), tTile.getXCoord(), tTile.getYCoord(), tTile.getZCoord(), horizontalOffset, verticalOffset, depthOffset, hintOnly);
+ }
+
+ @Override
+ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
+ super.onFirstTick(aBaseMetaTileEntity);
+ if (aBaseMetaTileEntity.isClientSide())
+ StructureLibAPI.queryAlignment((IAlignmentProvider) aBaseMetaTileEntity);
+ }
+}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index 0de4dfecbb..3b1a963c9e 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -26,6 +26,7 @@ import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Keyboard;
import java.util.ArrayList;
+import java.util.List;
import static gregtech.api.enums.GT_Values.V;
import static gregtech.api.enums.GT_Values.VN;
@@ -676,8 +677,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
return false;
}
- private boolean dumpFluid(FluidStack copiedFluidStack, boolean restrictiveHatchesOnly){
- for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
+ protected static boolean dumpFluid(List aOutputHatches, FluidStack copiedFluidStack, boolean restrictiveHatchesOnly){
+ for (GT_MetaTileEntity_Hatch_Output tHatch : aOutputHatches) {
if (!isValidMetaTileEntity(tHatch) || (restrictiveHatchesOnly && tHatch.mMode == 0)) {
continue;
}
@@ -709,8 +710,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity {
public boolean addOutput(FluidStack aLiquid) {
if (aLiquid == null) return false;
FluidStack copiedFluidStack = aLiquid.copy();
- if (!dumpFluid(copiedFluidStack, true)){
- dumpFluid(copiedFluidStack, false);
+ if (!dumpFluid(mOutputHatches, copiedFluidStack, true)){
+ dumpFluid(mOutputHatches, copiedFluidStack, false);
}
return false;
}
diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java
new file mode 100644
index 0000000000..c8d845ec19
--- /dev/null
+++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java
@@ -0,0 +1,71 @@
+package gregtech.api.util;
+
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import net.minecraft.block.Block;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+
+public class GT_StructureUtility {
+ private GT_StructureUtility() {
+ throw new AssertionError("Not instantiable");
+ }
+
+ public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots) {
+ return ofHatchAdder(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1);
+ }
+
+ public static IStructureElementNoPlacement ofHatchAdder(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta) {
+ if (IGT_HatchAdder == null || hintBlock == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElementNoPlacement() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ TileEntity tileEntity = world.getTileEntity(x, y, z);
+ return tileEntity instanceof IGregTechTileEntity && IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex);
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
+ return true;
+ }
+ };
+ }
+
+ public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) {
+ return ofHatchAdderOptional(IGT_HatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta);
+ }
+
+ public static IStructureElement ofHatchAdderOptional(IGT_HatchAdder IGT_HatchAdder, int textureIndex, Block hintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) {
+ if (IGT_HatchAdder == null || hintBlock == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElement() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ TileEntity tileEntity = world.getTileEntity(x, y, z);
+ Block worldBlock = world.getBlock(x, y, z);
+ return (tileEntity instanceof IGregTechTileEntity &&
+ IGT_HatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) textureIndex)) ||
+ (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta);
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
+ return true;
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2);
+ return true;
+ }
+ };
+ }
+}
diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
new file mode 100644
index 0000000000..be0194fc65
--- /dev/null
+++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
@@ -0,0 +1,14 @@
+package gregtech.api.util;
+
+
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+
+public interface IGT_HatchAdder {
+ /**
+ * Callback to add hatch, needs to check if hatch is valid (and add it)
+ * @param iGregTechTileEntity hatch
+ * @param aShort requested texture index, or null if not...
+ * @return managed to add hatch (structure still valid)
+ */
+ boolean apply(T t,IGregTechTileEntity iGregTechTileEntity, Short aShort);
+}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java
index 1ac4df6d73..84203ef849 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java
@@ -1,16 +1,16 @@
package gregtech.common.tileentities.machines.multi;
-import gregtech.api.GregTech_API;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import gregtech.api.enums.HeatingCoilLevel;
import gregtech.api.interfaces.IHeatingCoil;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
-public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTileEntity_MultiBlockBase {
+public abstract class GT_MetaTileEntity_AbstractMultiFurnace> extends GT_MetaTileEntity_EnhancedMultiBlockBase {
- private static final int CASING_INDEX = 11;
+ protected HeatingCoilLevel mCoilLevel;
protected GT_MetaTileEntity_AbstractMultiFurnace(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
@@ -25,55 +25,21 @@ public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTile
return true;
}
- @Override
- public boolean isFacingValid(byte aFacing) {
- return aFacing > 1;
- }
-
- protected HeatingCoilLevel getInitialHeatLevel(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) {
- Block coil = aBaseMetaTileEntity.getBlockOffset(xDir + 1, 1, zDir);
- if (!(coil instanceof IHeatingCoil))
- return null;
- IHeatingCoil heatingCoil = (IHeatingCoil) coil;
- byte tUsedMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + 1, 1, zDir);
- return heatingCoil.getCoilHeat(tUsedMeta);
- }
-
- protected boolean checkStructure(HeatingCoilLevel heatingCap, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity){
- for (int i = -1; i < 2; i++) {
- for (int j = -1; j < 2; j++) {
- if (!checkTopLayer(i, j, xDir, zDir, aBaseMetaTileEntity))
- return false;
-
- if (!checkBottomLayer(i, j, xDir, zDir, aBaseMetaTileEntity))
- return false;
-
- if (!checkCoils(heatingCap, i, j, xDir, zDir, aBaseMetaTileEntity))
- return false;
- }
+ protected final boolean addCoil(Block aBlock, int aMeta) {
+ if (aBlock instanceof IHeatingCoil) {
+ if (mCoilLevel != null)
+ return mCoilLevel == ((IHeatingCoil) aBlock).getCoilHeat(aMeta);
+ mCoilLevel = ((IHeatingCoil) aBlock).getCoilHeat(aMeta);
+ return true;
}
- return true;
+ return false;
}
- protected abstract boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity);
- protected abstract boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity);
-
- protected boolean checkBottomLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity){
- if ((xDir + i == 0) && (zDir + j == 0))
- return true;
- IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 0, zDir + j);
- if (addMaintenanceToMachineList(tTileEntity, CASING_INDEX))
- return true;
- if (addInputToMachineList(tTileEntity, CASING_INDEX))
- return true;
- if (addOutputToMachineList(tTileEntity, CASING_INDEX))
- return true;
- if (addEnergyInputToMachineList(tTileEntity, CASING_INDEX))
- return true;
-
- if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 0, zDir + j) != GregTech_API.sBlockCasings1)
- return false;
- return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 0, zDir + j) == CASING_INDEX;
+ protected boolean addBottomHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
+ return addMaintenanceToMachineList(aTileEntity, aBaseCasingIndex) ||
+ addInputToMachineList(aTileEntity, aBaseCasingIndex) ||
+ addOutputToMachineList(aTileEntity, aBaseCasingIndex) ||
+ addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex);
}
@Override
@@ -95,4 +61,10 @@ public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTile
public boolean explodesOnComponentBreak(ItemStack aStack) {
return false;
}
+
+ @Override
+ protected IAlignmentLimits getInitialAlignmentLimits() {
+ // even though flipping doesn't really change the overall structure, but maybe someone want it somehow
+ return (direction, rotation, flip) -> direction.offsetY == 0 && rotation.isNotRotated();
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java
index 5e99491c2e..733710e539 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java
@@ -1,22 +1,22 @@
package gregtech.common.tileentities.machines.multi;
+import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
+import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
+import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTech_API;
-import gregtech.api.enums.HeatingCoilLevel;
import gregtech.api.enums.Materials;
import gregtech.api.gui.GT_GUIContainer_MultiMachine;
-import gregtech.api.interfaces.IHeatingCoil;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output;
import gregtech.api.render.TextureFactory;
-import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
-import net.minecraft.block.Block;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
@@ -25,21 +25,36 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.input.Keyboard;
+import java.util.ArrayList;
+
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_Values.V;
import static gregtech.api.enums.GT_Values.VN;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE_GLOW;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_GLOW;
-import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
+import static gregtech.api.enums.Textures.BlockIcons.*;
+import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
+import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional;
-public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_AbstractMultiFurnace {
+public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_AbstractMultiFurnace implements IConstructable {
private int mHeatingCapacity = 0;
- private int controllerY;
+ private final ArrayList mPollutionOutputHatches = new ArrayList<>();
private final FluidStack[] pollutionFluidStacks = {Materials.CarbonDioxide.getGas(1000),
Materials.CarbonMonoxide.getGas(1000), Materials.SulfurDioxide.getGas(1000)};
private static final int CASING_INDEX = 11;
+ private static final String STRUCTURE_PIECE_MAIN = "main";
+ private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder()
+ .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{
+ {"ttt", "tmt", "ttt"},
+ {"CCC", "C-C", "CCC",},
+ {"CCC", "C-C", "CCC",},
+ {"b~b", "bbb", "bbb"}
+ }))
+ .addElement('t', ofHatchAdderOptional(GT_MetaTileEntity_ElectricBlastFurnace::addOutputHatchToTopList, CASING_INDEX, 1, GregTech_API.sBlockCasings1, CASING_INDEX))
+ .addElement('m', ofHatchAdder(GT_MetaTileEntity_ElectricBlastFurnace::addMufflerToMachineList, CASING_INDEX, 2))
+ .addElement('C', ofBlockAdder(GT_MetaTileEntity_ElectricBlastFurnace::addCoil, GregTech_API.sBlockCasings5, 0))
+ .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_ElectricBlastFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX))
+ .build();
public GT_MetaTileEntity_ElectricBlastFurnace(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
@@ -50,7 +65,7 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
}
@Override
- public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
+ public GT_MetaTileEntity_ElectricBlastFurnace newMetaEntity(IGregTechTileEntity aTileEntity) {
return new GT_MetaTileEntity_ElectricBlastFurnace(this.mName);
}
@@ -119,8 +134,8 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
}
@Override
- public boolean isFacingValid(byte aFacing) {
- return aFacing > 1;
+ public IStructureDefinition getStructureDefinition() {
+ return STRUCTURE_DEFINITION;
}
@Override
@@ -225,68 +240,33 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
return timesOverclocked;
}
- private boolean checkMachineFunction(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
- controllerY = aBaseMetaTileEntity.getYCoord();
- int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX;
- int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ;
-
- this.mHeatingCapacity = 0;
-
- replaceDeprecatedCoils(aBaseMetaTileEntity);
- HeatingCoilLevel heatingCap = getInitialHeatLevel(aBaseMetaTileEntity, xDir, zDir);
- if (heatingCap == null)
- return false;
-
- if (!checkStructure(heatingCap, xDir, zDir, aBaseMetaTileEntity))
- return false;
-
- this.mHeatingCapacity = (int) heatingCap.getHeat();
- this.mHeatingCapacity += 100 * (GT_Utility.getTier(getMaxInputVoltage()) - 2);
- return true;
- }
-
- @Override
- protected boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) {
- if ((i == 0) && (j == 0)) {
- return addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 3, zDir), CASING_INDEX);
+ public boolean addOutputHatchToTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) {
+ if (aTileEntity == null) return false;
+ IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
+ if (aMetaTileEntity == null) return false;
+ if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) {
+ ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex);
+ return mPollutionOutputHatches.add((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity);
}
- if (addOutputToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 3, zDir + j), CASING_INDEX))
- return true;
-
- if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 3, zDir + j) != GregTech_API.sBlockCasings1)
- return false;
-
- return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 3, zDir + j) == CASING_INDEX;
+ return false;
}
@Override
- protected boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) {
- if ((i == 0) && (j == 0)) {
- if (!aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir))
- return false;
+ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
+ this.mHeatingCapacity = 0;
- return aBaseMetaTileEntity.getAirOffset(xDir, 2, zDir);
- }
+ replaceDeprecatedCoils(aBaseMetaTileEntity);
- Block blockLow = aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j);
- if (!(blockLow instanceof IHeatingCoil))
- return false;
+ mCoilLevel = null;
- Block blockHi = aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j);
- if (!(blockHi instanceof IHeatingCoil))
+ if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0))
return false;
- byte metaLow = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j);
- HeatingCoilLevel coilHeatLow = ((IHeatingCoil) blockLow).getCoilHeat(metaLow);
- byte metaHi = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j);
- HeatingCoilLevel coilHeatHi = ((IHeatingCoil) blockHi).getCoilHeat(metaHi);
-
- return heatingCap == coilHeatLow && heatingCap == coilHeatHi;
- }
+ if (mCoilLevel == null)
+ return false;
- @Override
- public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
- return this.checkMachineFunction(aBaseMetaTileEntity, aStack);
+ this.mHeatingCapacity = (int) mCoilLevel.getHeat() + 100 * (GT_Utility.getTier(getMaxInputVoltage()) - 2);
+ return true;
}
private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) {
@@ -326,7 +306,6 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
public boolean addOutput(FluidStack aLiquid) {
if (aLiquid == null)
return false;
- int targetHeight;
FluidStack tLiquid = aLiquid.copy();
boolean isOutputPollution = false;
for (FluidStack pollutionFluidStack : pollutionFluidStacks) {
@@ -336,8 +315,9 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
isOutputPollution = true;
break;
}
+ ArrayList tOutputHatches;
if (isOutputPollution) {
- targetHeight = this.controllerY + 3;
+ tOutputHatches = this.mPollutionOutputHatches;
int pollutionReduction = 0;
for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) {
if (!isValidMetaTileEntity(tHatch))
@@ -347,23 +327,10 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
}
tLiquid.amount = tLiquid.amount * (pollutionReduction + 5) / 100;
} else {
- targetHeight = this.controllerY;
+ tOutputHatches = this.mOutputHatches;
}
- for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) {
- if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? !tHatch.outputsSteam() : !tHatch.outputsLiquids())
- continue;
-
- if (tHatch.getBaseMetaTileEntity().getYCoord() != targetHeight)
- continue;
-
- int tAmount = tHatch.fill(tLiquid, false);
- if (tAmount >= tLiquid.amount) {
- return tHatch.fill(tLiquid, true) >= tLiquid.amount;
- } else if (tAmount > 0) {
- tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true);
- }
- }
- return false;
+ return dumpFluid(tOutputHatches, tLiquid, true) ||
+ dumpFluid(tOutputHatches, tLiquid, false);
}
@Override
@@ -401,4 +368,15 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + EnumChatFormatting.GREEN + mPollutionReduction + EnumChatFormatting.RESET + " %"
};
}
+
+ @Override
+ public void construct(ItemStack stackSize, boolean hintsOnly) {
+ buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1,3,0);
+ }
+
+ @Override
+ public String[] getStructureDescription(ItemStack stackSize) {
+ // TODO implement me
+ return new String[0];
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java
index 3bf7dc4cfb..14dfe6f237 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java
@@ -1,11 +1,10 @@
package gregtech.common.tileentities.machines.multi;
+import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
+import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTech_API;
-import gregtech.api.enums.HeatingCoilLevel;
import gregtech.api.gui.GT_GUIContainer_MultiMachine;
-import gregtech.api.interfaces.IHeatingCoil;
import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler;
@@ -14,7 +13,6 @@ import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
-import net.minecraft.block.Block;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
@@ -24,18 +22,30 @@ import org.lwjgl.input.Keyboard;
import java.util.ArrayList;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAdder;
import static gregtech.api.enums.GT_Values.VN;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE_GLOW;
-import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_GLOW;
-import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
+import static gregtech.api.enums.Textures.BlockIcons.*;
+import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
+import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional;
-public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace {
+public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace {
private int mLevel = 0;
private int mCostDiscount = 1;
private static final int CASING_INDEX = 11;
+ private static final String STRUCTURE_PIECE_MAIN = "main";
+ private static final IStructureDefinition STRUCTURE_DEFINITION = StructureDefinition.builder()
+ .addShape(STRUCTURE_PIECE_MAIN, new String[][]{
+ {"ccc", "cmc", "ccc"},
+ {"CCC", "C-C", "CCC",},
+ {"b~b", "bbb", "bbb"}
+ })
+ .addElement('c', ofBlock(GregTech_API.sBlockCasings1, CASING_INDEX))
+ .addElement('m', ofHatchAdder(GT_MetaTileEntity_MultiFurnace::addMufflerToMachineList, CASING_INDEX, 2))
+ .addElement('C', ofBlockAdder(GT_MetaTileEntity_MultiFurnace::addCoil, GregTech_API.sBlockCasings5, 0))
+ .addElement('b', ofHatchAdderOptional(GT_MetaTileEntity_MultiFurnace::addBottomHatch, CASING_INDEX, 3, GregTech_API.sBlockCasings1, CASING_INDEX))
+ .build();
public GT_MetaTileEntity_MultiFurnace(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
@@ -46,7 +56,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu
}
@Override
- public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
+ public GT_MetaTileEntity_MultiFurnace newMetaEntity(IGregTechTileEntity aTileEntity) {
return new GT_MetaTileEntity_MultiFurnace(this.mName);
}
@@ -149,55 +159,29 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu
return true;
}
- private boolean checkMachineFunction(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
- int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX;
- int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ;
+ @Override
+ public IStructureDefinition getStructureDefinition() {
+ return STRUCTURE_DEFINITION;
+ }
+ @Override
+ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){
this.mLevel = 0;
this.mCostDiscount = 1;
replaceDeprecatedCoils(aBaseMetaTileEntity);
- HeatingCoilLevel heatingCap = getInitialHeatLevel(aBaseMetaTileEntity, xDir, zDir);
- if (heatingCap == null)
- return false;
-
- if (!checkStructure(heatingCap, xDir, zDir, aBaseMetaTileEntity))
- return false;
-
- this.mLevel = heatingCap.getLevel();
- this.mCostDiscount = heatingCap.getCostDiscount();
- return true;
- }
- @Override
- protected boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) {
- if ((i == 0) && (j == 0))
- return aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir);
+ mCoilLevel = null;
- Block coilM = aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j);
- if (!(coilM instanceof IHeatingCoil))
+ if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0))
return false;
- byte usedMetaM = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j);
-
- IHeatingCoil heatingCoilM = (IHeatingCoil) coilM;
- HeatingCoilLevel heatingLevelM = heatingCoilM.getCoilHeat(usedMetaM);
- return heatingLevelM == heatingCap;
- }
-
- @Override
- protected boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) {
- if ((i == 0) && (j == 0)) {
- return addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 2, zDir), CASING_INDEX);
- }
- if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j) != GregTech_API.sBlockCasings1)
+ if (mCoilLevel == null)
return false;
- return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j) == CASING_INDEX;
- }
- @Override
- public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){
- return this.checkMachineFunction(aBaseMetaTileEntity,aStack);
+ this.mLevel = mCoilLevel.getLevel();
+ this.mCostDiscount = mCoilLevel.getCostDiscount();
+ return true;
}
private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) {
diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info
index 1432a19054..0ec17827de 100644
--- a/src/main/resources/mcmod.info
+++ b/src/main/resources/mcmod.info
@@ -16,7 +16,8 @@
"parent": "",
"screenshots": [],
"dependencies": [
- "Industrialcraft"
+ "Industrialcraft",
+ "structurelib"
]
}
]
--
cgit
From cb876c46e9f185b73556c1c8ed7ca2751cac2cdc Mon Sep 17 00:00:00 2001
From: Glease <4586901+Glease@users.noreply.github.com>
Date: Mon, 31 May 2021 01:09:30 +0800
Subject: Implement IConstructable for demo multis
---
.../api/metatileentity/BaseMetaTileEntity.java | 2 +-
.../GT_MetaTileEntity_EnhancedMultiBlockBase.java | 35 +++++++++++++++++++++-
src/main/java/gregtech/api/util/GT_Utility.java | 15 +++++++++-
.../GT_MetaTileEntity_ElectricBlastFurnace.java | 17 ++---------
.../multi/GT_MetaTileEntity_MultiFurnace.java | 17 ++++++-----
5 files changed, 62 insertions(+), 24 deletions(-)
(limited to 'src')
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index d108236a39..6eb06d8fae 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -2383,7 +2383,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
@Override
public void setExtendedFacing(ExtendedFacing alignment) {
- setFrontFacing((byte) Math.max(alignment.getDirection().ordinal(), 5));
+ setFrontFacing((byte) Math.min(alignment.getDirection().ordinal(), ForgeDirection.UNKNOWN.ordinal() - 1));
}
@Override
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
index 7d06378ce1..c3d41664b7 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
@@ -4,15 +4,21 @@ import com.gtnewhorizon.structurelib.StructureLibAPI;
import com.gtnewhorizon.structurelib.alignment.IAlignment;
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
+import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import com.gtnewhorizon.structurelib.alignment.enumerable.Flip;
import com.gtnewhorizon.structurelib.alignment.enumerable.Rotation;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import cpw.mods.fml.common.network.NetworkRegistry;
+import gregtech.api.GregTech_API;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
+import org.lwjgl.input.Keyboard;
+
+import java.util.concurrent.atomic.AtomicReferenceArray;
/**
* Enhanced multiblock base class, featuring following improvement over {@link GT_MetaTileEntity_MultiBlockBase}
@@ -22,7 +28,8 @@ import net.minecraftforge.common.util.ForgeDirection;
*
* @param type of this
*/
-public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment {
+public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment, IConstructable {
+ private static final AtomicReferenceArray tooltips = new AtomicReferenceArray<>(GregTech_API.METATILEENTITIES.length);
private ExtendedFacing mExtendedFacing;
private final IAlignmentLimits mLimits;
@@ -76,6 +83,32 @@ public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase getStructureDefinition();
+ protected abstract GT_Multiblock_Tooltip_Builder createTooltip();
+
+ @Override
+ public String[] getDescription() {
+ if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
+ return getTooltip().getStructureInformation();
+ } else {
+ return getTooltip().getInformation();
+ }
+ }
+
+ protected GT_Multiblock_Tooltip_Builder getTooltip() {
+ int tId = getBaseMetaTileEntity().getMetaTileID();
+ GT_Multiblock_Tooltip_Builder tooltip = tooltips.get(tId);
+ if (tooltip == null) {
+ tooltip = createTooltip();
+ tooltips.set(tId, tooltip);
+ }
+ return tooltip;
+ }
+
+ @Override
+ public String[] getStructureDescription(ItemStack stackSize) {
+ return getTooltip().getStructureInformation();
+ }
+
protected IAlignmentLimits getInitialAlignmentLimits() {
return UNLIMITED;
}
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 28faeae7e3..c7cee8c9c2 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -3,6 +3,8 @@ package gregtech.api.util;
import cofh.api.transport.IItemDuct;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
+import com.gtnewhorizon.structurelib.alignment.IAlignment;
+import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.FMLCommonHandler;
import gregtech.api.GregTech_API;
@@ -1939,7 +1941,7 @@ public class GT_Utility {
tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----");
try {
- if (tTileEntity != null && tTileEntity instanceof IInventory)
+ if (tTileEntity instanceof IInventory)
tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET);
else
tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET);
@@ -1978,6 +1980,17 @@ public class GT_Utility {
} catch (Throwable e) {
if (D1) e.printStackTrace(GT_Log.err);
}
+ try {
+ if (tTileEntity instanceof IAlignmentProvider) {
+ IAlignment tAlignment = ((IAlignmentProvider) tTileEntity).getAlignment();
+ if (tAlignment != null) {
+ rEUAmount += 100;
+ tList.add(trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN + tAlignment.getExtendedFacing() + EnumChatFormatting.RESET);
+ }
+ }
+ } catch (Throwable e) {
+ if (D1) e.printStackTrace(GT_Log.err);
+ }
try {
if (tTileEntity instanceof ic2.api.tile.IWrenchable) {
rEUAmount += 100;
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java
index 733710e539..149c7a4172 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java
@@ -23,7 +23,6 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
-import org.lwjgl.input.Keyboard;
import java.util.ArrayList;
@@ -70,8 +69,8 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
}
@Override
- public String[] getDescription() {
- final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder();
+ protected GT_Multiblock_Tooltip_Builder createTooltip() {
+ GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder();
tt.addMachineType("Blast Furnace")
.addInfo("Controller block for the Electric Blast Furnace")
.addInfo("You can use some fluids to reduce recipe time. Place the circuit in the Input Bus")
@@ -95,11 +94,7 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
.addStructureInfo("Recovery amount scales with Muffler Hatch tier")
.addOutputHatch("Platline fluids, Any bottom layer casing")
.toolTipFinisher("Gregtech");
- if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
- return tt.getStructureInformation();
- } else {
- return tt.getInformation();
- }
+ return tt;
}
@Override
@@ -373,10 +368,4 @@ public class GT_MetaTileEntity_ElectricBlastFurnace extends GT_MetaTileEntity_Ab
public void construct(ItemStack stackSize, boolean hintsOnly) {
buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1,3,0);
}
-
- @Override
- public String[] getStructureDescription(ItemStack stackSize) {
- // TODO implement me
- return new String[0];
- }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java
index 14dfe6f237..aae7497f04 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java
@@ -1,5 +1,6 @@
package gregtech.common.tileentities.machines.multi;
+import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
import gregtech.api.GregTech_API;
@@ -29,7 +30,7 @@ import static gregtech.api.enums.Textures.BlockIcons.*;
import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional;
-public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace {
+public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMultiFurnace implements IConstructable {
private int mLevel = 0;
private int mCostDiscount = 1;
@@ -61,8 +62,8 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu
}
@Override
- public String[] getDescription() {
- final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder();
+ protected GT_Multiblock_Tooltip_Builder createTooltip() {
+ GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder();
tt.addMachineType("Furnace")
.addInfo("Controller Block for the Multi Smelter")
.addInfo("Smelts up to 8-128 items at once")
@@ -79,9 +80,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu
.addInputBus("Any bottom casing")
.addOutputBus("Any bottom casing")
.toolTipFinisher("Gregtech");
- if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
- return tt.getInformation();
- return tt.getStructureInformation();
+ return tt;
}
@Override
@@ -173,7 +172,7 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu
mCoilLevel = null;
- if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 3, 0))
+ if (!checkPiece(STRUCTURE_PIECE_MAIN, 1, 2, 0))
return false;
if (mCoilLevel == null)
@@ -238,4 +237,8 @@ public class GT_MetaTileEntity_MultiFurnace extends GT_MetaTileEntity_AbstractMu
};
}
+ @Override
+ public void construct(ItemStack stackSize, boolean hintsOnly) {
+ buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1, 2, 0);
+ }
}
--
cgit
From 86f69a4300e0bdb5c9921f37c84bb446e464ec78 Mon Sep 17 00:00:00 2001
From: Léa Gris
Date: Mon, 31 May 2021 10:13:56 +0200
Subject: feat(texture API): integrate ExtendedFacing rotation
Add ExtendedFacing rotation to the texture API.
Rotatable ExtendedFacing textures can be created with:
```java
TextureFactory.builder().addIcon(IICon).extFacing().build();
```
Improve and unify internal implementation of standard oriented and glow textures.
---
src/main/java/gregtech/GT_Mod.java | 3 +-
.../gregtech/api/interfaces/ITextureBuilder.java | 8 +
.../java/gregtech/api/util/LightingHelper.java | 1 +
.../common/render/GT_RenderedGlowTexture.java | 213 ------------
.../gregtech/common/render/GT_RenderedTexture.java | 383 +++++++++++++++------
.../common/render/GT_StdRenderedTexture.java | 36 --
.../gregtech/common/render/GT_TextureBuilder.java | 11 +-
7 files changed, 290 insertions(+), 365 deletions(-)
delete mode 100644 src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java
delete mode 100644 src/main/java/gregtech/common/render/GT_StdRenderedTexture.java
(limited to 'src')
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index d9a8d72ecd..278908b9a0 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -1,6 +1,7 @@
package gregtech;
import com.google.common.base.Stopwatch;
+import com.gtnewhorizon.structurelib.StructureLib;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.registry.EntityRegistry;
@@ -74,7 +75,7 @@ import static gregtech.api.enums.GT_Values.MOD_ID_FR;
@SuppressWarnings("ALL")
@Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false,
dependencies = " required-after:IC2;" +
- " required-after:structurelib;" +
+ " required-after:" + StructureLib.MOD_ID + ";" +
" after:dreamcraft;" +
" after:Forestry;" +
" after:PFAAGeologica;" +
diff --git a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java
index 8a4d715ccb..d72b538243 100644
--- a/src/main/java/gregtech/api/interfaces/ITextureBuilder.java
+++ b/src/main/java/gregtech/api/interfaces/ITextureBuilder.java
@@ -1,5 +1,6 @@
package gregtech.api.interfaces;
+import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import gregtech.api.render.TextureFactory;
import net.minecraft.block.Block;
import net.minecraftforge.common.util.ForgeDirection;
@@ -63,6 +64,13 @@ public interface ITextureBuilder {
*/
ITextureBuilder stdOrient();
+ /**
+ * Texture will orientate from block's {@link ExtendedFacing}
+ *
+ * @return {@link ITextureBuilder} for chaining
+ */
+ ITextureBuilder extFacing();
+
/**
* Texture always render with full brightness to glow in the dark
*
diff --git a/src/main/java/gregtech/api/util/LightingHelper.java b/src/main/java/gregtech/api/util/LightingHelper.java
index 598253b7d7..f131ef74a0 100644
--- a/src/main/java/gregtech/api/util/LightingHelper.java
+++ b/src/main/java/gregtech/api/util/LightingHelper.java
@@ -255,6 +255,7 @@ public class LightingHelper {
} else {
+ if (hasBrightnessOverride) tessellator.setBrightness(brightnessOverride);
tessellator.setColorOpaque_F(rgb[0] * lightness, rgb[1] * lightness, rgb[2] * lightness);
}
diff --git a/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java b/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java
deleted file mode 100644
index 899e4d7c5d..0000000000
--- a/src/main/java/gregtech/common/render/GT_RenderedGlowTexture.java
+++ /dev/null
@@ -1,213 +0,0 @@
-package gregtech.common.render;
-
-import gregtech.GT_Mod;
-import gregtech.api.enums.Textures.BlockIcons;
-import gregtech.api.interfaces.IColorModulationContainer;
-import gregtech.api.interfaces.IIconContainer;
-import gregtech.api.interfaces.ITexture;
-import net.minecraft.block.Block;
-import net.minecraft.client.renderer.RenderBlocks;
-import net.minecraft.client.renderer.Tessellator;
-import net.minecraft.util.IIcon;
-
-import static gregtech.api.util.LightingHelper.MAX_BRIGHTNESS;
-
-/**
- * This {@link ITexture} implementation renders texture with max brightness to glow in the dark.
- */
-
-class GT_RenderedGlowTexture implements ITexture, IColorModulationContainer {
- protected final IIconContainer mIconContainer;
- private final short[] mRGBa;
-
- GT_RenderedGlowTexture(IIconContainer aIcon, short[] aRGBa, boolean allowAlpha) {
- if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_RenderedTexture");
- mIconContainer = GT_Mod.gregtechproxy.mRenderGlowTextures ? aIcon : BlockIcons.VOID;
- mRGBa = aRGBa;
- }
-
- @Override
- public short[] getRGBA() {
- return mRGBa;
- }
-
- @Override
- public void renderXNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
- if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API
- if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return;
- final boolean enableAO = aRenderer.enableAO;
- aRenderer.enableAO = false;
- // TODO: Uncomment this once all addons have migrated to the new Texture API
- //startDrawingQuads(aRenderer, -1.0f, 0.0f, 0.0f);
- Tessellator.instance.setBrightness(MAX_BRIGHTNESS);
- Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]);
- aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon());
- if (mIconContainer.getOverlayIcon() != null) {
- Tessellator.instance.setColorOpaque(255, 255, 255);
- aRenderer.renderFaceXNeg(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
- }
- // TODO: Uncomment this once all addons have migrated to the new Texture API
- //draw(aRenderer);
- aRenderer.enableAO = enableAO;
- }
-
- @Override
- public void renderXPos(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
- if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API
- if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return;
- aRenderer.field_152631_f = true;
- final boolean enableAO = aRenderer.enableAO;
- aRenderer.enableAO = false;
- // TODO: Uncomment this once all addons have migrated to the new Texture API
- //startDrawingQuads(aRenderer, 1.0f, 0.0f, 0.0f);
- Tessellator.instance.setBrightness(MAX_BRIGHTNESS);
- Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]);
- aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getIcon());
- if (mIconContainer.getOverlayIcon() != null) {
- Tessellator.instance.setColorOpaque(255, 255, 255);
- aRenderer.renderFaceXPos(aBlock, aX, aY, aZ, mIconContainer.getOverlayIcon());
- }
- // TODO: Uncomment this once all addons have migrated to the new Texture API
- //draw(aRenderer);
- aRenderer.field_152631_f = false;
- aRenderer.enableAO = enableAO;
- }
-
- @Override
- public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) {
- if (aRenderer.useInventoryTint) return; // TODO: Remove this once all addons have migrated to the new Texture API
- if (!GT_Mod.gregtechproxy.mRenderGlowTextures) return;
- final boolean enableAO = aRenderer.enableAO;
- // TODO: Uncomment this once all addons have migrated to the new Texture API
- //startDrawingQuads(aRenderer, 0.0f, -1.0f, 0.0f);
- final Tessellator tessellator = Tessellator.instance;
- IIcon aIcon = mIconContainer.getIcon();
-
- float minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D);
- float maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D);
- float minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D);
- float maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D);
-
- if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) {
- minU = 16.0F - aIcon.getMaxU();
- maxU = 16.0F - aIcon.getMinU();
- }
-
- if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) {
- minV = aIcon.getMinV();
- maxV = aIcon.getMaxV();
- }
-
- double minX = aX + aRenderer.renderMinX;
- double maxX = aX + aRenderer.renderMaxX;
- double minY = aY + aRenderer.renderMinY;
- double minZ = aZ + aRenderer.renderMinZ;
- double maxZ = aZ + aRenderer.renderMaxZ;
-
- Tessellator.instance.setBrightness(MAX_BRIGHTNESS);
- Tessellator.instance.setColorOpaque(mRGBa[0], mRGBa[1], mRGBa[2]);
-
- tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV);
- tessellator.addVertexWithUV(minX, minY, minZ, maxU, minV);
- tessellator.addVertexWithUV(maxX, minY, minZ, minU, minV);
- tessellator.addVertexWithUV(maxX, minY, maxZ, minU, maxV);
-
- if (mIconContainer.getOverlayIcon() != null) {
- minU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMaxX) * 16.0D);
- maxU = aIcon.getInterpolatedU((1.0D - aRenderer.renderMinX) * 16.0D);
- minV = aIcon.getInterpolatedV(aRenderer.renderMinZ * 16.0D);
- maxV = aIcon.getInterpolatedV(aRenderer.renderMaxZ * 16.0D);
-
- if (aRenderer.renderMinX < 0.0D || aRenderer.renderMaxX > 1.0D) {
- minU = 16.0F - aIcon.getMaxU();
- maxU = 16.0F - aIcon.getMinU();
- }
-
- if (aRenderer.renderMinZ < 0.0D || aRenderer.renderMaxZ > 1.0D) {
- minV = aIcon.getMinV();
- maxV = aIcon.getMaxV();
- }
-
- minX = aX + (float) aRenderer.renderMinX;
- maxX = aX + (float) aRenderer.renderMaxX;
- minY = aY + (float) aRenderer.renderMinY;
- minZ = aZ + (float) aRenderer.renderMinZ;
- maxZ = aZ + (float) aRenderer.renderMaxZ;
-
- Tessellator.instance.setColorOpaque(255, 255, 255);
- tessellator.addVertexWithUV(minX, minY, maxZ, maxU, maxV);
- tessellator.addVertexWithUV(minX, minY, minZ, maxU