diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-07-30 11:54:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-30 11:54:50 +0200 |
commit | 0f7a5c79f0941195d078b1877cd876b1d73b2b33 (patch) | |
tree | 7029c33c0ffb93a1b911ae3395af424ceb7e7743 /src/main/java/gregtech/api | |
parent | 2bff27eca61fd5d19f64969f67442c3a55175d3e (diff) | |
parent | ea5c515f4769fa83f4eb6268f0b8048f76fbb0ac (diff) | |
download | GT5-Unofficial-0f7a5c79f0941195d078b1877cd876b1d73b2b33.tar.gz GT5-Unofficial-0f7a5c79f0941195d078b1877cd876b1d73b2b33.tar.bz2 GT5-Unofficial-0f7a5c79f0941195d078b1877cd876b1d73b2b33.zip |
Merge pull request #551 from GTNewHorizons/structurelib-integration
StructureLib integration
Diffstat (limited to 'src/main/java/gregtech/api')
13 files changed, 843 insertions, 42 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/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/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6c43799638..1adcb41259 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; @@ -25,11 +31,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; @@ -54,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; @@ -73,7 +76,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, 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; @@ -2368,4 +2371,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..63151bde59 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 { @@ -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_CubicMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java new file mode 100644 index 0000000000..de36b845b2 --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_CubicMultiBlockBase.java @@ -0,0 +1,155 @@ +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, 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: + * <ul> + * <li>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. + * Example 1: Require ULV input only: + * <pre> + * {@code + * @Override + * public boolean addInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + * if (aTileEntity == null) return false; + * IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + * if (aMetaTileEntity == null) return false; + * if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + * if (((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier != 0) return false; // addition + * ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + * ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = getRecipeMap(); + * return mInputHatches.add((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity); + * } + * if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + * if (((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier != 0) return false; // addition + * ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + * ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = getRecipeMap(); + * return mInputBusses.add((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity); + * } + * return false; + * } + * }</pre> + * Example 2: Allow dynamo, muffler and prevent energy hatch + * <pre> + * {@code + * @Override + * public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + * return addInputToMachineList(aTileEntity, aBaseCasingIndex) || + * addOutputToMachineList(aTileEntity, aBaseCasingIndex) || + * addDynamoToMachineList(aTileEntity, aBaseCasingIndex) || + * addMufflerToMachineList(aTileEntity, aBaseCasingIndex) || + * addMaintenanceToMachineList(aTileEntity, aBaseCasingIndex); + * } + * }</pre></li> + * <li>To limit rotation, override {@link #getInitialAlignmentLimits()}</li> + *</ul> + * @param <T> this + */ +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); + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + return addInputToMachineList(aTileEntity, aBaseCasingIndex) || + addOutputToMachineList(aTileEntity, aBaseCasingIndex) || + addEnergyInputToMachineList(aTileEntity, aBaseCasingIndex) || + addMaintenanceToMachineList(aTileEntity, aBaseCasingIndex); + } + + /** + * 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_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java index e30fe5d606..9afb9e58c1 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,10 @@ 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]); + hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey()] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new); } public String[] getInformation() { @@ -345,4 +515,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..bb2c644f95 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); @@ -1979,6 +1981,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 +2884,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); } |