From ecbc76dc6d2f1e4fd5de6cafc7b3fa4f74e8c1c2 Mon Sep 17 00:00:00 2001 From: kstvr32 <109012629+kstvr32@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:35:17 -0500 Subject: [PATCH 1/4] Updates Structure checks to add error hinting (#3254) Co-authored-by: kstvr32 Co-authored-by: Martin Robertz --- .../tileentities/multis/MTEWindmill.java | 6 + .../multis/mega/MegaMultiBlockBase.java | 5 + src/main/java/bartworks/util/BWUtil.java | 17 +++ .../tileEntity/MTEFuelRefineFactory.java | 106 ++++++---------- .../goodgenerator/util/StructureHelper.java | 115 ------------------ .../gregtech/api/util/GTStructureUtility.java | 56 +++++++++ .../api/util/HatchElementBuilder.java | 20 +++ .../multi/MTEConcreteBackfillerBase.java | 3 +- .../machines/multi/MTEDrillerBase.java | 1 - .../multi/MTELargeChemicalReactor.java | 7 ++ .../base/GTPPMultiBlockBase.java | 12 ++ .../chemplant/MTEChemicalPlant.java | 6 + ...aTileEntity_PowerSubStationController.java | 32 ++++- .../MTELapotronicSuperCapacitor.java | 11 +- .../common/tileentities/MTETankTFFT.java | 7 ++ 15 files changed, 213 insertions(+), 191 deletions(-) delete mode 100644 src/main/java/goodgenerator/util/StructureHelper.java diff --git a/src/main/java/bartworks/common/tileentities/multis/MTEWindmill.java b/src/main/java/bartworks/common/tileentities/multis/MTEWindmill.java index f86c2a9cc86..40a7aba420b 100644 --- a/src/main/java/bartworks/common/tileentities/multis/MTEWindmill.java +++ b/src/main/java/bartworks/common/tileentities/multis/MTEWindmill.java @@ -153,6 +153,12 @@ public boolean check(MTEWindmill t, World world, int x, int y, int z) { return t.setRotorBlock(tileEntity); } + @Override + public boolean couldBeValid(MTEWindmill mteWindmill, World world, int x, int y, int z, ItemStack trigger) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof TileEntityRotorBlock; + } + @Override public boolean spawnHint(MTEWindmill t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 0); diff --git a/src/main/java/bartworks/common/tileentities/multis/mega/MegaMultiBlockBase.java b/src/main/java/bartworks/common/tileentities/multis/mega/MegaMultiBlockBase.java index a164a7afd28..fc7ca95aae7 100644 --- a/src/main/java/bartworks/common/tileentities/multis/mega/MegaMultiBlockBase.java +++ b/src/main/java/bartworks/common/tileentities/multis/mega/MegaMultiBlockBase.java @@ -172,6 +172,11 @@ public boolean check(T o, World world, int x, int y, int z) { return world.isAirBlock(x, y, z); } + @Override + public boolean couldBeValid(T o, World world, int x, int y, int z, ItemStack trigger) { + return check(o, world, x, y, z); + } + @Override public boolean spawnHint(T o, World world, int x, int y, int z, ItemStack trigger) { if (world.blockExists(x, y, z) && !world.isAirBlock(x, y, z)) diff --git a/src/main/java/bartworks/util/BWUtil.java b/src/main/java/bartworks/util/BWUtil.java index ad75eb275e8..5f536030518 100644 --- a/src/main/java/bartworks/util/BWUtil.java +++ b/src/main/java/bartworks/util/BWUtil.java @@ -304,6 +304,18 @@ public boolean check(T te, World world, int x, int y, int z) { return getter.apply(te) == glassTier; } + @Override + public boolean couldBeValid(T te, World world, int x, int y, int z, ItemStack trigger) { + if (world.isAirBlock(x, y, z)) return false; + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + int glassTier = GlassTier.getGlassTier(block, meta); + + // If it is not a glass, the tier will be 0. + return glassTier != 0 && glassTier != notset && glassTier >= mintier && glassTier <= maxtier; + } + @Override public boolean spawnHint(T te, World world, int x, int y, int z, ItemStack itemStack) { StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), aDots - 1); @@ -340,6 +352,11 @@ public boolean check(T te, World world, int x, int y, int z) { return glassTier >= mintier && glassTier <= maxtier; } + @Override + public boolean couldBeValid(T te, World world, int x, int y, int z, ItemStack trigger) { + return check(te, world, x, y, z); + } + @Override public boolean spawnHint(T te, World world, int x, int y, int z, ItemStack itemStack) { StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), aDots - 1); diff --git a/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java b/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java index bb39f70e838..6b4e4f42829 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/MTEFuelRefineFactory.java @@ -1,30 +1,29 @@ package goodgenerator.blocks.tileEntity; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksTiered; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.util.GTStructureUtility.buildHatchAdder; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; -import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; -import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; -import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.ITierConverter; import com.gtnewhorizon.structurelib.structure.StructureDefinition; -import com.gtnewhorizon.structurelib.structure.StructureUtility; import goodgenerator.api.recipe.GoodGeneratorRecipeMaps; import goodgenerator.blocks.tileEntity.base.MTETooltipMultiBlockBaseEM; @@ -55,7 +54,6 @@ public class MTEFuelRefineFactory extends MTETooltipMultiBlockBaseEM implements private IStructureDefinition multiDefinition = null; private int Tier = -1; - private final int[] cnt = new int[] { 0, 0, 0, 0 }; private static final Block[] coils = new Block[] { Loaders.FRF_Coil_1, Loaders.FRF_Coil_2, Loaders.FRF_Coil_3, Loaders.FRF_Coil_4 }; @@ -118,64 +116,42 @@ public IStructureDefinition getStructure_EM() { .addElement('G', ofBlock(Loaders.fieldRestrictingGlass, 0)) .addElement( 'F', - ofChain( - onElementPass(x -> ++x.cnt[0], ofFieldCoil(0)), - onElementPass(x -> ++x.cnt[1], ofFieldCoil(1)), - onElementPass(x -> ++x.cnt[2], ofFieldCoil(2)), - onElementPass(x -> ++x.cnt[3], ofFieldCoil(3)))) + ofBlocksTiered( + fieldCoilTierConverter(), + getAllFieldCoilTiers(), + -1, + MTEFuelRefineFactory::setCoilTier, + MTEFuelRefineFactory::getCoilTier)) .build(); } return multiDefinition; } - public static IStructureElement ofFieldCoil(int aIndex) { - return new IStructureElement<>() { - - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block block = world.getBlock(x, y, z); - return block.equals(coils[aIndex]); - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, coils[getIndex(trigger)], 0); - return true; - } - - private int getIndex(ItemStack trigger) { - int s = trigger.stackSize; - if (s > 4 || s <= 0) s = 4; - return s - 1; + public static ITierConverter fieldCoilTierConverter() { + return (block, meta) -> { + for (int i = 0; i < coils.length; i++) { + if (block.equals(coils[i])) { + return i + 1; + } } + return null; + }; + } - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return world.setBlock(x, y, z, coils[getIndex(trigger)], 0, 3); - } + public static List> getAllFieldCoilTiers() { + ArrayList> tiers = new ArrayList<>(); + for (Block coil : coils) { + tiers.add(Pair.of(coil, 0)); + } + return tiers; + } - @Override - public BlocksToPlace getBlocksToPlace(T t, World world, int x, int y, int z, ItemStack trigger, - AutoPlaceEnvironment env) { - return BlocksToPlace.create(coils[getIndex(trigger)], 0); - } + private void setCoilTier(int tier) { + this.Tier = tier; + } - @Override - public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, - AutoPlaceEnvironment env) { - if (check(t, world, x, y, z)) return PlaceResult.SKIP; - return StructureUtility.survivalPlaceBlock( - coils[getIndex(trigger)], - 0, - world, - x, - y, - z, - env.getSource(), - env.getActor(), - env.getChatter()); - } - }; + private int getCoilTier() { + return this.Tier; } @Override @@ -216,22 +192,8 @@ public String[] getStructureDescription(ItemStack itemStack) { @Override public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { - cnt[0] = 0; - cnt[1] = 0; - cnt[2] = 0; - cnt[3] = 0; - return structureCheck_EM(mName, 7, 12, 1) && getTier() != -1; - } - - public int getTier() { - for (int i = 0; i < 4; i++) { - if (cnt[i] == 32) { - Tier = i + 1; - return i; - } - } Tier = -1; - return -1; + return structureCheck_EM(mName, 7, 12, 1); } @Override diff --git a/src/main/java/goodgenerator/util/StructureHelper.java b/src/main/java/goodgenerator/util/StructureHelper.java deleted file mode 100644 index 215f6fc1cad..00000000000 --- a/src/main/java/goodgenerator/util/StructureHelper.java +++ /dev/null @@ -1,115 +0,0 @@ -package goodgenerator.util; - -import java.util.Arrays; -import java.util.function.BiConsumer; -import java.util.function.BiPredicate; -import java.util.function.Function; - -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 com.gtnewhorizon.structurelib.StructureLibAPI; -import com.gtnewhorizon.structurelib.structure.IStructureElement; - -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.metatileentity.BaseMetaPipeEntity; -import gregtech.api.metatileentity.implementations.MTEFrame; -import gregtech.api.util.GTOreDictUnificator; - -public class StructureHelper { - - public static IStructureElement addFrame(Materials aMaterials) { - return new IStructureElement<>() { - - private IIcon[] mIcons; - - @Override - public boolean check(T t, World world, int x, int y, int z) { - TileEntity tBlock = world.getTileEntity(x, y, z); - if (tBlock instanceof BaseMetaPipeEntity tFrame) { - if (tFrame.isInvalidTileEntity()) return false; - if (tFrame.getMetaTileEntity() instanceof MTEFrame) { - return ((MTEFrame) tFrame.getMetaTileEntity()).mMaterial == aMaterials; - } - } - 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, aMaterials.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon()); - } - StructureLibAPI.hintParticleTinted(world, x, y, z, mIcons, aMaterials.mRGBa); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - ItemStack tFrame = GTOreDictUnificator.get(OrePrefixes.frameGt, aMaterials, 1); - if (tFrame.getItem() instanceof ItemBlock tFrameStackItem) { - return tFrameStackItem - .placeBlockAt(tFrame, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrame)); - } - return false; - } - }; - } - - // Only support to use meta to tier - public static IStructureElement addTieredBlock(Block aBlock, BiConsumer aSetTheFuckingMeta, - Function aGetTheFuckingMeta, int maxMeta) { - return addTieredBlock(aBlock, (t, i) -> { - aSetTheFuckingMeta.accept(t, i); - return true; - }, aGetTheFuckingMeta, maxMeta); - } - - public static IStructureElement addTieredBlock(Block aBlock, BiPredicate aSetTheFuckingMeta, - Function aGetTheFuckingMeta, int maxMeta) { - - return new IStructureElement<>() { - - @Override - public boolean check(T t, World world, int x, int y, int z) { - Block tBlock = world.getBlock(x, y, z); - if (aBlock == tBlock) { - Integer currentMeta = aGetTheFuckingMeta.apply(t); - int newMeta = tBlock.getDamageValue(world, x, y, z) + 1; - if (newMeta > maxMeta) return false; - if (currentMeta == 0) { - return aSetTheFuckingMeta.test(t, newMeta); - } else { - return currentMeta == newMeta; - } - } - return false; - } - - @Override - public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { - StructureLibAPI.hintParticle(world, x, y, z, aBlock, getMeta(trigger)); - return true; - } - - @Override - public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { - return world.setBlock(x, y, z, aBlock, getMeta(trigger), 3); - } - - private int getMeta(ItemStack trigger) { - int meta = trigger.stackSize - 1; - if (meta <= 0) meta = 0; - if (meta >= maxMeta) meta = maxMeta - 1; - return meta; - } - }; - } -} diff --git a/src/main/java/gregtech/api/util/GTStructureUtility.java b/src/main/java/gregtech/api/util/GTStructureUtility.java index 0b6b26dfbdd..2cb1cb0be96 100644 --- a/src/main/java/gregtech/api/util/GTStructureUtility.java +++ b/src/main/java/gregtech/api/util/GTStructureUtility.java @@ -55,6 +55,7 @@ import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.MTEHatch; import gregtech.api.metatileentity.implementations.MTETieredMachineBlock; import gregtech.common.blocks.BlockCasings5; import gregtech.common.blocks.BlockCyclotronCoils; @@ -95,6 +96,11 @@ public boolean check(T t, World world, int x, int y, int z) { return false; } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + return check(t, world, x, y, z); + } + @Override public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { world.setBlock(x, y, z, Blocks.water, 0, 2); @@ -132,6 +138,11 @@ public boolean check(T t, World world, int x, int y, int z) { return false; } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + return check(t, world, x, y, z); + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { if (mIcons == null) { @@ -249,6 +260,12 @@ public boolean check(T t, World world, int x, int y, int z) { && aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex); } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof IGregTechTileEntity; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, aHintMeta); @@ -325,6 +342,12 @@ public boolean check(T t, World world, int x, int y, int z) { && aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex); } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof IGregTechTileEntity; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, aHintMeta); @@ -417,6 +440,14 @@ public boolean check(T t, World world, int x, int y, int z) { || (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta); } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return (tileEntity instanceof IGregTechTileEntity) + || (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); @@ -480,6 +511,15 @@ public boolean check(T t, World world, int x, int y, int z) { } } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + Block block = world.getBlock(x, y, z); + if (!(block instanceof IHeatingCoil)) return false; + HeatingCoilLevel blockLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)); + HeatingCoilLevel expectedLevel = getHeatFromHint(trigger); + return blockLevel == expectedLevel; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, GregTechAPI.sBlockCasings5, getMetaFromHint(trigger)); @@ -587,6 +627,17 @@ public boolean check(T t, World world, int x, int y, int z) { } } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + Block block = world.getBlock(x, y, z); + if (block != GregTechAPI.sSolenoidCoilCasings) return false; + + int expectedMeta = getMetaFromHint(trigger); + int blockMeta = world.getBlockMetadata(x, y, z); + + return expectedMeta == blockMeta; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI @@ -659,6 +710,11 @@ public static Predicate filterByMTEClass(List filterByMTETier(int aMinTier, int aMaxTier) { return is -> { IMetaTileEntity tile = ItemMachines.getMetaTileEntity(is); + + if (tile instanceof MTEHatch hatch) { + if (hatch.getTierForStructure() <= aMaxTier && hatch.getTierForStructure() >= aMinTier) return true; + } + return tile instanceof MTETieredMachineBlock && ((MTETieredMachineBlock) tile).mTier <= aMaxTier && ((MTETieredMachineBlock) tile).mTier >= aMinTier; }; diff --git a/src/main/java/gregtech/api/util/HatchElementBuilder.java b/src/main/java/gregtech/api/util/HatchElementBuilder.java index d5517a451eb..045fd4ffe9d 100644 --- a/src/main/java/gregtech/api/util/HatchElementBuilder.java +++ b/src/main/java/gregtech/api/util/HatchElementBuilder.java @@ -402,6 +402,13 @@ public boolean check(T t, World world, int x, int y, int z) { && mAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) mCasingIndex); } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + // without modifying state, the best we can do is verify that this is a GT TE. + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof IGregTechTileEntity; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), mDot - 1); @@ -420,6 +427,19 @@ public boolean check(T t, World world, int x, int y, int z) { && mAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) mCasingIndex); } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof IGregTechTileEntity gtTileEntity) { + // verify that the block matches the item hatch filter + ItemStack blockItem = gtTileEntity.getMetaTileEntity() + .getStackForm(0); + return mHatchItemFilter.apply(t, trigger) + .test(blockItem); + } + return false; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), mDot - 1); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEConcreteBackfillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEConcreteBackfillerBase.java index 1ed03c7f2e2..b61973edc76 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEConcreteBackfillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEConcreteBackfillerBase.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.HatchElement.InputBus; import static gregtech.api.enums.HatchElement.InputHatch; import static gregtech.api.enums.HatchElement.Maintenance; +import static gregtech.api.enums.HatchElement.OutputBus; import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import java.util.List; @@ -125,7 +126,7 @@ protected boolean checkHatches() { @Override protected List> getAllowedHatches() { - return ImmutableList.of(InputHatch, InputBus, Maintenance, Energy); + return ImmutableList.of(InputHatch, InputBus, OutputBus, Maintenance, Energy); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEDrillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEDrillerBase.java index 4f7788d39c9..a729edeaeff 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEDrillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEDrillerBase.java @@ -116,7 +116,6 @@ protected IStructureDefinition computeValue(Class type) { 'b', lazy( t -> buildHatchAdder(MTEDrillerBase.class).atLeastList(t.getAllowedHatches()) - .adder(MTEDrillerBase::addToMachineList) .casingIndex(t.casingTextureIndex) .dot(1) .buildAndChain( diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java index 02c8f19ae0c..1d4026aff66 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTELargeChemicalReactor.java @@ -235,6 +235,13 @@ public boolean check(MTELargeChemicalReactor t, World world, int x, int y, int z } } + @Override + public boolean couldBeValid(MTELargeChemicalReactor t, World world, int x, int y, int z, ItemStack trigger) { + Block block = world.getBlock(x, y, z); + return block instanceof IHeatingCoil + && ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)) != HeatingCoilLevel.None; + } + @Override public boolean spawnHint(MTELargeChemicalReactor t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, GregTechAPI.sBlockCasings5, 0); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java index 08ee64597c9..22f0ec2701c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GTPPMultiBlockBase.java @@ -1068,6 +1068,18 @@ public boolean check(T t, World world, int x, int y, int z) { return false; } + @Override + public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) { + Block tBlock = world.getBlock(x, y, z); + if (aBlock == tBlock) { + int expectedMeta = getMeta(trigger); + int blockMeta = tBlock.getDamageValue(world, x, y, z) + 1; + if (blockMeta > maxMeta || blockMeta < minMeta + 1) return false; + return expectedMeta == blockMeta; + } + return false; + } + @Override public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { StructureLibAPI.hintParticle(world, x, y, z, aBlock, getMeta(trigger)); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/MTEChemicalPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/MTEChemicalPlant.java index e6ab4b7c1c4..41075e8d583 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/MTEChemicalPlant.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/MTEChemicalPlant.java @@ -263,6 +263,12 @@ public boolean check(MTEChemicalPlant t, World world, int x, int y, int z) { } else return false; } + @Override + public boolean couldBeValid(MTEChemicalPlant mteChemicalPlant, World world, int x, int y, int z, + ItemStack trigger) { + return check(aIndex, world, x, y, z); + } + private boolean check(int aIndex, World world, int x, int y, int z) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java index 492cb11081e..01aaf05b4f8 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -1,6 +1,7 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksTiered; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onlyIf; @@ -15,6 +16,9 @@ import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GTPPMultiBlockBase.GTPPHatchElement.TTDynamo; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GTPPMultiBlockBase.GTPPHatchElement.TTEnergy; +import java.util.ArrayList; +import java.util.List; + import javax.annotation.Nullable; import net.minecraft.block.Block; @@ -26,6 +30,7 @@ import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.ForgeDirection; +import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.StructureLibAPI; @@ -35,6 +40,7 @@ import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.ITierConverter; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureUtility; import com.gtnewhorizons.modularui.api.NumberFormatMUI; @@ -286,12 +292,36 @@ public IStructureDefinition ge onElementPass(x -> ++x.cellCount[3], ofCell(7)), onElementPass(x -> ++x.cellCount[4], ofCell(8)), onElementPass(x -> ++x.cellCount[5], ofCell(9)))))))) - .addElement('H', ofCell(4)) + .addElement( + 'H', + withChannel( + "cell", + // Adding this so preview looks correct + ofBlocksTiered(cellTierConverter(), getAllCellTiers(), -1, (te, t) -> {}, (te) -> -1))) .build(); } return STRUCTURE_DEFINITION; } + public static ITierConverter cellTierConverter() { + return (block, meta) -> { + int tier = getCellTier(block, meta); + if (tier == -1) return null; + return tier; + }; + } + + public static List> getAllCellTiers() { + ArrayList> tiers = new ArrayList<>(); + tiers.add(Pair.of(ModBlocks.blockCasings2Misc, 7)); + tiers.add(Pair.of(ModBlocks.blockCasings3Misc, 4)); + tiers.add(Pair.of(ModBlocks.blockCasings3Misc, 5)); + tiers.add(Pair.of(ModBlocks.blockCasings3Misc, 6)); + tiers.add(Pair.of(ModBlocks.blockCasings3Misc, 7)); + tiers.add(Pair.of(ModBlocks.blockCasings3Misc, 8)); + return tiers; + } + public static IStructureElement ofCell(int aIndex) { return new IStructureElement() { diff --git a/src/main/java/kekztech/common/tileentities/MTELapotronicSuperCapacitor.java b/src/main/java/kekztech/common/tileentities/MTELapotronicSuperCapacitor.java index 1bffe0045d2..4ae99ac3638 100644 --- a/src/main/java/kekztech/common/tileentities/MTELapotronicSuperCapacitor.java +++ b/src/main/java/kekztech/common/tileentities/MTELapotronicSuperCapacitor.java @@ -1,6 +1,7 @@ package kekztech.common.tileentities; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; import static com.gtnewhorizon.structurelib.structure.StructureUtility.onlyIf; @@ -240,6 +241,14 @@ public boolean check(MTELapotronicSuperCapacitor t, World world, int x, int y, i return true; } + @Override + public boolean couldBeValid(MTELapotronicSuperCapacitor mteLapotronicSuperCapacitor, + World world, int x, int y, int z, ItemStack trigger) { + Block worldBlock = world.getBlock(x, y, z); + int meta = worldBlock.getDamageValue(world, x, y, z); + return LSC_PART == worldBlock && meta != 0; + } + private int getHint(ItemStack stack) { return Capacitor.VALUES_BY_TIER[min( Capacitor.VALUES_BY_TIER.length, @@ -288,7 +297,7 @@ public PlaceResult survivalPlaceBlock(MTELapotronicSuperCapacitor t, World world chatter); } })))) - .addElement('C', ofBlock(LSC_PART, 1)) + .addElement('C', ofBlockAnyMeta(LSC_PART, 1)) .build(); private static final BigInteger MAX_LONG = BigInteger.valueOf(Long.MAX_VALUE); diff --git a/src/main/java/kekztech/common/tileentities/MTETankTFFT.java b/src/main/java/kekztech/common/tileentities/MTETankTFFT.java index 39c2c4d9a68..f19cd5fabfd 100644 --- a/src/main/java/kekztech/common/tileentities/MTETankTFFT.java +++ b/src/main/java/kekztech/common/tileentities/MTETankTFFT.java @@ -134,6 +134,13 @@ public boolean check(MTETankTFFT t, World world, int x, int y, int z) { return true; } + @Override + public boolean couldBeValid(MTETankTFFT t, World world, int x, int y, int z, ItemStack trigger) { + Block worldBlock = world.getBlock(x, y, z); + int meta = worldBlock.getDamageValue(world, x, y, z); + return TFFT_FIELD == worldBlock && meta != 0; + } + private int getHint(ItemStack stack) { return Math.min(Field.VALUES.length, ChannelDataAccessor.getChannelData(stack, "field")); } From 29a106c6732e5324e2addbfe40f137d74d39a0f2 Mon Sep 17 00:00:00 2001 From: Sampsa <69092953+S4mpsa@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:42:22 +0200 Subject: [PATCH 2/4] Add separate minimum & default tick rates for covers (#3722) Co-authored-by: Sampsa Co-authored-by: Martin Robertz Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com> --- .../gregtech/api/util/CoverBehaviorBase.java | 19 +++++++++++++++++++ .../gregtech/common/covers/CoverInfo.java | 2 ++ .../common/covers/CoverItemMeter.java | 6 ++++++ .../common/covers/CoverLiquidMeter.java | 6 ++++++ .../CoverAdvancedWirelessRedstoneBase.java | 5 +++++ .../CoverWirelessDoesWorkDetector.java | 6 ++++++ 6 files changed, 44 insertions(+) diff --git a/src/main/java/gregtech/api/util/CoverBehaviorBase.java b/src/main/java/gregtech/api/util/CoverBehaviorBase.java index cd8a1f5ba92..552eeabe66f 100644 --- a/src/main/java/gregtech/api/util/CoverBehaviorBase.java +++ b/src/main/java/gregtech/api/util/CoverBehaviorBase.java @@ -376,6 +376,16 @@ public final int getTickRate(ForgeDirection side, int aCoverID, ISerializableObj return getTickRateImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); } + /** + * Gets the initial tick rate for doCoverThings of the Cover + *

+ * Defaults to getTickRate(), override for different initial and minimum tick rates + */ + public final int getDefaultTickRate(ForgeDirection side, int aCoverID, ISerializableObject aCoverVariable, + ICoverable aTileEntity) { + return getDefaultTickRateImpl(side, aCoverID, forceCast(aCoverVariable), aTileEntity); + } + /** * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). */ @@ -760,6 +770,15 @@ protected int getTickRateImpl(ForgeDirection side, int aCoverID, T aCoverVariabl return 0; } + /** + * Gets the initial tick rate for doCoverThings of the Cover + *

+ * Defaults to getTickRate(), override for different initial and minimum tick rates + */ + protected int getDefaultTickRateImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return getTickRateImpl(side, aCoverID, aCoverVariable, aTileEntity); + } + /** * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). */ diff --git a/src/main/java/gregtech/common/covers/CoverInfo.java b/src/main/java/gregtech/common/covers/CoverInfo.java index 0a3ef3a07b7..8c5f4fdd25c 100644 --- a/src/main/java/gregtech/common/covers/CoverInfo.java +++ b/src/main/java/gregtech/common/covers/CoverInfo.java @@ -52,6 +52,8 @@ public CoverInfo(ForgeDirection side, int aID, ICoverable aTile, ISerializableOb coverBehavior = GregTechAPI.getCoverBehaviorNew(aID); coverData = aCoverData == null ? coverBehavior.createDataObject() : aCoverData; coveredTile = new WeakReference<>(aTile); + tickRateAddition = coverBehavior.getDefaultTickRate(coverSide, coverID, coverData, coveredTile.get()) + - this.getMinimumTickRate(); } public CoverInfo(ICoverable aTile, NBTTagCompound aNBT) { diff --git a/src/main/java/gregtech/common/covers/CoverItemMeter.java b/src/main/java/gregtech/common/covers/CoverItemMeter.java index 376a93682c3..84a2c9613c7 100644 --- a/src/main/java/gregtech/common/covers/CoverItemMeter.java +++ b/src/main/java/gregtech/common/covers/CoverItemMeter.java @@ -178,6 +178,12 @@ protected boolean manipulatesSidedRedstoneOutputImpl(ForgeDirection side, int aC @Override protected int getTickRateImpl(ForgeDirection side, int aCoverID, ItemMeterData aCoverVariable, + ICoverable aTileEntity) { + return 1; + } + + @Override + protected int getDefaultTickRateImpl(ForgeDirection side, int aCoverID, ItemMeterData aCoverVariable, ICoverable aTileEntity) { return 5; } diff --git a/src/main/java/gregtech/common/covers/CoverLiquidMeter.java b/src/main/java/gregtech/common/covers/CoverLiquidMeter.java index 2f13f25421e..c826d794829 100644 --- a/src/main/java/gregtech/common/covers/CoverLiquidMeter.java +++ b/src/main/java/gregtech/common/covers/CoverLiquidMeter.java @@ -150,6 +150,12 @@ protected boolean manipulatesSidedRedstoneOutputImpl(ForgeDirection side, int aC @Override protected int getTickRateImpl(ForgeDirection side, int aCoverID, LiquidMeterData aCoverVariable, + ICoverable aTileEntity) { + return 1; + } + + @Override + protected int getDefaultTickRateImpl(ForgeDirection side, int aCoverID, LiquidMeterData aCoverVariable, ICoverable aTileEntity) { return 5; } diff --git a/src/main/java/gregtech/common/covers/redstone/CoverAdvancedWirelessRedstoneBase.java b/src/main/java/gregtech/common/covers/redstone/CoverAdvancedWirelessRedstoneBase.java index 963678a24cb..e3881258ca4 100644 --- a/src/main/java/gregtech/common/covers/redstone/CoverAdvancedWirelessRedstoneBase.java +++ b/src/main/java/gregtech/common/covers/redstone/CoverAdvancedWirelessRedstoneBase.java @@ -150,6 +150,11 @@ public String getDescriptionImpl(ForgeDirection side, int aCoverID, T aCoverVari @Override public int getTickRateImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { + return 1; + } + + @Override + protected int getDefaultTickRateImpl(ForgeDirection side, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { return 5; } diff --git a/src/main/java/gregtech/common/covers/redstone/CoverWirelessDoesWorkDetector.java b/src/main/java/gregtech/common/covers/redstone/CoverWirelessDoesWorkDetector.java index 1d5f89ee902..769f578fd12 100644 --- a/src/main/java/gregtech/common/covers/redstone/CoverWirelessDoesWorkDetector.java +++ b/src/main/java/gregtech/common/covers/redstone/CoverWirelessDoesWorkDetector.java @@ -95,6 +95,12 @@ protected boolean manipulatesSidedRedstoneOutputImpl(ForgeDirection side, int aC @Override public int getTickRateImpl(ForgeDirection side, int aCoverID, ActivityTransmitterData aCoverVariable, + ICoverable aTileEntity) { + return 1; + } + + @Override + protected int getDefaultTickRateImpl(ForgeDirection side, int aCoverID, ActivityTransmitterData aCoverVariable, ICoverable aTileEntity) { return 5; } From 85b17a1854d99b1a2e5bb8621b785ae64ff3aca7 Mon Sep 17 00:00:00 2001 From: HoleFish <48403212+HoleFish@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:34:53 +0800 Subject: [PATCH 3/4] Disable wirecutter interaction on EOH when it's working (#3710) Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com> Co-authored-by: Martin Robertz --- .../metaTileEntity/multi/MTEEyeOfHarmony.java | 32 +++++++++++++------ .../resources/assets/tectech/lang/en_US.lang | 3 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java b/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java index 4f4a8dfce7e..ea1f38a0d2a 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/MTEEyeOfHarmony.java @@ -46,6 +46,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MathHelper; +import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -938,17 +939,30 @@ public final void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPla public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, float aX, float aY, float aZ, ItemStack aTool) { if (astralArrayAmount != 0) { - while (astralArrayAmount >= 64) { + if (recipeRunning) { + GTUtility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("eoh.rightclick.wirecutter.1")); + } else { + long originalAmount = astralArrayAmount; + while (astralArrayAmount >= 64) { + if (aPlayer.inventory.getFirstEmptyStack() != -1) { + aPlayer.inventory.addItemStackToInventory(CustomItemList.astralArrayFabricator.get(64)); + astralArrayAmount -= 64; + } else { + break; + } + } if (aPlayer.inventory.getFirstEmptyStack() != -1) { - aPlayer.inventory.addItemStackToInventory(CustomItemList.astralArrayFabricator.get(64)); - astralArrayAmount -= 64; - } else { - break; + aPlayer.inventory + .addItemStackToInventory(CustomItemList.astralArrayFabricator.get(astralArrayAmount)); + astralArrayAmount = 0; + } + if (originalAmount - astralArrayAmount > 0) { + GTUtility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocalFormatted( + "eoh.rightclick.wirecutter.2", + GTUtility.formatNumbers(originalAmount - astralArrayAmount))); } - } - if (aPlayer.inventory.getFirstEmptyStack() != -1) { - aPlayer.inventory.addItemStackToInventory(CustomItemList.astralArrayFabricator.get(astralArrayAmount)); - astralArrayAmount = 0; } } return true; diff --git a/src/main/resources/assets/tectech/lang/en_US.lang b/src/main/resources/assets/tectech/lang/en_US.lang index 34d60bf04ce..df5d9fa8166 100644 --- a/src/main/resources/assets/tectech/lang/en_US.lang +++ b/src/main/resources/assets/tectech/lang/en_US.lang @@ -851,7 +851,8 @@ gt.blockcasingsBA0.11.desc.1=Can survive at least one big bang, maybe two... achievement.gt.blockcasingsBA0.10=Reinforced Temporal Structure Casing gt.blockcasingsBA0.10.desc.0=Resistant to temporal shearing from time dilation differences. gt.blockcasingsBA0.10.desc.1=This block can last an eternity without any decay. - +eoh.rightclick.wirecutter.1=Can't retrieve Astral Array Fabricators when the machine is working! +eoh.rightclick.wirecutter.2=Retrieved %s Astral Array Fabricators # Antimatter gt.blockmachines.antimatterForge.name=Semi-Stable Antimatter Stabilization Sequencer From e4a885a62ab1393002e4dad0fa0293ad81d18004 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Fri, 27 Dec 2024 00:51:48 -0500 Subject: [PATCH 4/4] Matter manipulator compat (#3222) Co-authored-by: Martin Robertz Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com> --- .../gregtech/api/enums/MetaTileEntityIDs.java | 2 + .../java/gregtech/api/enums/OrePrefixes.java | 51 +++++++ .../api/interfaces/tileentity/ICoverable.java | 4 + .../tileentity/IRedstoneEmitter.java | 19 +++ .../metatileentity/BaseMetaTileEntity.java | 4 + .../metatileentity/CoverableTileEntity.java | 30 ++++ .../java/gregtech/api/util/GTUtility.java | 134 +++++++++++++++++- .../tileentities/base/TileEntityBase.java | 35 +++++ .../metaTileEntity/multi/base/Parameters.java | 31 ++++ 9 files changed, 309 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java index 1ab129e110e..4e7c28a2bda 100644 --- a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java +++ b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java @@ -759,6 +759,8 @@ public enum MetaTileEntityIDs { SOLAR_PANEL_LuV(2736), SOLAR_PANEL_ZPM(2737), SOLAR_PANEL_UV(2738), + MATTER_MANIPULATOR_UPLINK(2750), + HATCH_MATTER_MANIPULATOR_UPLINK_ME(2751), INDUSTRIAL_LASER_ENGRAVER_CONTROLLER(3004), INDUSTRIAL_COMPRESSOR_CONTROLLER(3005), HIP_COMPRESSOR_CONTROLLER(3006), diff --git a/src/main/java/gregtech/api/enums/OrePrefixes.java b/src/main/java/gregtech/api/enums/OrePrefixes.java index 159e0461881..81259da9bfd 100644 --- a/src/main/java/gregtech/api/enums/OrePrefixes.java +++ b/src/main/java/gregtech/api/enums/OrePrefixes.java @@ -12,6 +12,7 @@ import java.util.List; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; import com.google.common.collect.ImmutableList; @@ -25,7 +26,10 @@ import gregtech.api.objects.MaterialStack; import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; +import gregtech.api.util.GTUtility.ItemId; import gregtech.loaders.materialprocessing.ProcessingModSupport; +import it.unimi.dsi.fastutil.Pair; +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import it.unimi.dsi.fastutil.objects.ObjectSet; @@ -1184,6 +1188,53 @@ public static String stripPrefix(String aOre) { return aOre; } + public static Pair detectPrefix(String oredictName) { + for (OrePrefixes prefix : values()) { + if (oredictName.startsWith(prefix.name())) { + return Pair.of( + prefix, + oredictName.substring( + prefix.name() + .length())); + } + } + + return null; + } + + private static final ThreadLocal>>> PREFIX_CACHE = ThreadLocal + .withInitial(Object2ObjectLinkedOpenHashMap::new); + + public static ImmutableList> detectPrefix(ItemStack stack) { + Object2ObjectLinkedOpenHashMap>> cache = PREFIX_CACHE.get(); + + ItemId itemId = ItemId.create(stack); + + var cacheResult = cache.getAndMoveToFirst(itemId); + + if (cacheResult != null) return cacheResult; + + ImmutableList.Builder> result = ImmutableList.builder(); + + for (int id : OreDictionary.getOreIDs(stack)) { + Pair p = detectPrefix(OreDictionary.getOreName(id)); + + if (p != null) { + result.add(p); + } + } + + ImmutableList> prefixes = result.build(); + + cache.putAndMoveToFirst(itemId, prefixes); + + while (cache.size() > 1024) { + cache.removeLast(); + } + + return prefixes; + } + public static String replacePrefix(String aOre, OrePrefixes aPrefix) { for (OrePrefixes tPrefix : values()) { if (aOre.startsWith(tPrefix.toString())) { diff --git a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java index 00ae2db9bd0..87b87598cb6 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/ICoverable.java @@ -17,6 +17,10 @@ public interface ICoverable extends IRedstoneTileEntity, IHasInventory, IBasicEn boolean dropCover(ForgeDirection side, ForgeDirection droppedSide, boolean aForced); + default ItemStack removeCoverAtSide(ForgeDirection side, boolean aForced) { + return null; + } + @Deprecated void setCoverDataAtSide(ForgeDirection side, int aData); diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java b/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java index 1b280184ce7..42dff0802dc 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java @@ -38,6 +38,25 @@ public interface IRedstoneEmitter extends IHasWorldObjectAndCoords { */ void setStrongOutputRedstoneSignal(ForgeDirection side, byte aStrength); + /** + * Sets the strength of the redstone signal on the given side to strong or weak. + * Does not change the actual signal. + * + * @param side Must not be UNKNOWN + * @param isStrong True = strong, false = weak + */ + default void setRedstoneOutputStrength(ForgeDirection side, boolean isStrong) {} + + /** + * Checks if the given side will output a strong redstone signal when emitting a redstone signal. + * + * @param side Must not be UNKNOWN + * @return True = strong signal, false = weak signal + */ + default boolean getRedstoneOutputStrength(ForgeDirection side) { + return false; + } + /** * Gets the Output for the comparator on the given Side */ diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 79cb8cccff3..a3ed50ef81a 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1180,6 +1180,10 @@ public void generatePowerNodes() { } } + public void setCableUpdateDelay(int delay) { + cableUpdateDelay = delay; + } + @Override public long getOutputAmperage() { if (canAccessData() && mMetaTileEntity.isElectric()) return mMetaTileEntity.maxAmperesOut(); diff --git a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java index c9376504f60..02877d8497f 100644 --- a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java @@ -421,6 +421,21 @@ public boolean dropCover(ForgeDirection side, ForgeDirection droppedSide, boolea return true; } + @Override + public ItemStack removeCoverAtSide(ForgeDirection side, boolean aForced) { + final CoverInfo coverInfo = getCoverInfoAtSide(side); + if (!coverInfo.isValid()) return null; + if (!coverInfo.onCoverRemoval(aForced) && !aForced) return null; + final ItemStack tStack = coverInfo.getDrop(); + if (tStack != null) { + coverInfo.onDropped(); + } + clearCoverInfoAtSide(side); + updateOutputRedstoneSignal(side); + + return tStack; + } + protected void onBaseTEDestroyed() { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { final CoverInfo coverInfo = getCoverInfoAtSide(side); @@ -446,6 +461,21 @@ public void setStrongOutputRedstoneSignal(ForgeDirection side, byte strength) { setOutputRedstoneSignal(side, strength); } + @Override + public void setRedstoneOutputStrength(ForgeDirection side, boolean isStrong) { + if (isStrong) { + mStrongRedstone |= (byte) side.flag; + } else { + mStrongRedstone &= ~(byte) side.flag; + } + setOutputRedstoneSignal(side, mSidedRedstone[side.ordinal()]); + } + + @Override + public boolean getRedstoneOutputStrength(ForgeDirection side) { + return (mStrongRedstone & side.flag) != 0; + } + @Override public void setInternalOutputRedstoneSignal(ForgeDirection side, byte aStrength) { if (!getCoverBehaviorAtSideNew(side) diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index da805f995db..dc863c64cda 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -114,6 +114,8 @@ import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; +import org.joml.Vector3i; + import com.google.auto.value.AutoValue; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; @@ -4516,6 +4518,14 @@ public static int clamp(int val, int lo, int hi) { return MathHelper.clamp_int(val, lo, hi); } + public static int min(int first, int... rest) { + for (int i = 0; i < rest.length; i++) { + int l = rest[i]; + if (l < first) first = l; + } + return first; + } + public static long min(long first, long... rest) { for (int i = 0; i < rest.length; i++) { long l = rest[i]; @@ -4524,6 +4534,14 @@ public static long min(long first, long... rest) { return first; } + public static int max(int first, int... rest) { + for (int i = 0; i < rest.length; i++) { + int l = rest[i]; + if (l > first) first = l; + } + return first; + } + public static long max(long first, long... rest) { for (int i = 0; i < rest.length; i++) { long l = rest[i]; @@ -4536,10 +4554,41 @@ public static int ceilDiv(int lhs, int rhs) { return (lhs + rhs - 1) / rhs; } + /** Handles negatives properly, but it's slower than {@link #ceilDiv(int, int)}. */ + public static int ceilDiv2(int lhs, int rhs) { + int sign = signum(lhs) * signum(rhs); + + if (lhs == 0) return 0; + if (rhs == 0) throw new ArithmeticException("/ by zero"); + + lhs = Math.abs(lhs); + rhs = Math.abs(rhs); + + int unsigned = 1 + ((lhs - 1) / rhs); + + return unsigned * sign; + } + public static long ceilDiv(long lhs, long rhs) { return (lhs + rhs - 1) / rhs; } + public static int signum(int x) { + return x < 0 ? -1 : x > 0 ? 1 : 0; + } + + public static long signum(long x) { + return x < 0 ? -1 : x > 0 ? 1 : 0; + } + + public static Vector3i signum(Vector3i v) { + v.x = signum(v.x); + v.y = signum(v.y); + v.z = signum(v.z); + + return v; + } + /** * Hash an item stack for the purpose of storing hash across launches */ @@ -4781,6 +4830,14 @@ public static ItemId createAsWildcard(ItemStack itemStack) { return new AutoValue_GTUtility_ItemId(itemStack.getItem(), W, null, null); } + public static ItemId createAsWildcardWithNBT(ItemStack itemStack) { + NBTTagCompound nbt = itemStack.getTagCompound(); + if (nbt != null) { + nbt = (NBTTagCompound) nbt.copy(); + } + return new AutoValue_GTUtility_ItemId(itemStack.getItem(), W, nbt, null); + } + /** * This method stores NBT as null. */ @@ -4839,9 +4896,84 @@ public NBTTagCompound writeToNBT() { @Nonnull public ItemStack getItemStack() { ItemStack itemStack = new ItemStack(item(), 1, metaData()); - itemStack.setTagCompound(nbt()); + NBTTagCompound nbt = nbt(); + itemStack.setTagCompound(nbt == null ? null : (NBTTagCompound) nbt.copy()); return itemStack; } + + @Nonnull + public ItemStack getItemStack(int stackSize) { + ItemStack itemStack = new ItemStack(item(), stackSize, metaData()); + NBTTagCompound nbt = nbt(); + itemStack.setTagCompound(nbt == null ? null : (NBTTagCompound) nbt.copy()); + return itemStack; + } + } + + @AutoValue + public abstract static class FluidId { + + public static FluidId create(NBTTagCompound tag) { + return new AutoValue_GTUtility_FluidId( + FluidRegistry.getFluid(tag.getString("FluidName")), + tag.hasKey("Tag", Constants.NBT.TAG_COMPOUND) ? tag.getCompoundTag("Tag") : null, + tag.hasKey("Amount", Constants.NBT.TAG_INT) ? tag.getInteger("Amount") : null); + } + + public NBTTagCompound writeToNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("FluidName", fluid().getName()); + if (nbt() != null) tag.setTag("Tag", nbt()); + Integer amount = amount(); + if (amount != null) tag.setInteger("Amount", amount); + return tag; + } + + public static FluidId create(FluidStack fluidStack) { + return createWithCopy(fluidStack.getFluid(), null, fluidStack.tag); + } + + public static FluidId createWithAmount(FluidStack fluidStack) { + return createWithCopy(fluidStack.getFluid(), (Integer) fluidStack.amount, fluidStack.tag); + } + + public static FluidId create(Fluid fluid) { + return createNoCopy(fluid, null, null); + } + + public static FluidId createWithCopy(Fluid fluid, Integer amount, @Nullable NBTTagCompound nbt) { + if (nbt != null) { + nbt = (NBTTagCompound) nbt.copy(); + } + return new AutoValue_GTUtility_FluidId(fluid, nbt, amount); + } + + /** + * This method does not copy the NBT tag. + */ + public static FluidId createNoCopy(Fluid fluid, Integer amount, @Nullable NBTTagCompound nbt) { + return new AutoValue_GTUtility_FluidId(fluid, nbt, amount); + } + + protected abstract Fluid fluid(); + + @Nullable + protected abstract NBTTagCompound nbt(); + + @Nullable + protected abstract Integer amount(); + + @Nonnull + public FluidStack getFluidStack() { + NBTTagCompound nbt = nbt(); + return new FluidStack(fluid(), 1, nbt != null ? (NBTTagCompound) nbt.copy() : null); + } + + @Nonnull + public FluidStack getFluidStack(int amount) { + NBTTagCompound nbt = nbt(); + return new FluidStack(fluid(), amount, nbt != null ? (NBTTagCompound) nbt.copy() : null); + } } public static int getPlasmaFuelValueInEUPerLiterFromMaterial(Materials material) { diff --git a/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java b/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java index 811fb0cab13..63a2d8329bf 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java +++ b/src/main/java/gtPlusPlus/core/tileentities/base/TileEntityBase.java @@ -1063,6 +1063,26 @@ public boolean dropCover(ForgeDirection side, ForgeDirection droppedSide, boolea return false; } + @Override + public ItemStack removeCoverAtSide(ForgeDirection side, boolean aForced) { + if (getCoverBehaviorAtSide(side) + .onCoverRemoval(side, getCoverIDAtSide(side), mCoverData[side.ordinal()], this, aForced) || aForced) { + ItemStack tStack = getCoverBehaviorAtSide(side) + .getDrop(side, getCoverIDAtSide(side), getCoverDataAtSide(side), this); + if (tStack != null) { + tStack.setTagCompound(null); + } + setCoverIDAtSide(side, 0); + if (mMetaTileEntity.hasSidedRedstoneOutputBehavior()) { + setOutputRedstoneSignal(side, (byte) 0); + } else { + setOutputRedstoneSignal(side, (byte) 15); + } + return tStack; + } + return null; + } + public String getOwnerName() { if (GTUtility.isStringInvalid(mOwnerName)) return "Player"; return mOwnerName; @@ -1092,6 +1112,21 @@ public void setStrongOutputRedstoneSignal(ForgeDirection side, byte aStrength) { setOutputRedstoneSignal(side, aStrength); } + @Override + public void setRedstoneOutputStrength(ForgeDirection side, boolean isStrong) { + if (isStrong) { + mStrongRedstone |= (byte) side.flag; + } else { + mStrongRedstone &= ~(byte) side.flag; + } + setOutputRedstoneSignal(side, mSidedRedstone[side.ordinal()]); + } + + @Override + public boolean getRedstoneOutputStrength(ForgeDirection side) { + return (mStrongRedstone & side.flag) != 0; + } + @Override public long injectEnergyUnits(ForgeDirection side, long aVoltage, long aAmperage) { if (!canAccessData() || !mMetaTileEntity.isElectric() diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/base/Parameters.java b/src/main/java/tectech/thing/metaTileEntity/multi/base/Parameters.java index 27eb961166e..55c78712574 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/base/Parameters.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/base/Parameters.java @@ -1,6 +1,9 @@ package tectech.thing.metaTileEntity.multi.base; import java.util.ArrayList; +import java.util.Arrays; + +import tectech.thing.metaTileEntity.multi.base.Parameters.Group.ParameterIn; /** * Instantiate parameters as field in parametersInstantiation_EM(); @@ -93,6 +96,34 @@ public Group getGroup(int hatchNo) { return groups[hatchNo] != null ? groups[hatchNo] : new Group(hatchNo, false); } + public boolean hasInputs() { + return !parameterInArrayList.isEmpty(); + } + + public double[] getInputs() { + return Arrays.copyOf(iParamsIn, iParamsIn.length); + } + + public void setInputs(double[] inputs) { + if (inputs.length != iParamsIn.length) { + throw new IllegalArgumentException("inputs must be the same length as iParamsIn (20)"); + } + + for (int i = 0; i < iParamsIn.length; i++) { + int hatch = i % 10; + int paramId = i / 10; + + Group group = groups[hatch]; + + if (group != null && (parent.mMaxProgresstime <= 0 || group.updateWhileRunning)) { + ParameterIn param = group.parameterIn[paramId]; + if (param != null) { + param.set(inputs[i] < 0 ? 0 : inputs[i]); + } + } + } + } + public interface IParameter { double get();