diff options
Diffstat (limited to 'src/main/java/gregtech/api/util')
7 files changed, 439 insertions, 67 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index 7e66e6cc2a..ac9f7bd3d4 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -383,14 +383,14 @@ public class GT_ModHandler { } /** - * Gets an Item from RailCraft + * Gets an Item from the specified mod */ public static ItemStack getModItem(String aModID, String aItem, long aAmount) { return getModItem(aModID, aItem, aAmount, null); } /** - * Gets an Item from RailCraft, and returns a Replacement Item if not possible + * Gets an Item from the specified mod, and returns a Replacement Item if not possible */ public static ItemStack getModItem(String aModID, String aItem, long aAmount, ItemStack aReplacement) { if (GT_Utility.isStringInvalid(aItem) || !GregTech_API.sPreloadStarted) return null; @@ -398,7 +398,7 @@ public class GT_ModHandler { } /** - * Gets an Item from RailCraft, but the Damage Value can be specified + * Gets an Item from the specified mod, but the Damage Value can be specified */ public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta) { ItemStack rStack = getModItem(aModID, aItem, aAmount); @@ -408,7 +408,7 @@ public class GT_ModHandler { } /** - * Gets an Item from RailCraft, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible + * Gets an Item from the specified mod, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible */ public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta, ItemStack aReplacement) { ItemStack rStack = getModItem(aModID, aItem, aAmount, aReplacement); diff --git a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java index e30fe5d606..3071cb95a3 100644 --- a/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java +++ b/src/main/java/gregtech/api/util/GT_Multiblock_Tooltip_Builder.java @@ -1,11 +1,19 @@ package gregtech.api.util; -import java.util.LinkedList; -import java.util.List; - +import com.google.common.collect.Multimaps; +import com.google.common.collect.SetMultimap; +import com.gtnewhorizon.structurelib.StructureLibAPI; +import gregtech.api.enums.Materials; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.IntStream; +import java.util.stream.Stream; + /** * This makes it easier to build multi tooltips, with a standardized format. <br> * Info section order should be:<br> @@ -32,12 +40,16 @@ import net.minecraft.util.StatCollector; public class GT_Multiblock_Tooltip_Builder { private static final String TAB = " "; private static final String COLON = ": "; - + private static final String SEPARATOR = ", "; + private final List<String> iLines; private final List<String> sLines; - + private final List<String> hLines; + private final SetMultimap<Integer, String> hBlocks; + private String[] iArray; private String[] sArray; + private String[] hArray; //Localized tooltips private static final String TT_machineType = StatCollector.translateToLocal("GT5U.MBTT.MachineType"); @@ -58,11 +70,17 @@ public class GT_Multiblock_Tooltip_Builder { private static final String TT_pps = StatCollector.translateToLocal("GT5U.MBTT.PPS"); private static final String TT_hold = StatCollector.translateToLocal("GT5U.MBTT.Hold"); private static final String TT_todisplay = StatCollector.translateToLocal("GT5U.MBTT.Display"); + private static final String TT_structurehint = StatCollector.translateToLocal("GT5U.MBTT.StructureHint"); private static final String TT_mod = StatCollector.translateToLocal("GT5U.MBTT.Mod"); + private static final String TT_air = StatCollector.translateToLocal("GT5U.MBTT.Air"); + private static final String[] TT_dots = IntStream.range(0, 16).mapToObj(i -> StatCollector.translateToLocal("structurelib.blockhint." + i + ".name")).toArray(String[]::new); public GT_Multiblock_Tooltip_Builder() { iLines = new LinkedList<>(); sLines = new LinkedList<>(); + hLines = new LinkedList<>(); + hBlocks = Multimaps.newSetMultimap(new HashMap<>(), HashSet::new); + hBlocks.put(StructureLibAPI.HINT_BLOCK_META_AIR, TT_air); } /** @@ -103,11 +121,10 @@ public class GT_Multiblock_Tooltip_Builder { } /** - * Add a line telling you what the machine type is. Usually, this will be the name of a SB version.<br> - * Machine Type: machine + * Add a line telling how much this machine pollutes. * - * @param machine - * Name of the machine type + * @param pollution + * Amount of pollution per second when active * * @return Instance this method was called on. */ @@ -307,7 +324,136 @@ public class GT_Multiblock_Tooltip_Builder { sLines.add(TAB + TT_outputhatch + COLON + info); return this; } - + + /** + * Use this method to add a structural part that isn't covered by the other methods.<br> + * (indent)name: info + * @param name + * Name of the hatch or other component. + * @param info + * Positional information. + * @param dots + * The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOtherStructurePart(String name, String info, int... dots) { + sLines.add(TAB + name + COLON + info); + for (int dot : dots) hBlocks.put(dot, name); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Maintenance Hatch: info + * + * @param info Positional information. + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMaintenanceHatch(String info, int... dots) { + sLines.add(TAB + TT_maintenancehatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_maintenancehatch); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Muffler Hatch: info + * + * @param info Location where the hatch goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addMufflerHatch(String info, int... dots) { + sLines.add(TAB + TT_mufflerhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_mufflerhatch); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Energy Hatch: info + * + * @param info Positional information. + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addEnergyHatch(String info, int... dots) { + sLines.add(TAB + TT_energyhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_energyhatch); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Dynamo Hatch: info + * + * @param info Positional information. + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addDynamoHatch(String info, int... dots) { + sLines.add(TAB + TT_dynamohatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_dynamohatch); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Input Bus: info + * + * @param info Location where the bus goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInputBus(String info, int... dots) { + sLines.add(TAB + TT_inputbus + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_inputbus); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Input Hatch: info + * + * @param info Location where the hatch goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addInputHatch(String info, int... dots) { + sLines.add(TAB + TT_inputhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_inputhatch); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Output Bus: info + * + * @param info Location where the bus goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOutputBus(String info, int... dots) { + sLines.add(TAB + TT_outputbus + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_outputbus); + return this; + } + + /** + * Add a line of information about the structure:<br> + * (indent)Output Hatch: info + * + * @param info Location where the bus goes + * @param dots The valid locations for this part when asked to display hints + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addOutputHatch(String info, int... dots) { + sLines.add(TAB + TT_outputhatch + COLON + info); + for (int dot : dots) hBlocks.put(dot, TT_outputhatch); + return this; + } + /** * Use this method to add non-standard structural info.<br> * (indent)info @@ -319,6 +465,30 @@ public class GT_Multiblock_Tooltip_Builder { sLines.add(TAB + info); return this; } + + /** + * Use this method to add non-standard structural hint. This info will appear before the standard structural hint. + * @param info + * The line to be added. This should be an entry into minecraft's localization system. + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addStructureHint(String info) { + hLines.add(StatCollector.translateToLocal(info)); + return this; + } + + /** + * Use this method to add an entry to standard structural hint without creating a corresponding line in structure information + * @param name + * The name of block This should be an entry into minecraft's localization system. + * @param dots + * Possible locations of this block + * @return Instance this method was called on. + */ + public GT_Multiblock_Tooltip_Builder addStructureHint(String name, int... dots) { + for (int dot : dots) hBlocks.put(dot, StatCollector.translateToLocal(name)); + return this; + } /** * Call at the very end.<br> @@ -331,10 +501,11 @@ public class GT_Multiblock_Tooltip_Builder { public void toolTipFinisher(String mod) { iLines.add(TT_hold + " " + EnumChatFormatting.BOLD + "[LSHIFT]" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " " + TT_todisplay); iLines.add(TT_mod + COLON + EnumChatFormatting.GREEN + mod + EnumChatFormatting.GRAY); - iArray = new String[iLines.size()]; - sArray = new String[sLines.size()]; - iLines.toArray(iArray); - sLines.toArray(sArray); + hLines.add(TT_structurehint); + iArray = iLines.toArray(new String[0]); + sArray = sLines.toArray(new String[0]); + // e.getKey() - 1 because 1 dot is meta 0. + hArray = Stream.concat(hLines.stream(), hBlocks.asMap().entrySet().stream().map(e -> TT_dots[e.getKey() - 1] + COLON + String.join(SEPARATOR, e.getValue()))).toArray(String[]::new); } public String[] getInformation() { @@ -345,4 +516,7 @@ public class GT_Multiblock_Tooltip_Builder { return sArray; } + public String[] getStructureHint() { + return hArray; + } } diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index a04df205b7..19f46dfd15 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -197,6 +197,11 @@ public class GT_Recipe implements Comparable<GT_Recipe> { this(aInput1, aOutput1, null, null, null, aFuelValue, aType); } + private static FluidStack[] tryGetFluidInputsFromCells(ItemStack aInput) { + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true); + return tFluid == null ? null : new FluidStack[] {tFluid}; + } + // aSpecialValue = EU per Liter! If there is no Liquid for this Object, then it gets multiplied with 1000! public GT_Recipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2, ItemStack aOutput3, ItemStack aOutput4, int aSpecialValue, int aType) { this(true, new ItemStack[]{aInput1}, new ItemStack[]{aOutput1, aOutput2, aOutput3, aOutput4}, null, null, null, null, 0, 0, Math.max(1, aSpecialValue)); @@ -977,6 +982,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { * Just a Recipe Map with Utility specifically for Fuels. */ public static class GT_Recipe_Map_Fuel extends GT_Recipe_Map { + private final Map<String, GT_Recipe> mRecipesByFluidInput = new HashMap<>(); public GT_Recipe_Map_Fuel(Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, String aLocalName, String aNEIName, String aNEIGUIPath, int aUsualInputCount, int aUsualOutputCount, int aMinimalInputItems, int aMinimalInputFluids, int aAmperage, String aNEISpecialValuePre, int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) { super(aRecipeList, aUnlocalizedName, aLocalName, aNEIName, aNEIGUIPath, aUsualInputCount, aUsualOutputCount, aMinimalInputItems, aMinimalInputFluids, aAmperage, aNEISpecialValuePre, aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, aNEIAllowed); } @@ -1000,6 +1006,24 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public GT_Recipe addFuel(ItemStack aInput, ItemStack aOutput, FluidStack aFluidInput, FluidStack aFluidOutput, int aChance, int aFuelValueInEU) { return addRecipe(true, new ItemStack[]{aInput}, new ItemStack[]{aOutput}, null, new int[]{aChance}, new FluidStack[]{aFluidInput}, new FluidStack[]{aFluidOutput}, 0, 0, aFuelValueInEU); } + + @Override + public GT_Recipe add(GT_Recipe aRecipe) { + aRecipe = super.add(aRecipe); + if (aRecipe.mInputs != null && GT_Utility.getNonnullElementCount(aRecipe.mInputs) == 1 && + (aRecipe.mFluidInputs == null || GT_Utility.getNonnullElementCount(aRecipe.mFluidInputs) == 0)) { + FluidStack tFluid = GT_Utility.getFluidForFilledItem(aRecipe.mInputs[0], true); + if (tFluid != null) { + tFluid.amount = 0; + mRecipesByFluidInput.put(tFluid.getUnlocalizedName(), aRecipe); + } + } + return aRecipe; + } + + public GT_Recipe findFuel(FluidStack aFluidInput) { + return mRecipesByFluidInput.get(aFluidInput.getUnlocalizedName()); + } } /** diff --git a/src/main/java/gregtech/api/util/GT_StructureUtility.java b/src/main/java/gregtech/api/util/GT_StructureUtility.java new file mode 100644 index 0000000000..a627da4fd6 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_StructureUtility.java @@ -0,0 +1,183 @@ +package gregtech.api.util; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.IStructureElementNoPlacement; +import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.interfaces.IHeatingCoil; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.BaseMetaPipeEntity; +import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame; +import gregtech.common.blocks.GT_Block_Casings5; +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import java.util.Arrays; +import java.util.function.BiConsumer; +import java.util.function.BiPredicate; +import java.util.function.Function; + +public class GT_StructureUtility { + private GT_StructureUtility() { + throw new AssertionError("Not instantiable"); + } + + public static <T> IStructureElementNoPlacement<T> ofHatchAdder(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, int aDots) { + return ofHatchAdder(aHatchAdder, aTextureIndex, StructureLibAPI.getBlockHint(), aDots - 1); + } + + public static <T> IStructureElement<T> ofFrame(Materials aFrameMaterial) { + if (aFrameMaterial == null) throw new IllegalArgumentException(); + return new IStructureElement<T>() { + + private IIcon[] mIcons; + + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tBase = world.getTileEntity(x, y, z); + if (tBase instanceof BaseMetaPipeEntity) { + BaseMetaPipeEntity tPipeBase = (BaseMetaPipeEntity) tBase; + if (tPipeBase.isInvalidTileEntity()) return false; + if (tPipeBase.getMetaTileEntity() instanceof GT_MetaPipeEntity_Frame) + return aFrameMaterial == ((GT_MetaPipeEntity_Frame) tPipeBase.getMetaTileEntity()).mMaterial; + } + return false; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + if (mIcons == null) { + mIcons = new IIcon[6]; + Arrays.fill(mIcons, aFrameMaterial.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon()); + } + StructureLibAPI.hintParticleTinted(world, x, y, z, mIcons, aFrameMaterial.mRGBa); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + ItemStack tFrameStack = GT_OreDictUnificator.get(OrePrefixes.frameGt, aFrameMaterial, 1); + if (tFrameStack.getItem() instanceof ItemBlock) { + ItemBlock tFrameStackItem = (ItemBlock) tFrameStack.getItem(); + return tFrameStackItem.placeBlockAt(tFrameStack, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrameStack)); + } + return false; + } + }; + } + + public static <T> IStructureElementNoPlacement<T> ofHatchAdder(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, Block aHintBlock, int aHintMeta) { + if (aHatchAdder == null || aHintBlock == null) { + throw new IllegalArgumentException(); + } + return new IStructureElementNoPlacement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + return tileEntity instanceof IGregTechTileEntity && aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, aHintMeta); + return true; + } + }; + } + + public static <T> IStructureElement<T> ofHatchAdderOptional(IGT_HatchAdder<T> aHatchAdder, int textureIndex, int dots, Block placeCasing, int placeCasingMeta) { + return ofHatchAdderOptional(aHatchAdder, textureIndex, StructureLibAPI.getBlockHint(), dots - 1, placeCasing, placeCasingMeta); + } + + public static <T> IStructureElement<T> ofHatchAdderOptional(IGT_HatchAdder<T> aHatchAdder, int aTextureIndex, Block aHintBlock, int hintMeta, Block placeCasing, int placeCasingMeta) { + if (aHatchAdder == null || aHintBlock == null) { + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + Block worldBlock = world.getBlock(x, y, z); + return (tileEntity instanceof IGregTechTileEntity && + aHatchAdder.apply(t, (IGregTechTileEntity) tileEntity, (short) aTextureIndex)) || + (worldBlock == placeCasing && worldBlock.getDamageValue(world, x, y, z) == placeCasingMeta); + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, aHintBlock, hintMeta); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + world.setBlock(x, y, z, placeCasing, placeCasingMeta, 2); + return true; + } + }; + } + + /** + * Assume all coils accepted. + * @see #ofCoil(BiPredicate, Function) + */ + public static <T> IStructureElement<T> ofCoil(BiConsumer<T, HeatingCoilLevel> aHeatingCoilSetter, Function<T, HeatingCoilLevel> aHeatingCoilGetter) { + return ofCoil((t, l) -> { + aHeatingCoilSetter.accept(t, l); + return true; + }, aHeatingCoilGetter); + } + + /** + * Heating coil structure element. + * @param aHeatingCoilSetter Notify the controller of this new coil. + * Got called exactly once per coil. + * Might be called less times if structure test fails. + * If the setter returns false then it assumes the coil is rejected. + * @param aHeatingCoilGetter Get the current heating level. Null means no coil recorded yet. + */ + public static <T> IStructureElement<T> ofCoil(BiPredicate<T, HeatingCoilLevel> aHeatingCoilSetter, Function<T, HeatingCoilLevel> aHeatingCoilGetter) { + if (aHeatingCoilSetter == null || aHeatingCoilGetter == null) { + throw new IllegalArgumentException(); + } + return new IStructureElement<T>() { + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + if (!(block instanceof IHeatingCoil)) + return false; + HeatingCoilLevel existingLevel = aHeatingCoilGetter.apply(t), + newLevel = ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)); + if (existingLevel == null || existingLevel == HeatingCoilLevel.None) { + return aHeatingCoilSetter.test(t, newLevel); + } else { + return newLevel == existingLevel; + } + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle(world, x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger)); + return true; + } + + private int getMeta(ItemStack trigger) { + // -4 to skip unimplemented tiers + return GT_Block_Casings5.getMetaFromCoilHeat(HeatingCoilLevel.getFromTier((byte) Math.min(HeatingCoilLevel.getMaxTier() - 4, Math.max(0, trigger.stackSize - 1)))); + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock(x, y, z, GregTech_API.sBlockCasings5, getMeta(trigger), 3); + } + }; + } +} diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 28faeae7e3..12ec2427ce 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -3,29 +3,20 @@ package gregtech.api.util; import cofh.api.transport.IItemDuct; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.gtnewhorizon.structurelib.alignment.IAlignment; +import com.gtnewhorizon.structurelib.alignment.IAlignmentProvider; import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.enchants.Enchantment_Radioactivity; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.ItemList; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.enums.SubTag; -import gregtech.api.enums.Textures; -import gregtech.api.enums.ToolDictNames; +import gregtech.api.enums.*; import gregtech.api.events.BlockScanningEvent; import gregtech.api.interfaces.IBlockContainer; import gregtech.api.interfaces.IDebugableBlock; import gregtech.api.interfaces.IProjectileItem; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.IBasicEnergyContainer; -import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.interfaces.tileentity.IUpgradableMachine; +import gregtech.api.interfaces.tileentity.*; import gregtech.api.items.GT_EnergyArmor_Item; import gregtech.api.items.GT_Generic_Item; import gregtech.api.items.GT_MetaGenerated_Tool; @@ -41,11 +32,7 @@ import ic2.api.recipe.RecipeOutput; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.EnumCreatureAttribute; +import net.minecraft.entity.*; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -81,16 +68,9 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidContainerItem; -import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.oredict.OreDictionary; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.lang.reflect.Constructor; @@ -99,31 +79,11 @@ import java.lang.reflect.Method; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Optional; -import java.util.UUID; import static gregtech.GT_Mod.GT_FML_LOGGER; -import static gregtech.api.enums.GT_Values.D1; -import static gregtech.api.enums.GT_Values.DW; -import static gregtech.api.enums.GT_Values.E; -import static gregtech.api.enums.GT_Values.GT; -import static gregtech.api.enums.GT_Values.L; -import static gregtech.api.enums.GT_Values.M; -import static gregtech.api.enums.GT_Values.NW; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.enums.GT_Values.W; +import static gregtech.api.enums.GT_Values.*; import static gregtech.common.GT_Proxy.GTPOLLUTION; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; @@ -1939,7 +1899,7 @@ public class GT_Utility { tList.add("----- X: " +EnumChatFormatting.AQUA+ aX +EnumChatFormatting.RESET+ " Y: " +EnumChatFormatting.AQUA+ aY +EnumChatFormatting.RESET+ " Z: " +EnumChatFormatting.AQUA+ aZ +EnumChatFormatting.RESET+ " D: " +EnumChatFormatting.AQUA+ aWorld.provider.dimensionId +EnumChatFormatting.RESET+ " -----"); try { - if (tTileEntity != null && tTileEntity instanceof IInventory) + if (tTileEntity instanceof IInventory) tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ ((IInventory) tTileEntity).getInventoryName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); else tList.add(trans("162","Name: ") +EnumChatFormatting.BLUE+ tBlock.getUnlocalizedName() +EnumChatFormatting.RESET+ trans("163"," MetaData: ") +EnumChatFormatting.AQUA+ aWorld.getBlockMetadata(aX, aY, aZ) +EnumChatFormatting.RESET); @@ -1979,6 +1939,17 @@ public class GT_Utility { if (D1) e.printStackTrace(GT_Log.err); } try { + if (tTileEntity instanceof IAlignmentProvider) { + IAlignment tAlignment = ((IAlignmentProvider) tTileEntity).getAlignment(); + if (tAlignment != null) { + rEUAmount += 100; + tList.add(trans("219", "Extended Facing: ") + EnumChatFormatting.GREEN + tAlignment.getExtendedFacing() + EnumChatFormatting.RESET); + } + } + } catch (Throwable e) { + if (D1) e.printStackTrace(GT_Log.err); + } + try { if (tTileEntity instanceof ic2.api.tile.IWrenchable) { rEUAmount += 100; tList.add(trans("171","Facing: ") +EnumChatFormatting.GREEN+ ((ic2.api.tile.IWrenchable) tTileEntity).getFacing() +EnumChatFormatting.RESET+ trans("172"," / Chance: ") +EnumChatFormatting.YELLOW+ (((ic2.api.tile.IWrenchable) tTileEntity).getWrenchDropRate() * 100) +EnumChatFormatting.RESET+ "%"); @@ -2871,4 +2842,8 @@ public class GT_Utility { dropItem.delayBeforeCanPickup = 0; } } + + public static long getNonnullElementCount(Object[] tArray) { + return Arrays.stream(tArray).filter(Objects::nonNull).count(); + } } diff --git a/src/main/java/gregtech/api/util/IGT_HatchAdder.java b/src/main/java/gregtech/api/util/IGT_HatchAdder.java new file mode 100644 index 0000000000..362fddaf1f --- /dev/null +++ b/src/main/java/gregtech/api/util/IGT_HatchAdder.java @@ -0,0 +1,15 @@ +package gregtech.api.util; + + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +public interface IGT_HatchAdder<T> { + /** + * Callback to add hatch, needs to check if hatch is valid (and add it) + * + * @param iGregTechTileEntity hatch + * @param aShort requested texture index, or null if not... + * @return managed to add hatch (structure still valid) + */ + boolean apply(T t, IGregTechTileEntity iGregTechTileEntity, Short aShort); +} diff --git a/src/main/java/gregtech/api/util/LightingHelper.java b/src/main/java/gregtech/api/util/LightingHelper.java index 598253b7d7..f131ef74a0 100644 --- a/src/main/java/gregtech/api/util/LightingHelper.java +++ b/src/main/java/gregtech/api/util/LightingHelper.java @@ -255,6 +255,7 @@ public class LightingHelper { } else { + if (hasBrightnessOverride) tessellator.setBrightness(brightnessOverride); tessellator.setColorOpaque_F(rgb[0] * lightness, rgb[1] * lightness, rgb[2] * lightness); } |