aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
authorAndrey <timeconqueror999@gmail.com>2021-08-01 13:40:42 +0300
committerGitHub <noreply@github.com>2021-08-01 13:40:42 +0300
commit01bad48a4cc564725277c93ed1f004db8048bdc2 (patch)
tree2eff9d12b13fc6db5682c31c7dd3253fdaf1ec4f /src/main/java/gregtech/api
parent352e16cceb3e419f1ea63af2384b0aced76f9451 (diff)
parent827a47c3cf0c26d81403f718dc3654a367436c2b (diff)
downloadGT5-Unofficial-01bad48a4cc564725277c93ed1f004db8048bdc2.tar.gz
GT5-Unofficial-01bad48a4cc564725277c93ed1f004db8048bdc2.tar.bz2
GT5-Unofficial-01bad48a4cc564725277c93ed1f004db8048bdc2.zip
Merge branch 'experimental' into code-improvements
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/enums/HeatingCoilLevel.java14
-rw-r--r--src/main/java/gregtech/api/enums/OrePrefixes.java6
-rw-r--r--src/main/java/gregtech/api/gui/GT_Container_BasicTank.java3
-rw-r--r--src/main/java/gregtech/api/interfaces/ITextureBuilder.java8
-rw-r--r--src/main/java/gregtech/api/items/GT_RadioactiveCellIC_Item.java3
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java43
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java29
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java14
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java110
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java185
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java9
-rw-r--r--src/main/java/gregtech/api/util/GT_ModHandler.java8
-rw-r--r--src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java202
-rw-r--r--src/main/java/gregtech/api/util/GT_Recipe.java24
-rw-r--r--src/main/java/gregtech/api/util/GT_StructureUtility.java183
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java73
-rw-r--r--src/main/java/gregtech/api/util/IGT_HatchAdder.java15
-rw-r--r--src/main/java/gregtech/api/util/LightingHelper.java1
18 files changed, 831 insertions, 99 deletions
diff --git a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
index d4446e31d0..06ceedff53 100644
--- a/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
+++ b/src/main/java/gregtech/api/enums/HeatingCoilLevel.java
@@ -23,6 +23,8 @@ public enum HeatingCoilLevel {
MAX,
;
+ private static final HeatingCoilLevel[] VALUES = values();
+
/**
* @return the Coils Tier Name
*/
@@ -61,9 +63,17 @@ public enum HeatingCoilLevel {
}
public static HeatingCoilLevel getFromTier(byte tier){
- if (tier < 0 || tier > HeatingCoilLevel.values().length -1)
+ if (tier < 0 || tier > getMaxTier())
return HeatingCoilLevel.None;
- return HeatingCoilLevel.values()[tier+2];
+ return VALUES[tier+2];
+ }
+
+ public static int size() {
+ return VALUES.length;
+ }
+
+ public static int getMaxTier() {
+ return VALUES.length - 1 - 2;
}
}
diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java
index ba91886c99..3aaea29f28 100644
--- a/src/main/java/gregtech/api/enums/OrePrefixes.java
+++ b/src/main/java/gregtech/api/enums/OrePrefixes.java
@@ -102,6 +102,7 @@ public enum OrePrefixes {
cellMolten("Cells of Molten stuff", "Molten ", " Cell", true, true, true, true, false, false, false, true, false, false, 0, M * 1, 64, 31), // Hot Cell full of molten stuff, which can be used in the Plasma Generator.
cell("Cells", "", " Cell", true, true, true, true, false, false, true, true, false, false, B[4] | B[8], M * 1, 64, 30), // Regular Gas/Fluid Cell. Introduced by Calclavia
bucket("Buckets", "", " Bucket", true, true, true, true, false, false, true, false, false, false, B[4] | B[8], M * 1, 16, -1), // A vanilla Iron Bucket filled with the Material.
+ bucketClay("Clay Buckets", "", " Clay Bucket", true, true, true, true, false, false, true, false, false, false, B[4] | B[8], M * 1, 16, -1), // An Iguana Tweaks Clay Bucket filled with the Material.
bottle("Bottles", "", " Bottle", true, true, true, true, false, false, false, false, false, false, B[4] | B[8], -1, 16, -1), // Glass Bottle containing a Fluid.
capsule("Capsules", "", " Capsule", false, true, true, true, false, false, false, false, false, false, B[4] | B[8], M * 1, 16, -1),
crystal("Crystals", "", " Crystal", false, true, false, false, false, false, true, false, false, false, B[2], M * 1, 64, -1),
@@ -413,6 +414,10 @@ public enum OrePrefixes {
bucket.mNotGeneratedItems.add(Materials.Lava);
bucket.mNotGeneratedItems.add(Materials.Milk);
bucket.mNotGeneratedItems.add(Materials.Water);
+ bucketClay.mNotGeneratedItems.add(Materials.Empty);
+ bucketClay.mNotGeneratedItems.add(Materials.Lava);
+ bucketClay.mNotGeneratedItems.add(Materials.Milk);
+ bucketClay.mNotGeneratedItems.add(Materials.Water);
bottle.mNotGeneratedItems.add(Materials.Empty);
bottle.mNotGeneratedItems.add(Materials.Water);
bottle.mNotGeneratedItems.add(Materials.Milk);
@@ -522,6 +527,7 @@ public enum OrePrefixes {
cableGt02.mSecondaryMaterial = new MaterialStack(Materials.Rubber, plate.mMaterialAmount);
cableGt01.mSecondaryMaterial = new MaterialStack(Materials.Rubber, plate.mMaterialAmount);
bucket.mSecondaryMaterial = new MaterialStack(Materials.Iron, ingot.mMaterialAmount * 3);
+ bucketClay.mSecondaryMaterial = new MaterialStack(Materials.Clay, dust.mMaterialAmount * 5);
cell.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2);
cellPlasma.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2);
cellMolten.mSecondaryMaterial = new MaterialStack(Materials.Tin, plate.mMaterialAmount * 2);
diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java
index 0ce9ab9232..477e52d103 100644
--- a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java
+++ b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java
@@ -52,9 +52,6 @@ public class GT_Container_BasicTank extends GT_ContainerMetaTile_Machine {
IFluidAccess tDrainableAccess = IFluidAccess.from(tTank, false);
return handleFluidSlotClick(tDrainableAccess, aPlayer, aMouseclick == 0, true, !tTank.isDrainableStackSeparate());
}
- if (mTileEntity.isServerSide()) {
- aPlayer.addChatComponentMessage(new ChatComponentText(String.format("Slot Index: %d, aMouseClick: %d, Shift Hold: %d", aShifthold, aMouseclick, aShifthold)));
- }
return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
}
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;
@@ -64,6 +65,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
*
* @return {@link ITextureBuilder} for chaining
diff --git a/src/main/java/gregtech/api/items/GT_RadioactiveCellIC_Item.java b/src/main/java/gregtech/api/items/GT_RadioactiveCellIC_Item.java
index e24ed04539..7950672ec2 100644
--- a/src/main/java/gregtech/api/items/GT_RadioactiveCellIC_Item.java
+++ b/src/main/java/gregtech/api/items/GT_RadioactiveCellIC_Item.java
@@ -2,6 +2,7 @@ package gregtech.api.items;
import gregtech.api.GregTech_API;
+import gregtech.api.util.GT_Utility;
import ic2.api.reactor.IReactor;
import ic2.api.reactor.IReactorComponent;
import ic2.core.IC2Potion;
@@ -153,7 +154,7 @@ public class GT_RadioactiveCellIC_Item extends GT_RadioactiveCell_Item implement
public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean isCurrentItem) {
if (this.sRadiation > 0 && (entity instanceof EntityLivingBase)) {
EntityLivingBase entityLiving = (EntityLivingBase) entity;
- if (!GregTech_API.mIC2Classic&&!ItemArmorHazmat.hasCompleteHazmat(entityLiving)) {
+ if (!GregTech_API.mIC2Classic&&!GT_Utility.isWearingFullRadioHazmat(entityLiving)) {
IC2Potion.radiation.applyTo(entityLiving, sRadiation * 20, sRadiation * 10);
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index 9e26ab648d..e4b7a8e84c 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -8,6 +8,12 @@ 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.constructable.IConstructable;
+import com.gtnewhorizon.structurelib.alignment.constructable.IConstructableProvider;
+import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import cpw.mods.fml.common.Optional;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
@@ -50,6 +56,7 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
+import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
@@ -66,10 +73,9 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE;
* <p/>
* This is the main TileEntity for EVERYTHING.
*/
-@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 {
+ @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, IAlignmentProvider, IConstructableProvider {
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;
@@ -2382,4 +2388,33 @@ 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();
+ }
+
+ @Nullable
+ @Override
+ public IConstructable getConstructable() {
+ return getMetaTileEntity() instanceof IConstructable ? (IConstructable) getMetaTileEntity() : null;
+ }
+
+ private class BasicAlignment implements IAlignment {
+
+ @Override
+ public ExtendedFacing getExtendedFacing() {
+ return ExtendedFacing.of(ForgeDirection.getOrientation(getFrontFacing()));
+ }
+
+ @Override
+ public void setExtendedFacing(ExtendedFacing alignment) {
+ setFrontFacing((byte) Math.min(alignment.getDirection().ordinal(), ForgeDirection.UNKNOWN.ordinal() - 1));
+ }
+
+ @Override
+ public IAlignmentLimits getAlignmentLimits() {
+ return (direction, rotation, flip) -> rotation.isNotRotated() && flip.isNotFlipped();
+ }
+ }
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java
index 9bbfbf0a3a..48d1bd8a18 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java
@@ -18,8 +18,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler;
-import java.util.Collection;
-
import static gregtech.api.enums.GT_Values.V;
public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity_BasicTank {
@@ -154,7 +152,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity
@Override
public long maxEUStore() {
- return Math.max(getEUVar(), V[mTier] * 40L + getMinimumStoredEU());
+ return Math.max(getEUVar(), V[mTier] * 80L + getMinimumStoredEU());
}
@Override
@@ -271,19 +269,18 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity
public int getFuelValue(FluidStack aLiquid) {
//System.out.println("Fluid stack check");
- if (aLiquid == null || getRecipes() == null) return 0;
- FluidStack tLiquid;
- Collection<GT_Recipe> tRecipeList = getRecipes().mRecipeList;
- if (tRecipeList != null) for (GT_Recipe tFuel : tRecipeList)
- if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null)
- if (aLiquid.isFluidEqual(tLiquid)){
- long val=(long)tFuel.mSpecialValue * getEfficiency() * consumedFluidPerOperation(tLiquid) / 100;
- if(val> Integer.MAX_VALUE){
- throw new ArithmeticException("Integer LOOPBACK!");
- }
- return (int) val;
- }
- return 0;
+ GT_Recipe_Map tRecipes = getRecipes();
+ if (aLiquid == null || !(tRecipes instanceof GT_Recipe.GT_Recipe_Map_Fuel)) return 0;
+ GT_Recipe.GT_Recipe_Map_Fuel tFuels = (GT_Recipe.GT_Recipe_Map_Fuel) tRecipes;
+ GT_Recipe tFuel = tFuels.findFuel(aLiquid);
+ if (tFuel == null) {
+ return 0;
+ }
+ long val=(long)tFuel.mSpecialValue * getEfficiency() * consumedFluidPerOperation(aLiquid) / 100;
+ if(val> Integer.MAX_VALUE){
+ throw new ArithmeticException("Integer LOOPBACK!");
+ }
+ return (int) val;
}
public int getFuelValue(ItemStack aStack) {
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
index 7f9e21ff65..faea347c67 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java
@@ -330,10 +330,20 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM
protected void fillStacksIntoFirstSlots() {
if (bSortStacks) {
- for (int i = 0; i < mInventory.length; i++)
- for (int j = i + 1; j < mInventory.length; j++)
+ for (int i = 0; i < mInventory.length - 1; i++) {
+ if (!isValidSlot(i)) {
+ continue;
+ }
+
+ for (int j = i + 1; j < mInventory.length; j++) {
+ if (!isValidSlot(j)) {
+ continue;
+ }
+
if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j])))
GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1);
+ }
+ }
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java
new file mode 100644
index 0000000000..3854a96cda
--- /dev/null
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java
@@ -0,0 +1,110 @@
+package gregtech.api.metatileentity.implementations;
+
+import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
+import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import com.gtnewhorizon.structurelib.structure.StructureDefinition;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import net.minecraft.item.ItemStack;
+
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
+import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
+import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
+
+/**
+ * A simple 3x3x3 hollow cubic multiblock, that can be arbitrarily rotated, made of a single type of machine casing and accepts hatches everywhere.
+ * Controller will be placed in front center of the structure.
+ * <p>
+ * Note: You cannot use different casing for the same Class. Make a new subclass for it. You also should not change the casing
+ * dynamically, i.e. it should be a dumb method returning some sort of constant.
+ * <p>
+ * Implementation tips:
+ * 1. To restrict hatches, override {@link #addDynamoToMachineList(IGregTechTileEntity, int)} and its cousins instead of overriding the whole
+ * {@link #getStructureDefinition()} or change {@link #checkHatches(IGregTechTileEntity, ItemStack)}. The former is a total overkill, while the later cannot
+ * stop the structure check early.
+ * 2. To limit rotation, override {@link #getInitialAlignmentLimits()}
+ *
+ * @param <T>
+ */
+public abstract class GT_MetaTileEntity_CubicMultiBlockBase<T extends GT_MetaTileEntity_CubicMultiBlockBase<T>> extends GT_MetaTileEntity_EnhancedMultiBlockBase<T> {
+ protected static final String STRUCTURE_PIECE_MAIN = "main";
+ protected static final ClassValue<IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>>>() {
+ @Override
+ protected IStructureDefinition<GT_MetaTileEntity_CubicMultiBlockBase<?>> computeValue(Class<?> type) {
+ return StructureDefinition.<GT_MetaTileEntity_CubicMultiBlockBase<?>>builder()
+ .addShape(STRUCTURE_PIECE_MAIN, transpose(new String[][]{
+ {"hhh", "hhh", "hhh"},
+ {"h~h", "h-h", "hhh"},
+ {"hhh", "hhh", "hhh"},
+ }))
+ .addElement('h', ofChain(
+ lazy(t -> ofHatchAdder(GT_MetaTileEntity_CubicMultiBlockBase::addToMachineList, t.getHatchTextureIndex(), 1)),
+ onElementPass(
+ GT_MetaTileEntity_CubicMultiBlockBase::onCorrectCasingAdded,
+ lazy(GT_MetaTileEntity_CubicMultiBlockBase::getCasingElement)
+ )
+ ))
+ .build();
+ }
+ };
+ private int mCasingAmount = 0;
+
+ protected GT_MetaTileEntity_CubicMultiBlockBase(int aID, String aName, String aNameRegional) {
+ super(aID, aName, aNameRegional);
+ }
+
+ protected GT_MetaTileEntity_CubicMultiBlockBase(String aName) {
+ super(aName);
+ }
+
+ /**
+ * Create a simple 3x3x3 hollow cubic structure made of a single type of machine casing and accepts hatches everywhere.
+ * <p>
+ * The created definition contains a single piece named {@link #STRUCTURE_PIECE_MAIN}.
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public IStructureDefinition<T> getStructureDefinition() {
+ return (IStructureDefinition<T>) STRUCTURE_DEFINITION.get(getClass());
+ }
+
+ @Override
+ public void construct(ItemStack aStack, boolean aHintsOnly) {
+ buildPiece(STRUCTURE_PIECE_MAIN, aStack, aHintsOnly, 1, 1, 0);
+ }
+
+ @Override
+ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
+ mCasingAmount = 0;
+ return checkPiece(STRUCTURE_PIECE_MAIN, 1, 1, 0) &&
+ mCasingAmount >= getRequiredCasingCount() &&
+ checkHatches(aBaseMetaTileEntity, aStack);
+ }
+
+ /**
+ * Called by {@link #checkMachine(IGregTechTileEntity, ItemStack)} to check if all required hatches are present.
+ * <p>
+ * Default implementation requires EXACTLY ONE maintenance hatch to be present, and ignore all other conditions.
+ *
+ * @param aBaseMetaTileEntity the tile entity of self
+ * @param aStack The item stack inside the controller
+ * @return true if the test passes, false otherwise
+ */
+ protected boolean checkHatches(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
+ return mMaintenanceHatches.size() == 1;
+ }
+
+ protected abstract IStructureElement<GT_MetaTileEntity_CubicMultiBlockBase<?>> getCasingElement();
+
+ /**
+ * The hatch's texture index.
+ */
+ protected abstract int getHatchTextureIndex();
+
+ protected abstract int getRequiredCasingCount();
+
+ protected void onCorrectCasingAdded() {
+ mCasingAmount++;
+ }
+}
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..cc2513f5c2
--- /dev/null
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_EnhancedMultiBlockBase.java
@@ -0,0 +1,185 @@
+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.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.entity.player.EntityPlayer;
+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}
+ * <p>
+ * 1. TecTech style declarative structure check utilizing StructureLib.
+ * 2. Arbitrarily rotating the whole structure, if allowed to.
+ *
+ * @param <T> type of this
+ */
+public abstract class GT_MetaTileEntity_EnhancedMultiBlockBase<T extends GT_MetaTileEntity_EnhancedMultiBlockBase<T>> extends GT_MetaTileEntity_MultiBlockBase implements IAlignment, IConstructable {
+ private static final AtomicReferenceArray<GT_Multiblock_Tooltip_Builder> tooltips = new AtomicReferenceArray<>(GregTech_API.METATILEENTITIES.length);
+ private ExtendedFacing mExtendedFacing = ExtendedFacing.DEFAULT;
+ private IAlignmentLimits mLimits = getInitialAlignmentLimits();
+
+ protected GT_MetaTileEntity_EnhancedMultiBlockBase(int aID, String aName, String aNameRegional) {
+ super(aID, aName, aNameRegional);
+ }
+
+ protected GT_MetaTileEntity_EnhancedMultiBlockBase(String aName) {
+ super(aName);
+ }
+
+ @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 boolean onWrenchRightClick(byte aSide, byte aWrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
+ if (aWrenchingSide != getBaseMetaTileEntity().getFrontFacing())
+ return super.onWrenchRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ);
+ if (aPlayer.isSneaking()) {
+ // we won't be allowing horizontal flips, as it can be perfectly emulated by rotating twice and flipping horizontally
+ // allowing an extra round of flip make it hard to draw meaningful flip markers in GT_Proxy#drawGrid
+ toolSetFlip(getFlip().isHorizontallyFlipped() ? Flip.NONE : Flip.HORIZONTAL);
+ } else {
+ toolSetRotation(null);
+ }
+ return true;
+ }
+
+ @Override
+ public void onFacingChange() {
+ toolSetDirection(ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()));
+ }
+
+ @Override
+ public IAlignmentLimits getAlignmentLimits() {
+ return mLimits;
+ }
+
+ protected void setAlignmentLimits(IAlignmentLimits mLimits) {
+ this.mLimits = mLimits;
+ }
+
+ /**
+ * Due to limitation of Java type system, you might need to do an unchecked cast.
+ * HOWEVER, the returned IStructureDefinition is expected to be evaluated against current instance only, and should
+ * not be used against other instances, even for those of the same class.
+ */
+ public abstract IStructureDefinition<T> 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().getStructureHint();
+ }
+
+ protected IAlignmentLimits getInitialAlignmentLimits() {
+ return (d, r, f) -> !f.isVerticallyFliped();
+ }
+
+ @Override
+ public void saveNBTData(NBTTagCompound aNBT) {
+ super.saveNBTData(aNBT);
+ aNBT.setByte("eRotation", (byte) mExtendedFacing.getRotation().getIndex());
+ aNBT.setByte("eFlip", (byte) mExtendedFacing.getFlip().getIndex());
+ }
+
+ @Override
+ public void loadNBTData(NBTTagCompound aNBT) {
+ super.loadNBTData(aNBT);
+ mExtendedFacing = ExtendedFacing.of(ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()),
+ Rotation.byIndex(aNBT.getByte("eRotation")),
+ Flip.byIndex(aNBT.getByte("eFlip")));
+ }
+
+ @SuppressWarnings("unchecked")
+ private IStructureDefinition<GT_MetaTileEntity_EnhancedMultiBlockBase<T>> getCastedStructureDefinition() {
+ return (IStructureDefinition<GT_MetaTileEntity_EnhancedMultiBlockBase<T>>) getStructureDefinition();
+ }
+
+ /**
+ * Explanation of the world coordinate these offset means:
+ *
+ * Imagine you stand in front of the controller, with controller facing towards you not rotated or flipped.
+ *
+ * The horizontalOffset would be the number of blocks on the left side of the controller, not counting controller itself.
+ * The verticalOffset would be the number of blocks on the top side of the controller, not counting controller itself.
+ * The depthOffset would be the number of blocks between you and controller, not counting controller itself.
+ *
+ * All these offsets can be negative.
+ */
+ 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<GT_MetaTileEntity_Hatch_Output> 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_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java
index 7e66e6cc2a..ac9f7bd3d4 100644
--- a/src/main/java/gregtech/api/util/GT_ModHandler.java
+++ b/src/main/java/gregtech/api/util/GT_ModHandler.java
@@ -383,14 +383,14 @@ public class GT_ModHandler {
}
/**
- * Gets an Item from RailCraft
+ * Gets an Item from the specified mod
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount) {
return getModItem(aModID, aItem, aAmount, null);
}
/**
- * Gets an Item from RailCraft, and returns a Replacement Item if not possible
+ * Gets an Item from the specified mod, and returns a Replacement Item if not possible
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount, ItemStack aReplacement) {
if (GT_Utility.isStringInvalid(aItem) || !GregTech_API.sPreloadStarted) return null;
@@ -398,7 +398,7 @@ public class GT_ModHandler {
}
/**
- * Gets an Item from RailCraft, but the Damage Value can be specified
+ * Gets an Item from the specified mod, but the Damage Value can be specified
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta) {
ItemStack rStack = getModItem(aModID, aItem, aAmount);
@@ -408,7 +408,7 @@ public class GT_ModHandler {
}
/**
- * Gets an Item from RailCraft, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible
+ * Gets an Item from the specified mod, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible
*/
public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta, ItemStack aReplacement) {
ItemStack rStack = getModItem(aModID, aItem, aAmount, aReplacement);
diff --git a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
index e30fe5d606..3071cb95a3 100644
--- a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
+++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java
@@ -1,11 +1,19 @@
package gregtech.api.util;
-import java.util.LinkedList;
-import java.util.List;
-
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import gregtech.api.enums.Materials;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
/**
* This makes it easier to build multi tooltips, with a standardized format. <br>
* Info section order should be:<br>
@@ -32,12 +40,16 @@ import net.minecraft.util.StatCollector;
public class GT_Multiblock_Tooltip_Builder {
private static final String TAB = " ";
private static final String COLON = ": ";
-
+ private static final String SEPARATOR = ", ";
+
private final List<String> iLines;
private final List<String> sLines;
-
+ private final List<String> hLines;
+ private final SetMultimap<Integer, String> hBlocks;
+
private String[] iArray;
private String[] sArray;
+ private String[] hArray;
//Localized tooltips
private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType");
@@ -58,11 +70,17 @@ public class GT_Multiblock_Tooltip_Builder {
private static final String TT_pps = StatCollector.translateToLocal("GT5U.MBTT.PPS");
private static final String TT_hold = StatCollector.translateToLocal("GT5U.MBTT.Hold");
private static final String TT_todisplay = StatCollector.translateToLocal("GT5U.MBTT.Display");
+ private static final String TT_structurehint = StatCollector.translateToLocal("GT5U.MBTT.StructureHint");
private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod");
+ private static final String TT_air = StatCollector.translateToLocal("GT5U.MBTT.Air");
+ private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("structurelib.blockhint." + i + ".name")).toArray(String[]::new);
public GT_Multiblock_Tooltip_Builder() {
iLines = new LinkedList<>();
sLines = new LinkedList<>();
+ hLines = new LinkedList<>();
+ hBlocks = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new);
+ hBlocks.put(StructureLibAPI.HINT_BLOCK_META_AIR, TT_air);
}
/**
@@ -103,11 +121,10 @@ public class GT_Multiblock_Tooltip_Builder {
}
/**
- * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.<br>
- * Machine Type: machine
+ * Add a line telling how much this machine pollutes.
*
- * @param machine
- * Name of the machine type
+ * @param pollution
+ * Amount of pollution per second when active
*
* @return Instance this method was called on.
*/
@@ -307,7 +324,136 @@ public class GT_Multiblock_Tooltip_Builder {
sLines.add(TAB + TT_outputhatch + COLON + info);
return this;
}
-
+
+ /**
+ * Use this method to add a structural part that isn't covered by the other methods.<br>
+ * (indent)name: info
+ * @param name
+ * Name of the hatch or other component.
+ * @param info
+ * Positional information.
+ * @param dots
+ * The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOtherStructurePart(String name, String info, int... dots) {
+ sLines.add(TAB + name + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, name);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Maintenance Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addMaintenanceHatch(String info, int... dots) {
+ sLines.add(TAB + TT_maintenancehatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_maintenancehatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Muffler Hatch: info
+ *
+ * @param info Location where the hatch goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addMufflerHatch(String info, int... dots) {
+ sLines.add(TAB + TT_mufflerhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_mufflerhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Energy Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addEnergyHatch(String info, int... dots) {
+ sLines.add(TAB + TT_energyhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_energyhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Dynamo Hatch: info
+ *
+ * @param info Positional information.
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addDynamoHatch(String info, int... dots) {
+ sLines.add(TAB + TT_dynamohatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_dynamohatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Input Bus: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addInputBus(String info, int... dots) {
+ sLines.add(TAB + TT_inputbus + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_inputbus);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Input Hatch: info
+ *
+ * @param info Location where the hatch goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addInputHatch(String info, int... dots) {
+ sLines.add(TAB + TT_inputhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_inputhatch);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Output Bus: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOutputBus(String info, int... dots) {
+ sLines.add(TAB + TT_outputbus + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_outputbus);
+ return this;
+ }
+
+ /**
+ * Add a line of information about the structure:<br>
+ * (indent)Output Hatch: info
+ *
+ * @param info Location where the bus goes
+ * @param dots The valid locations for this part when asked to display hints
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addOutputHatch(String info, int... dots) {
+ sLines.add(TAB + TT_outputhatch + COLON + info);
+ for (int dot : dots) hBlocks.put(dot, TT_outputhatch);
+ return this;
+ }
+
/**
* Use this method to add non-standard structural info.<br>
* (indent)info
@@ -319,6 +465,30 @@ public class GT_Multiblock_Tooltip_Builder {
sLines.add(TAB + info);
return this;
}
+
+ /**
+ * Use this method to add non-standard structural hint. This info will appear before the standard structural hint.
+ * @param info
+ * The line to be added. This should be an entry into minecraft's localization system.
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addStructureHint(String info) {
+ hLines.add(StatCollector.translateToLocal(info));
+ return this;
+ }
+
+ /**
+ * Use this method to add an entry to standard structural hint without creating a corresponding line in structure information
+ * @param name
+ * The name of block This should be an entry into minecraft's localization system.
+ * @param dots
+ * Possible locations of this block
+ * @return Instance this method was called on.
+ */
+ public GT_Multiblock_Tooltip_Builder addStructureHint(String name, int... dots) {
+ for (int dot : dots) hBlocks.put(dot, StatCollector.translateToLocal(name));
+ return this;
+ }
/**
* Call at the very end.<br>
@@ -331,10 +501,11 @@ public class GT_Multiblock_Tooltip_Builder {
public void toolTipFinisher(String mod) {
iLines.add(TT_hold + " " + EnumChatFormatting.BOLD + "[LSHIFT]" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " " + TT_todisplay);
iLines.add(TT_mod + COLON + EnumChatFormatting.GREEN + mod + EnumChatFormatting.GRAY);
- iArray = new String[iLines.size()];
- sArray = new String[sLines.size()];
- iLines.toArray(iArray);
- sLines.toArray(sArray);
+ hLines.add(TT_structurehint);
+ iArray = iLines.toArray(new String[0]);
+ sArray = sLines.toArray(new String[0]);
+ // e.getKey() - 1 because 1 dot is meta 0.
+ hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey() - 1] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new);
}
public String[] getInformation() {
@@ -345,4 +516,7 @@ public class GT_Multiblock_Tooltip_Builder {
return sArray;
}
+ public String[] getStructureHint() {
+ return hArray;
+ }
}
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java
index a04df205b7..19f46dfd15 100644
--- a/src/main/java/gregtech/api/util/GT_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Recipe.java
@@ -197,6 +197,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
this(aInput1, aOutput1, null, null, null, aFuelValue, aType);
}
+ private static FluidStack[] tryGetFluidInputsFromCells(ItemStack aInput) {
+ FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true);
+ return tFluid == null ? null : new FluidStack[] {tFluid};
+ }
+
// aSpecialValue = EU per Liter! If there is no Liquid for this Object, then it gets multiplied with 1000!
public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aSpecialValue, int aType) {
this(true, new ItemStack[]{aInput1}, new ItemStack[]{aOutput1, aOutput2, aOutput3, aOutput4}, null, null, null, null, 0, 0, Math.max(1, aSpecialValue));
@@ -977,6 +982,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
* Just a Recipe Map with Utility specifically for Fuels.
*/
public static class GT_Recipe_Map_Fuel extends GT_Recipe_Map {
+ private final Map<String, GT_Recipe> mRecipesByFluidInput = new HashMap<>();
public GT_Recipe_Map_Fuel(Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) {
super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed);
}
@@ -1000,6 +1006,24 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe addFuel(ItemStack aInput, ItemStack aOutput, FluidStack aFluidInput, FluidStack aFluidOutput, int aChance, int aFuelValueInEU) {
return addRecipe(true, new ItemStack[]{aInput}, new ItemStack[]{aOutput}, null, new int[]{aChance}, new FluidStack[]{aFluidInput}, new FluidStack[]{aFluidOutput}, 0, 0, aFuelValueInEU);
}
+
+ @Override
+ public GT_Recipe add(GT_Recipe aRecipe) {
+ aRecipe = super.add(aRecipe);
+ if (aRecipe.mInputs != null && GT_Utility.getNonnullElementCount(aRecipe.mInputs) == 1 &&
+ (aRecipe.mFluidInputs == null || GT_Utility.getNonnullElementCount(aRecipe.mFluidInputs) == 0)) {
+ FluidStack tFluid = GT_Utility.getFluidForFilledItem(aRecipe.mInputs[0], true);
+ if (tFluid != null) {
+ tFluid.amount = 0;
+ mRecipesByFluidInput.put(tFluid.getUnlocalizedName(), aRecipe);
+ }
+ }
+ return aRecipe;
+ }
+
+ public GT_Recipe findFuel(FluidStack aFluidInput) {
+ return mRecipesByFluidInput.get(aFluidInput.getUnlocalizedName());
+ }
}
/**
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..a627da4fd6
--- /dev/null
+++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java
@@ -0,0 +1,183 @@
+package gregtech.api.util;
+
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.HeatingCoilLevel;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OrePrefixes;
+import gregtech.api.interfaces.IHeatingCoil;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.BaseMetaPipeEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame;
+import gregtech.common.blocks.GT_Block_Casings5;
+import net.minecraft.block.Block;
+import net.minecraft.init.Items;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.World;
+
+import java.util.Arrays;
+import java.util.function.BiConsumer;
+import java.util.function.BiPredicate;
+import java.util.function.Function;
+
+public class GT_StructureUtility {
+ private GT_StructureUtility() {
+ throw new AssertionError("Not instantiable");
+ }
+
+ public static <T> IStructureElementNoPlacement<T> ofHatchAdder(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, int aDots) {
+ return ofHatchAdder(aHatchAdder, aTextureIndex, StructureLibAPI.getBlockHint(), aDots - 1);
+ }
+
+ public static <T> IStructureElement<T> ofFrame(Materials aFrameMaterial) {
+ if (aFrameMaterial == null) throw new IllegalArgumentException();
+ return new IStructureElement<T>() {
+
+ private IIcon[] mIcons;
+
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ TileEntity tBase = world.getTileEntity(x, y, z);
+ if (tBase instanceof BaseMetaPipeEntity) {
+ BaseMetaPipeEntity tPipeBase = (BaseMetaPipeEntity) tBase;
+ if (tPipeBase.isInvalidTileEntity()) return false;
+ if (tPipeBase.getMetaTileEntity() instanceof GT_MetaPipeEntity_Frame)
+ return aFrameMaterial == ((GT_MetaPipeEntity_Frame) tPipeBase.getMetaTileEntity()).mMaterial;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ if (mIcons == null) {
+ mIcons = new IIcon[6];
+ Arrays.fill(mIcons, aFrameMaterial.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon());
+ }
+ StructureLibAPI.hintParticleTinted(world, x, y, z, mIcons, aFrameMaterial.mRGBa);
+ return true;
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ ItemStack tFrameStack = GT_OreDictUnificator.get(OrePrefixes.frameGt, aFrameMaterial, 1);
+ if (tFrameStack.getItem() instanceof ItemBlock) {
+ ItemBlock tFrameStackItem = (ItemBlock) tFrameStack.getItem();
+ return tFrameStackItem.placeBlockAt(tFrameStack, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrameStack));
+ }
+ return false;
+ }
+ };
+ }
+
+ public static <T> IStructureElementNoPlacement<T> ofHatchAdder(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, Block aHintBlock, int aHintMeta) {
+ if (aHatchAdder == null || aHintBlock == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElementNoPlacement<T>() {
+ @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 && aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex);
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, aHintMeta);
+ return true;
+ }
+ };
+ }
+
+ public static <T> IStructureElement<T> ofHatchAdderOptional(IGT_HatchAdder<T> aHatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) {
+ return ofHatchAdderOptional(aHatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta);
+ }
+
+ public static <T> IStructureElement<T> ofHatchAdderOptional(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, Block aHintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) {
+ if (aHatchAdder == null || aHintBlock == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElement<T>() {
+ @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 &&
+ aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex)) ||
+ (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, aHintBlock, 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;
+ }
+ };
+ }
+
+ /**
+ * Assume all coils accepted.
+ * @see #ofCoil(BiPredicate, Function)
+ */
+ public static <T> IStructureElement<T> ofCoil(BiConsumer<T, HeatingCoilLevel> aHeatingCoilSetter, Function<T, HeatingCoilLevel> aHeatingCoilGetter) {
+ return ofCoil((t, l) -> {
+ aHeatingCoilSetter.accept(t, l);
+ return true;
+ }, aHeatingCoilGetter);
+ }
+
+ /**
+ * Heating coil structure element.
+ * @param aHeatingCoilSetter Notify the controller of this new coil.
+ * Got called exactly once per coil.
+ * Might be called less times if structure test fails.
+ * If the setter returns false then it assumes the coil is rejected.
+ * @param aHeatingCoilGetter Get the current heating level. Null means no coil recorded yet.
+ */
+ public static <T> IStructureElement<T> ofCoil(BiPredicate<T, HeatingCoilLevel> aHeatingCoilSetter, Function<T, HeatingCoilLevel> aHeatingCoilGetter) {
+ if (aHeatingCoilSetter == null || aHeatingCoilGetter == null) {
+ throw new IllegalArgumentException();
+ }
+ return new IStructureElement<T>() {
+ @Override
+ public boolean check(T t, World world, int x, int y, int z) {
+ Block block = world.getBlock(x, y, z);
+ if (!(block instanceof IHeatingCoil))
+ return false;
+ HeatingCoilLevel existingLevel = aHeatingCoilGetter.apply(t),
+ newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z));
+ if (existingLevel == null || existingLevel == HeatingCoilLevel.None) {
+ return aHeatingCoilSetter.test(t, newLevel);
+ } else {
+ return newLevel == existingLevel;
+ }
+ }
+
+ @Override
+ public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger));
+ return true;
+ }
+
+ private int getMeta(ItemStack trigger) {
+ // -4 to skip unimplemented tiers
+ return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.getMaxTier() - 4, Math.max(0, trigger.stackSize - 1))));
+ }
+
+ @Override
+ public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
+ return world.setBlock(x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger), 3);
+ }
+ };
+ }
+}
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 28faeae7e3..12ec2427ce 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -3,29 +3,20 @@ 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;
import gregtech.api.damagesources.GT_DamageSources;
import gregtech.api.enchants.Enchantment_Radioactivity;
-import gregtech.api.enums.GT_Values;
-import gregtech.api.enums.ItemList;
-import gregtech.api.enums.Materials;
-import gregtech.api.enums.OrePrefixes;
-import gregtech.api.enums.SubTag;
-import gregtech.api.enums.Textures;
-import gregtech.api.enums.ToolDictNames;
+import gregtech.api.enums.*;
import gregtech.api.events.BlockScanningEvent;
import gregtech.api.interfaces.IBlockContainer;
import gregtech.api.interfaces.IDebugableBlock;
import gregtech.api.interfaces.IProjectileItem;
import gregtech.api.interfaces.ITexture;
-import gregtech.api.interfaces.tileentity.IBasicEnergyContainer;
-import gregtech.api.interfaces.tileentity.ICoverable;
-import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation;
-import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.interfaces.tileentity.IMachineProgress;
-import gregtech.api.interfaces.tileentity.IUpgradableMachine;
+import gregtech.api.interfaces.tileentity.*;
import gregtech.api.items.GT_EnergyArmor_Item;
import gregtech.api.items.GT_Generic_Item;
import gregtech.api.items.GT_MetaGenerated_Tool;
@@ -41,11 +32,7 @@ import ic2.api.recipe.RecipeOutput;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
-import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityList;
-import net.minecraft.entity.EntityLiving;
-import net.minecraft.entity.EntityLivingBase;
-import net.minecraft.entity.EnumCreatureAttribute;
+import net.minecraft.entity.*;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -81,16 +68,9 @@ import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.world.BlockEvent;
-import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
-import net.minecraftforge.fluids.FluidRegistry;
-import net.minecraftforge.fluids.FluidStack;
-import net.minecraftforge.fluids.FluidTankInfo;
-import net.minecraftforge.fluids.IFluidContainerItem;
-import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.oredict.OreDictionary;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
@@ -99,31 +79,11 @@ import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.UUID;
import static gregtech.GT_Mod.GT_FML_LOGGER;
-import static gregtech.api.enums.GT_Values.D1;
-import static gregtech.api.enums.GT_Values.DW;
-import static gregtech.api.enums.GT_Values.E;
-import static gregtech.api.enums.GT_Values.GT;
-import static gregtech.api.enums.GT_Values.L;
-import static gregtech.api.enums.GT_Values.M;
-import static gregtech.api.enums.GT_Values.NW;
-import static gregtech.api.enums.GT_Values.V;
-import static gregtech.api.enums.GT_Values.W;
+import static gregtech.api.enums.GT_Values.*;
import static gregtech.common.GT_Proxy.GTPOLLUTION;
import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation;
@@ -1939,7 +1899,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);
@@ -1979,6 +1939,17 @@ public class GT_Utility {
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;
tList.add(trans("171","Facing: ") +EnumChatFormatting.GREEN+ ((ic2.api.tile.IWrenchable) tTileEntity).getFacing() +EnumChatFormatting.RESET+ trans("172"," / Chance: ") +EnumChatFormatting.YELLOW+ (((ic2.api.tile.IWrenchable) tTileEntity).getWrenchDropRate() * 100) +EnumChatFormatting.RESET+ "%");
@@ -2871,4 +2842,8 @@ public class GT_Utility {
dropItem.delayBeforeCanPickup = 0;
}
}
+
+ public static long getNonnullElementCount(Object[] tArray) {
+ return Arrays.stream(tArray).filter(Objects::nonNull).count();
+ }
}
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..362fddaf1f
--- /dev/null
+++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java
@@ -0,0 +1,15 @@
+package gregtech.api.util;
+
+
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+
+public interface IGT_HatchAdder<T> {
+ /**
+ * 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/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);
}