From ed3142bf0973fb49d0e2c7e60ba4b8463a72beeb Mon Sep 17 00:00:00 2001 From: LAGIdiot Date: Sat, 8 Apr 2023 03:33:39 +0200 Subject: [PATCH] Refactor detector covers (#1659) * Add base class for detector covers * Fix toggle not toggling * Add screwdriver handling to CoverDetectorBase * Call super on initialSyncData in CoverDetectorBase even though parent functions are empty * Update Fluid Detector Covers to extend CoverDetectorBase * Update Item Detector Covers to extend CoverDetectorBase * Update Energy Detector Covers to extend CoverDetectorBase - with added compatibility check for inverted NBT key * Update Activity Detector Covers to extend CoverDetectorBase * Rename detector cover for activity to follow naming system on rest of cover detectors * Extract function to compute redstone from basic detector covers * Remove unused lang keys for detector messages * Update Advanced Activity detector to use utility function for calculating redstone signal strength * Make toggle function in CoverDetectorBase private as it is not needed anywhere else * Clean up * Move redstone logic related functions to own util file * Add used network key for updating inverted on Detector covers to GregtechDataCodes --- .../api/capability/GregtechDataCodes.java | 3 + .../java/gregtech/api/util/GTUtility.java | 56 ++-------- .../java/gregtech/api/util/RedstoneUtil.java | 67 +++++++++++ .../common/covers/CoverBehaviors.java | 4 +- .../detector/CoverActivityDetector.java | 104 ------------------ .../detector/CoverDetectorActivity.java | 42 +++++++ ...ava => CoverDetectorActivityAdvanced.java} | 35 ++---- .../covers/detector/CoverDetectorBase.java | 93 ++++++++++++++++ .../covers/detector/CoverDetectorEnergy.java | 78 +------------ .../detector/CoverDetectorEnergyAdvanced.java | 57 +++++----- .../covers/detector/CoverDetectorFluid.java | 86 +-------------- .../detector/CoverDetectorFluidAdvanced.java | 18 +-- .../covers/detector/CoverDetectorItem.java | 86 +-------------- .../detector/CoverDetectorItemAdvanced.java | 19 ++-- .../resources/assets/gregtech/lang/en_us.lang | 16 +-- .../resources/assets/gregtech/lang/ja_jp.lang | 16 +-- .../resources/assets/gregtech/lang/ru_ru.lang | 10 -- .../resources/assets/gregtech/lang/zh_cn.lang | 15 --- 18 files changed, 293 insertions(+), 512 deletions(-) create mode 100644 src/main/java/gregtech/api/util/RedstoneUtil.java delete mode 100644 src/main/java/gregtech/common/covers/detector/CoverActivityDetector.java create mode 100644 src/main/java/gregtech/common/covers/detector/CoverDetectorActivity.java rename src/main/java/gregtech/common/covers/detector/{CoverActivityDetectorAdvanced.java => CoverDetectorActivityAdvanced.java} (50%) create mode 100644 src/main/java/gregtech/common/covers/detector/CoverDetectorBase.java diff --git a/src/main/java/gregtech/api/capability/GregtechDataCodes.java b/src/main/java/gregtech/api/capability/GregtechDataCodes.java index 03cb6489668..3c22a144c7a 100644 --- a/src/main/java/gregtech/api/capability/GregtechDataCodes.java +++ b/src/main/java/gregtech/api/capability/GregtechDataCodes.java @@ -127,6 +127,9 @@ public class GregtechDataCodes { // Quantum Chest public static final int UPDATE_ITEM_COUNT = 14; + // Detector Covers + public static final int UPDATE_INVERTED = 100; + // NBT Keys // From MetaTileEntityHolder diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index 744c2fd7423..cb41fd6fa2a 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -92,7 +92,7 @@ public class GTUtility { private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(); private static final DecimalFormat TWO_PLACES_FORMAT = new DecimalFormat("#.##"); - private static TreeMap romanNumeralConversions = new TreeMap<>(); + private static final TreeMap romanNumeralConversions = new TreeMap<>(); private static final NavigableMap tierByVoltage = new TreeMap<>(); @@ -1084,6 +1084,7 @@ public static boolean isBlockSnowLayer(@Nonnull IBlockState blockState) { /** * Attempt to break a (single) snow layer at the given BlockPos. + * * @return true if the passed IBlockState was a snow layer */ public static boolean tryBreakSnowLayer(World world, BlockPos pos, @Nonnull IBlockState blockState, boolean playSound) { @@ -1109,11 +1110,12 @@ public static Pattern getForwardNewLineRegex() { /** * Tries to parse a string into an int, returning a default value if it fails. - * @param val string to parse + * + * @param val string to parse * @param defaultValue default value to return * @return returns an int from the parsed string, otherwise the default value */ - public static int tryParseInt(String val, int defaultValue){ + public static int tryParseInt(String val, int defaultValue) { try { return Integer.parseInt(val); } catch (NumberFormatException e) { @@ -1124,11 +1126,12 @@ public static int tryParseInt(String val, int defaultValue){ /** * Tries to parse a string into a long, returning a default value if it fails. - * @param val string to parse + * + * @param val string to parse * @param defaultValue default value to return * @return returns a long from the parsed string, otherwise the default value */ - public static long tryParseLong(String val, long defaultValue){ + public static long tryParseLong(String val, long defaultValue) { try { return Long.parseLong(val); } catch (NumberFormatException e) { @@ -1137,48 +1140,6 @@ public static long tryParseLong(String val, long defaultValue){ return defaultValue; } - /** - * Compares a value against a min and max, with an option to invert the logic - * @param value value to be compared - * @param maxValue the max that the value can be - * @param minValue the min that the value can be - * @param isInverted whether to invert the logic of this method - * @return an int from 0 (value <= min) to 15 (value >= max) normally, with a ratio when the value is between min and max - */ - public static int computeRedstoneBetweenValues(int value, float maxValue, float minValue, boolean isInverted) { - if (value >= maxValue) { - return isInverted ? 0 : 15; // value above maxValue should normally be 15, otherwise 0 - } else if (value <= minValue) { - return isInverted ? 15 : 0; // value below minValue should normally be 0, otherwise 15 - } - - float ratio; - if (!isInverted) { - ratio = 15 * (value - minValue) / (maxValue - minValue); // value closer to max results in higher output - } else { - ratio = 15 * (maxValue - value) / (maxValue - minValue); // value closer to min results in higher output - } - - return Math.round(ratio); - } - - /** - * Compares a value against a min and max, with an option to invert the logic. Has latching functionality. - * @param value value to be compared - * @param maxValue the max that the value can be - * @param minValue the min that the value can be - * @param output the output value the function modifies - * @return returns the modified output value - */ - public static int computeLatchedRedstoneBetweenValues(float value, float maxValue, float minValue, boolean isInverted, int output) { - if (value >= maxValue) { - output = !isInverted ? 0 : 15; // value above maxValue should normally be 0, otherwise 15 - } else if (value <= minValue) { - output = !isInverted ? 15 : 0; // value below minValue should normally be 15, otherwise 0 - } - return output; - } - /** * @param fluidHandler the handler to drain from * @param doDrain if the handler should be actually drained @@ -1243,7 +1204,6 @@ public static Set getAllSubItems(@Nonnull ItemStack stack) { * @param height The height of the box * @param pointX The X value of the point to check * @param pointY The Y value of the point to check - * * @return True if the provided (X,Y) point is within the described box, else false */ public static boolean isPointWithinRange(int initialX, int initialY, int width, int height, int pointX, int pointY) { diff --git a/src/main/java/gregtech/api/util/RedstoneUtil.java b/src/main/java/gregtech/api/util/RedstoneUtil.java new file mode 100644 index 00000000000..3341f89af61 --- /dev/null +++ b/src/main/java/gregtech/api/util/RedstoneUtil.java @@ -0,0 +1,67 @@ +package gregtech.api.util; + +public class RedstoneUtil { + + /** + * Compares a value against a min and max, with an option to invert the logic + * + * @param value value to be compared + * @param maxValue the max that the value can be + * @param minValue the min that the value can be + * @param isInverted whether to invert the logic of this method + * @return an int from 0 (value <= min) to 15 (value >= max) normally, with a ratio when the value is between min and max + */ + public static int computeRedstoneBetweenValues(int value, float maxValue, float minValue, boolean isInverted) { + if (value >= maxValue) { + return isInverted ? 0 : 15; // value above maxValue should normally be 15, otherwise 0 + } else if (value <= minValue) { + return isInverted ? 15 : 0; // value below minValue should normally be 0, otherwise 15 + } + + float ratio; + if (!isInverted) { + ratio = 15 * (value - minValue) / (maxValue - minValue); // value closer to max results in higher output + } else { + ratio = 15 * (maxValue - value) / (maxValue - minValue); // value closer to min results in higher output + } + + return Math.round(ratio); + } + + /** + * Compares a value against a min and max, with an option to invert the logic. Has latching functionality. + * + * @param value value to be compared + * @param maxValue the max that the value can be + * @param minValue the min that the value can be + * @param output the output value the function modifies + * @return returns the modified output value + */ + public static int computeLatchedRedstoneBetweenValues(float value, float maxValue, float minValue, boolean isInverted, int output) { + if (value >= maxValue) { + output = !isInverted ? 0 : 15; // value above maxValue should normally be 0, otherwise 15 + } else if (value <= minValue) { + output = !isInverted ? 15 : 0; // value below minValue should normally be 15, otherwise 0 + } + return output; + } + + /** + * Compares a current against max, with an option to invert the logic. + * + * @param current value to be compared + * @param max the max that value can be + * @param isInverted whether to invert the logic of this method + * @return value 0 to 15 + * @throws ArithmeticException when max is 0 + */ + public static int computeRedstoneValue(long current, long max, boolean isInverted) throws ArithmeticException { + int outputAmount = (int) (15 * current / max); + + if (isInverted) { + outputAmount = 15 - outputAmount; + } + + return outputAmount; + } +} diff --git a/src/main/java/gregtech/common/covers/CoverBehaviors.java b/src/main/java/gregtech/common/covers/CoverBehaviors.java index b8f3ffd5c3e..2953b8cbcb8 100644 --- a/src/main/java/gregtech/common/covers/CoverBehaviors.java +++ b/src/main/java/gregtech/common/covers/CoverBehaviors.java @@ -74,8 +74,8 @@ public static void init() { registerBehavior(new ResourceLocation(GTValues.MODID, "fluid_detector_advanced"), MetaItems.COVER_FLUID_DETECTOR_ADVANCED, CoverDetectorFluidAdvanced::new); registerBehavior(new ResourceLocation(GTValues.MODID, "item_detector"), MetaItems.COVER_ITEM_DETECTOR, CoverDetectorItem::new); registerBehavior(new ResourceLocation(GTValues.MODID, "item_detector_advanced"), MetaItems.COVER_ITEM_DETECTOR_ADVANCED, CoverDetectorItemAdvanced::new); - registerBehavior(new ResourceLocation(GTValues.MODID, "activity_detector"), MetaItems.COVER_ACTIVITY_DETECTOR, CoverActivityDetector::new); - registerBehavior(new ResourceLocation(GTValues.MODID, "activity_detector_advanced"), MetaItems.COVER_ACTIVITY_DETECTOR_ADVANCED, CoverActivityDetectorAdvanced::new); + registerBehavior(new ResourceLocation(GTValues.MODID, "activity_detector"), MetaItems.COVER_ACTIVITY_DETECTOR, CoverDetectorActivity::new); + registerBehavior(new ResourceLocation(GTValues.MODID, "activity_detector_advanced"), MetaItems.COVER_ACTIVITY_DETECTOR_ADVANCED, CoverDetectorActivityAdvanced::new); registerBehavior(new ResourceLocation(GTValues.MODID, "crafting_table"), MetaItems.COVER_CRAFTING, CoverCraftingTable::new); registerBehavior(new ResourceLocation(GTValues.MODID, "infinite_water"), MetaItems.COVER_INFINITE_WATER, CoverInfiniteWater::new); registerBehavior(new ResourceLocation(GTValues.MODID, "ender_fluid_link"), MetaItems.COVER_ENDER_FLUID_LINK, CoverEnderFluidLink::new); diff --git a/src/main/java/gregtech/common/covers/detector/CoverActivityDetector.java b/src/main/java/gregtech/common/covers/detector/CoverActivityDetector.java deleted file mode 100644 index a7e8bae9744..00000000000 --- a/src/main/java/gregtech/common/covers/detector/CoverActivityDetector.java +++ /dev/null @@ -1,104 +0,0 @@ -package gregtech.common.covers.detector; - -import codechicken.lib.raytracer.CuboidRayTraceResult; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.pipeline.IVertexOperation; -import codechicken.lib.vec.Cuboid6; -import codechicken.lib.vec.Matrix4; -import gregtech.api.capability.GregtechTileCapabilities; -import gregtech.api.capability.IWorkable; -import gregtech.api.cover.CoverBehavior; -import gregtech.api.cover.ICoverable; -import gregtech.client.renderer.texture.Textures; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.text.TextComponentTranslation; - -public class CoverActivityDetector extends CoverBehavior implements ITickable { - - protected boolean isInverted; - - public CoverActivityDetector(ICoverable coverHolder, EnumFacing attachedSide) { - super(coverHolder, attachedSide); - this.isInverted = false; - } - - @Override - public boolean canAttach() { - return coverHolder.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null) != null; - } - - @Override - public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, Cuboid6 plateBox, BlockRenderLayer layer) { - Textures.DETECTOR_ACTIVITY.renderSided(attachedSide, plateBox, renderState, pipeline, translation); - } - - @Override - public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { - if (this.coverHolder.getWorld().isRemote) { - return EnumActionResult.SUCCESS; - } - - if (this.isInverted) { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.activity_detector.message_activity_normal")); - } else { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.activity_detector.message_activity_inverted")); - } - return EnumActionResult.SUCCESS; - } - - protected void setInverted() { - this.isInverted = !this.isInverted; - if (!this.coverHolder.getWorld().isRemote) { - this.coverHolder.writeCoverData(this, 100, b -> b.writeBoolean(this.isInverted)); - this.coverHolder.notifyBlockUpdate(); - this.coverHolder.markDirty(); - } - } - - @Override - public void update() { - if (this.coverHolder.getOffsetTimer() % 20 != 0) - return; - - IWorkable workable = coverHolder.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null); - if (workable == null) - return; - - if (isInverted) setRedstoneSignalOutput(workable.isActive() && workable.isWorkingEnabled() ? 0 : 15); - else setRedstoneSignalOutput(workable.isActive() && workable.isWorkingEnabled() ? 15 : 0); - } - - @Override - public boolean canConnectRedstone() { - return true; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { - super.writeToNBT(tagCompound); - tagCompound.setBoolean("isInverted", this.isInverted); - - return tagCompound; - } - - @Override - public void readFromNBT(NBTTagCompound tagCompound) { - super.readFromNBT(tagCompound); - this.isInverted = tagCompound.getBoolean("isInverted"); - } - - @Override - public void writeInitialSyncData(PacketBuffer packetBuffer) { - packetBuffer.writeBoolean(this.isInverted); - } - - @Override - public void readInitialSyncData(PacketBuffer packetBuffer) { - this.isInverted = packetBuffer.readBoolean(); - } -} diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorActivity.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorActivity.java new file mode 100644 index 00000000000..89700897800 --- /dev/null +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorActivity.java @@ -0,0 +1,42 @@ +package gregtech.common.covers.detector; + +import codechicken.lib.render.CCRenderState; +import codechicken.lib.render.pipeline.IVertexOperation; +import codechicken.lib.vec.Cuboid6; +import codechicken.lib.vec.Matrix4; +import gregtech.api.capability.GregtechTileCapabilities; +import gregtech.api.capability.IWorkable; +import gregtech.api.cover.ICoverable; +import gregtech.client.renderer.texture.Textures; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; + +public class CoverDetectorActivity extends CoverDetectorBase implements ITickable { + public CoverDetectorActivity(ICoverable coverHolder, EnumFacing attachedSide) { + super(coverHolder, attachedSide); + } + + @Override + public boolean canAttach() { + return coverHolder.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null) != null; + } + + @Override + public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline, Cuboid6 plateBox, BlockRenderLayer layer) { + Textures.DETECTOR_ACTIVITY.renderSided(attachedSide, plateBox, renderState, pipeline, translation); + } + + @Override + public void update() { + if (this.coverHolder.getOffsetTimer() % 20 != 0) + return; + + IWorkable workable = coverHolder.getCapability(GregtechTileCapabilities.CAPABILITY_WORKABLE, null); + if (workable == null) + return; + + if (isInverted()) setRedstoneSignalOutput(workable.isActive() && workable.isWorkingEnabled() ? 0 : 15); + else setRedstoneSignalOutput(workable.isActive() && workable.isWorkingEnabled() ? 15 : 0); + } +} diff --git a/src/main/java/gregtech/common/covers/detector/CoverActivityDetectorAdvanced.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorActivityAdvanced.java similarity index 50% rename from src/main/java/gregtech/common/covers/detector/CoverActivityDetectorAdvanced.java rename to src/main/java/gregtech/common/covers/detector/CoverDetectorActivityAdvanced.java index 357696b17ee..67812ead88e 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverActivityDetectorAdvanced.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorActivityAdvanced.java @@ -1,6 +1,5 @@ package gregtech.common.covers.detector; -import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; @@ -8,17 +7,13 @@ import gregtech.api.capability.GregtechTileCapabilities; import gregtech.api.capability.IWorkable; import gregtech.api.cover.ICoverable; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.BlockRenderLayer; -import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.text.TextComponentTranslation; -public class CoverActivityDetectorAdvanced extends CoverActivityDetector { - - public CoverActivityDetectorAdvanced(ICoverable coverHolder, EnumFacing attachedSide) { +public class CoverDetectorActivityAdvanced extends CoverDetectorActivity { + public CoverDetectorActivityAdvanced(ICoverable coverHolder, EnumFacing attachedSide) { super(coverHolder, attachedSide); } @@ -27,22 +22,6 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO Textures.DETECTOR_ACTIVITY_ADVANCED.renderSided(attachedSide, plateBox, renderState, pipeline, translation); } - @Override - public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { - if (this.coverHolder.getWorld().isRemote) { - return EnumActionResult.SUCCESS; - } - - if (this.isInverted) { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.activity_detector_advanced.message_activity_normal")); - } else { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.activity_detector_advanced.message_activity_inverted")); - } - return EnumActionResult.SUCCESS; - } - @Override public void update() { if (this.coverHolder.getOffsetTimer() % 20 != 0) @@ -52,12 +31,14 @@ public void update() { if (workable == null) return; - int outputAmount = (int) (15.0 * workable.getProgress() / workable.getMaxProgress()); + if (workable.getMaxProgress() == 0) + return; + + int outputAmount = RedstoneUtil.computeRedstoneValue(workable.getProgress(), workable.getMaxProgress(), isInverted()); + //nonstandard logic for handling off state if (!workable.isWorkingEnabled()) outputAmount = 0; - else if (this.isInverted) - outputAmount = 15 - outputAmount; setRedstoneSignalOutput(outputAmount); } diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorBase.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorBase.java new file mode 100644 index 00000000000..0601e49d978 --- /dev/null +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorBase.java @@ -0,0 +1,93 @@ +package gregtech.common.covers.detector; + +import codechicken.lib.raytracer.CuboidRayTraceResult; +import gregtech.api.cover.CoverBehavior; +import gregtech.api.cover.ICoverable; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.text.TextComponentTranslation; + +import static gregtech.api.capability.GregtechDataCodes.UPDATE_INVERTED; + +public abstract class CoverDetectorBase extends CoverBehavior { + protected static final String NBT_KEY_IS_INVERTED = "isInverted"; + + private boolean isInverted; + + public CoverDetectorBase(ICoverable coverHolder, EnumFacing attachedSide) { + super(coverHolder, attachedSide); + isInverted = false; + } + + protected boolean isInverted() { + return this.isInverted; + } + + protected void setInverted(boolean isInverted) { + this.isInverted = isInverted; + } + + private void toggleInvertedWithNotification() { + setInverted(!isInverted()); + + if (!this.coverHolder.getWorld().isRemote) { + this.coverHolder.writeCoverData(this, UPDATE_INVERTED, b -> b.writeBoolean(isInverted())); + this.coverHolder.notifyBlockUpdate(); + this.coverHolder.markDirty(); + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { + super.writeToNBT(tagCompound); + tagCompound.setBoolean(NBT_KEY_IS_INVERTED, isInverted()); + + return tagCompound; + } + + @Override + public void readFromNBT(NBTTagCompound tagCompound) { + super.readFromNBT(tagCompound); + + if (tagCompound.hasKey(NBT_KEY_IS_INVERTED)) { //compatibility check + setInverted(tagCompound.getBoolean(NBT_KEY_IS_INVERTED)); + } + } + + @Override + public void writeInitialSyncData(PacketBuffer packetBuffer) { + super.writeInitialSyncData(packetBuffer); + packetBuffer.writeBoolean(isInverted()); + } + + @Override + public void readInitialSyncData(PacketBuffer packetBuffer) { + super.readInitialSyncData(packetBuffer); + setInverted(packetBuffer.readBoolean()); + } + + @Override + public boolean canConnectRedstone() { + return true; + } + + @Override + public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { + if (this.coverHolder.getWorld().isRemote) { + return EnumActionResult.SUCCESS; + } + + String translationKey = isInverted() + ? "gregtech.cover.detector_base.message_inverted_state" + : "gregtech.cover.detector_base.message_normal_state"; + playerIn.sendMessage(new TextComponentTranslation(translationKey)); + + toggleInvertedWithNotification(); + + return EnumActionResult.SUCCESS; + } +} diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergy.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergy.java index 9729553415a..4ca57ecb0ac 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergy.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergy.java @@ -1,28 +1,21 @@ package gregtech.common.covers.detector; -import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; import gregtech.api.capability.GregtechCapabilities; import gregtech.api.capability.IEnergyContainer; -import gregtech.api.cover.CoverBehavior; import gregtech.api.cover.ICoverable; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.text.TextComponentTranslation; - -public class CoverDetectorEnergy extends CoverBehavior implements ITickable { - - protected boolean isInverted; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; +public class CoverDetectorEnergy extends CoverDetectorBase implements ITickable { public CoverDetectorEnergy(ICoverable coverHolder, EnumFacing attachedSide) { super(coverHolder, attachedSide); - this.isInverted = false; } @Override @@ -35,31 +28,6 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO Textures.DETECTOR_ENERGY.renderSided(attachedSide, plateBox, renderState, pipeline, translation); } - @Override - public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { - if (this.coverHolder.getWorld().isRemote) { - return EnumActionResult.SUCCESS; - } - - if (this.isInverted) { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.energy_detector.message_electricity_storage_normal")); - } else { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.energy_detector.message_electricity_storage_inverted")); - } - return EnumActionResult.SUCCESS; - } - - private void setInverted() { - this.isInverted = !this.isInverted; - if (!this.coverHolder.getWorld().isRemote) { - this.coverHolder.writeCoverData(this, 100, b -> b.writeBoolean(this.isInverted)); - this.coverHolder.notifyBlockUpdate(); - this.coverHolder.markDirty(); - } - } - @Override public void update() { if (this.coverHolder.getOffsetTimer() % 20 != 0) @@ -73,41 +41,7 @@ public void update() { if (energyCapacity == 0) return; - int outputAmount = (int) (15.0 * storedEnergy / energyCapacity); - - if (this.isInverted) - outputAmount = 15 - outputAmount; - - setRedstoneSignalOutput(outputAmount); + setRedstoneSignalOutput(RedstoneUtil.computeRedstoneValue(storedEnergy, energyCapacity, isInverted())); } } - - @Override - public boolean canConnectRedstone() { - return true; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { - super.writeToNBT(tagCompound); - tagCompound.setBoolean("isInverted", this.isInverted); - - return tagCompound; - } - - @Override - public void readFromNBT(NBTTagCompound tagCompound) { - super.readFromNBT(tagCompound); - this.isInverted = tagCompound.getBoolean("isInverted"); - } - - @Override - public void writeInitialSyncData(PacketBuffer packetBuffer) { - packetBuffer.writeBoolean(this.isInverted); - } - - @Override - public void readInitialSyncData(PacketBuffer packetBuffer) { - this.isInverted = packetBuffer.readBoolean(); - } } diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergyAdvanced.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergyAdvanced.java index f366a33715a..f3e55e46906 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergyAdvanced.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorEnergyAdvanced.java @@ -14,12 +14,16 @@ import gregtech.api.gui.Widget; import gregtech.api.gui.widgets.*; import gregtech.api.util.GTUtility; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import javax.annotation.Nonnull; @@ -35,7 +39,7 @@ public class CoverDetectorEnergyAdvanced extends CoverDetectorEnergy implements private boolean usePercent; private WidgetGroup widgetsToUpdate; - public CoverDetectorEnergyAdvanced (ICoverable coverHolder, EnumFacing attachedSide) { + public CoverDetectorEnergyAdvanced(ICoverable coverHolder, EnumFacing attachedSide) { super(coverHolder, attachedSide); this.minValue = DEFAULT_MIN_EU; this.maxValue = DEFAULT_MAX_EU; @@ -49,7 +53,7 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO } @Override - public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult){ + public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { if (!this.coverHolder.getWorld().isRemote) { openUI((EntityPlayerMP) playerIn); } @@ -65,15 +69,13 @@ public void update() { if (usePercent) { if (energyContainer.getEnergyCapacity() > 0) { float ratio = (float) energyContainer.getEnergyStored() / energyContainer.getEnergyCapacity(); - this.outputAmount = GTUtility.computeLatchedRedstoneBetweenValues(ratio * 100, this.maxValue, this.minValue, this.isInverted, this.outputAmount); - // compareValue((float) energyContainer.getEnergyStored() / energyContainer.getEnergyCapacity() * 100, maxValue, minValue); + this.outputAmount = RedstoneUtil.computeLatchedRedstoneBetweenValues(ratio * 100, this.maxValue, this.minValue, isInverted(), this.outputAmount); } else { - this.outputAmount = isInverted ? 0 : 15; + this.outputAmount = isInverted() ? 0 : 15; } } else { - this.outputAmount = GTUtility.computeLatchedRedstoneBetweenValues(energyContainer.getEnergyStored(), - this.maxValue, this.minValue, this.isInverted, this.outputAmount); - // compareValue(energyContainer.getEnergyStored(), maxValue, minValue); + this.outputAmount = RedstoneUtil.computeLatchedRedstoneBetweenValues(energyContainer.getEnergyStored(), + this.maxValue, this.minValue, isInverted(), this.outputAmount); } } setRedstoneSignalOutput(outputAmount); @@ -81,7 +83,6 @@ public void update() { @Override public ModularUI createUI(EntityPlayer player) { - WidgetGroup group = new WidgetGroup(); group.addWidget(new LabelWidget(10, 8, "cover.advanced_energy_detector.label")); @@ -139,35 +140,28 @@ private String getMaxValue() { return String.valueOf(maxValue); } - private void setMinValue(String val){ + private void setMinValue(String val) { long parsedValue = GTUtility.tryParseLong(val, usePercent ? DEFAULT_MIN_PERCENT : DEFAULT_MIN_EU); this.minValue = Math.min(this.maxValue - 1, Math.max(0, parsedValue)); } - private void setMaxValue(String val){ + private void setMaxValue(String val) { long parsedValue = GTUtility.tryParseLong(val, usePercent ? DEFAULT_MAX_PERCENT : DEFAULT_MAX_EU); long maxUpperLimit = usePercent ? 100 : Long.MAX_VALUE; this.maxValue = Math.max(this.minValue + 1, Math.min(parsedValue, maxUpperLimit)); } - private boolean isInverted(){ - return this.isInverted; - } - private void setInverted(boolean b){ - this.isInverted = b; - } - - private boolean isUsePercent(){ + private boolean isUsePercent() { return this.usePercent; } - private void setUsePercent(boolean b){ - this.usePercent = b; + private void setUsePercent(boolean b) { + this.usePercent = b; - if (this.usePercent){ // using percent + if (this.usePercent) { // using percent this.minValue = DEFAULT_MIN_PERCENT; this.maxValue = DEFAULT_MAX_PERCENT; } else { // using discrete EU @@ -186,7 +180,7 @@ private void updateSyncedWidgets() { } } - private String getPostFix(){ + private String getPostFix() { return usePercent ? " %" : " EU"; } @@ -201,8 +195,8 @@ public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound tagCompound) { tagCompound.setLong("maxEU", this.maxValue); tagCompound.setLong("minEU", this.minValue); tagCompound.setInteger("outputAmount", this.outputAmount); - tagCompound.setBoolean("inverted", this.isInverted); tagCompound.setBoolean("usePercent", this.usePercent); + return tagCompound; } @@ -212,8 +206,17 @@ public void readFromNBT(@Nonnull NBTTagCompound tagCompound) { this.minValue = tagCompound.getLong("minEU"); this.maxValue = tagCompound.getLong("maxEU"); this.outputAmount = tagCompound.getInteger("outputAmount"); - this.isInverted = tagCompound.getBoolean("inverted"); this.usePercent = tagCompound.getBoolean("usePercent"); + + readDeprecatedInvertedKeyFromNBT(tagCompound); + } + + //inverted here was saved using different key, now it is normalized but construction is for compatibility + private void readDeprecatedInvertedKeyFromNBT(@Nonnull NBTTagCompound tagCompound) { + String oldInvertedKey = "inverted"; + if (!tagCompound.hasKey(NBT_KEY_IS_INVERTED) && tagCompound.hasKey(oldInvertedKey)) { + setInverted(tagCompound.getBoolean(oldInvertedKey)); + } } @Override @@ -222,7 +225,6 @@ public void writeInitialSyncData(@Nonnull PacketBuffer packetBuffer) { packetBuffer.writeLong(this.minValue); packetBuffer.writeLong(this.maxValue); packetBuffer.writeInt(this.outputAmount); - packetBuffer.writeBoolean(this.isInverted); packetBuffer.writeBoolean(this.usePercent); } @@ -232,7 +234,6 @@ public void readInitialSyncData(@Nonnull PacketBuffer packetBuffer) { this.minValue = packetBuffer.readLong(); this.maxValue = packetBuffer.readLong(); this.outputAmount = packetBuffer.readInt(); - this.isInverted = packetBuffer.readBoolean(); this.usePercent = packetBuffer.readBoolean(); } } diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorFluid.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorFluid.java index 4553035fa83..d9d5f13db6c 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverDetectorFluid.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorFluid.java @@ -1,30 +1,23 @@ package gregtech.common.covers.detector; -import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; -import gregtech.api.cover.CoverBehavior; import gregtech.api.cover.ICoverable; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; -public class CoverDetectorFluid extends CoverBehavior implements ITickable { - - private boolean isInverted; - +public class CoverDetectorFluid extends CoverDetectorBase implements ITickable { public CoverDetectorFluid(ICoverable coverHolder, EnumFacing attachedSide) { super(coverHolder, attachedSide); - this.isInverted = false; } @Override @@ -37,39 +30,6 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO Textures.DETECTOR_FLUID.renderSided(attachedSide, plateBox, renderState, pipeline, translation); } - @Override - public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { - if (this.coverHolder.getWorld().isRemote) { - return EnumActionResult.SUCCESS; - } - - if (this.isInverted) { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.fluid_detector.message_fluid_storage_normal")); - } else { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.fluid_detector.message_fluid_storage_inverted")); - } - return EnumActionResult.SUCCESS; - } - - protected boolean isInverted(){ - return this.isInverted; - } - - protected void setInverted(boolean b){ - this.isInverted = b; - } - - private void setInverted() { - this.isInverted = !this.isInverted; - if (!this.coverHolder.getWorld().isRemote) { - this.coverHolder.writeCoverData(this, 100, b -> b.writeBoolean(this.isInverted)); - this.coverHolder.notifyBlockUpdate(); - this.coverHolder.markDirty(); - } - } - @Override public void update() { if (this.coverHolder.getOffsetTimer() % 20 != 0) @@ -93,40 +53,6 @@ public void update() { if (fluidCapacity == 0) return; - int outputAmount = (int) (15.0 * storedFluid / fluidCapacity); - - if (this.isInverted) - outputAmount = 15 - outputAmount; - - setRedstoneSignalOutput(outputAmount); - } - - @Override - public boolean canConnectRedstone() { - return true; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { - super.writeToNBT(tagCompound); - tagCompound.setBoolean("isInverted", this.isInverted); - - return tagCompound; - } - - @Override - public void readFromNBT(NBTTagCompound tagCompound) { - super.readFromNBT(tagCompound); - this.isInverted = tagCompound.getBoolean("isInverted"); - } - - @Override - public void writeInitialSyncData(PacketBuffer packetBuffer) { - packetBuffer.writeBoolean(this.isInverted); - } - - @Override - public void readInitialSyncData(PacketBuffer packetBuffer) { - this.isInverted = packetBuffer.readBoolean(); + setRedstoneSignalOutput(RedstoneUtil.computeRedstoneValue(storedFluid, fluidCapacity, isInverted())); } } diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorFluidAdvanced.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorFluidAdvanced.java index 2df7cf3de17..77e15e90408 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverDetectorFluidAdvanced.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorFluidAdvanced.java @@ -5,29 +5,28 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; -import gregtech.api.cover.CoverBehavior; import gregtech.api.cover.CoverWithUI; import gregtech.api.cover.ICoverable; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.widgets.*; -import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; import gregtech.common.covers.filter.FluidFilterContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; -import java.util.regex.Pattern; - public class CoverDetectorFluidAdvanced extends CoverDetectorFluid implements CoverWithUI { private static final int PADDING = 3; @@ -94,7 +93,7 @@ public ModularUI createUI(EntityPlayer player) { this.fluidFilter.initUI(5 + 4 * (SIZE + PADDING), group::addWidget); - return ModularUI.builder(GuiTextures.BACKGROUND, 176, 164 + 82) + return ModularUI.builder(GuiTextures.BACKGROUND, 176, 164 + 82) .widget(group) .bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 164) .build(this, player); @@ -137,8 +136,9 @@ public void update() { storedFluid += contents.amount; } - setRedstoneSignalOutput(GTUtility.computeRedstoneBetweenValues(storedFluid, max, min, this.isInverted())); + setRedstoneSignalOutput(RedstoneUtil.computeRedstoneBetweenValues(storedFluid, max, min, this.isInverted())); } + @Override public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); @@ -159,12 +159,14 @@ public void readFromNBT(NBTTagCompound tagCompound) { @Override public void writeInitialSyncData(PacketBuffer packetBuffer) { + super.writeInitialSyncData(packetBuffer); packetBuffer.writeInt(this.min); packetBuffer.writeInt(this.max); } @Override public void readInitialSyncData(PacketBuffer packetBuffer) { + super.readInitialSyncData(packetBuffer); this.min = packetBuffer.readInt(); this.max = packetBuffer.readInt(); } diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorItem.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorItem.java index abd63afbc3d..5fc1edd4997 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverDetectorItem.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorItem.java @@ -1,28 +1,21 @@ package gregtech.common.covers.detector; -import codechicken.lib.raytracer.CuboidRayTraceResult; import codechicken.lib.render.CCRenderState; import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; -import gregtech.api.cover.CoverBehavior; import gregtech.api.cover.ICoverable; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; -public class CoverDetectorItem extends CoverBehavior implements ITickable { - - private boolean isInverted; - +public class CoverDetectorItem extends CoverDetectorBase implements ITickable { public CoverDetectorItem(ICoverable coverHolder, EnumFacing attachedSide) { super(coverHolder, attachedSide); - this.isInverted = false; } @Override @@ -35,39 +28,6 @@ public void renderCover(CCRenderState renderState, Matrix4 translation, IVertexO Textures.DETECTOR_ITEM.renderSided(attachedSide, plateBox, renderState, pipeline, translation); } - @Override - public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) { - if (this.coverHolder.getWorld().isRemote) { - return EnumActionResult.SUCCESS; - } - - if (this.isInverted) { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.item_detector.message_item_storage_normal")); - } else { - this.setInverted(); - playerIn.sendMessage(new TextComponentTranslation("gregtech.cover.item_detector.message_item_storage_inverted")); - } - return EnumActionResult.SUCCESS; - } - - protected boolean isInverted(){ - return this.isInverted; - } - - protected void setInverted(boolean b){ - this.isInverted = b; - } - - private void setInverted() { - this.isInverted = !this.isInverted; - if (!this.coverHolder.getWorld().isRemote) { - this.coverHolder.writeCoverData(this, 100, b -> b.writeBoolean(this.isInverted)); - this.coverHolder.notifyBlockUpdate(); - this.coverHolder.markDirty(); - } - } - @Override public void update() { if (this.coverHolder.getOffsetTimer() % 20 != 0) @@ -87,40 +47,6 @@ public void update() { storedItems += itemHandler.getStackInSlot(i).getCount(); } - int outputAmount = (int) (15.0 * storedItems / itemCapacity); - - if (this.isInverted) - outputAmount = 15 - outputAmount; - - setRedstoneSignalOutput(outputAmount); - } - - @Override - public boolean canConnectRedstone() { - return true; - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { - super.writeToNBT(tagCompound); - tagCompound.setBoolean("isInverted", this.isInverted); - - return tagCompound; - } - - @Override - public void readFromNBT(NBTTagCompound tagCompound) { - super.readFromNBT(tagCompound); - this.isInverted = tagCompound.getBoolean("isInverted"); - } - - @Override - public void writeInitialSyncData(PacketBuffer packetBuffer) { - packetBuffer.writeBoolean(this.isInverted); - } - - @Override - public void readInitialSyncData(PacketBuffer packetBuffer) { - this.isInverted = packetBuffer.readBoolean(); + setRedstoneSignalOutput(RedstoneUtil.computeRedstoneValue(storedItems, itemCapacity, isInverted())); } } diff --git a/src/main/java/gregtech/common/covers/detector/CoverDetectorItemAdvanced.java b/src/main/java/gregtech/common/covers/detector/CoverDetectorItemAdvanced.java index a0c46e6b90f..945118418d6 100644 --- a/src/main/java/gregtech/common/covers/detector/CoverDetectorItemAdvanced.java +++ b/src/main/java/gregtech/common/covers/detector/CoverDetectorItemAdvanced.java @@ -5,28 +5,26 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; -import gregtech.api.capability.impl.FilteredItemHandler; -import gregtech.api.cover.CoverBehavior; import gregtech.api.cover.CoverWithUI; import gregtech.api.cover.ICoverable; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.widgets.*; -import gregtech.api.util.GTLog; import gregtech.api.util.GTUtility; +import gregtech.api.util.RedstoneUtil; import gregtech.client.renderer.texture.Textures; import gregtech.common.covers.filter.ItemFilterContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.*; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; -import java.util.regex.Pattern; - public class CoverDetectorItemAdvanced extends CoverDetectorItem implements CoverWithUI { private static final int PADDING = 3; @@ -82,7 +80,7 @@ public ModularUI createUI(EntityPlayer player) { this.itemFilter.initUI(5 + 4 * (SIZE + PADDING), group::addWidget); - return ModularUI.builder(GuiTextures.BACKGROUND, 176, 188 + 82) + return ModularUI.builder(GuiTextures.BACKGROUND, 176, 188 + 82) .widget(group) .bindPlayerInventory(player.inventory, GuiTextures.SLOT, 7, 188) .build(this, player); @@ -126,12 +124,13 @@ public void update() { int storedItems = 0; for (int i = 0; i < itemHandler.getSlots(); i++) { - if(itemFilter.testItemStack(itemHandler.getStackInSlot(i))) + if (itemFilter.testItemStack(itemHandler.getStackInSlot(i))) storedItems += itemHandler.getStackInSlot(i).getCount(); } - setRedstoneSignalOutput(GTUtility.computeRedstoneBetweenValues(storedItems, max, min, this.isInverted())); + setRedstoneSignalOutput(RedstoneUtil.computeRedstoneBetweenValues(storedItems, max, min, isInverted())); } + @Override public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index d2d9e5f225d..0007fb14d86 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -5078,20 +5078,8 @@ gregtech.chat.cape=§5Congrats: you just unlocked a new cape! See the Cape Selec gregtech.universal.clear_nbt_recipe.tooltip=§cThis will destroy all contents! -gregtech.cover.energy_detector.message_electricity_storage_normal=Monitoring Normal Electricity Storage -gregtech.cover.energy_detector.message_electricity_storage_inverted=Monitoring Inverted Electricity Storage - -gregtech.cover.fluid_detector.message_fluid_storage_normal=Monitoring Normal Fluid Storage -gregtech.cover.fluid_detector.message_fluid_storage_inverted=Monitoring Inverted Fluid Storage - -gregtech.cover.item_detector.message_item_storage_normal=Monitoring Normal Item Storage -gregtech.cover.item_detector.message_item_storage_inverted=Monitoring Inverted Item Storage - -gregtech.cover.activity_detector.message_activity_normal=Monitoring Normal Activity Status -gregtech.cover.activity_detector.message_activity_inverted=Monitoring Inverted Activity Status - -gregtech.cover.activity_detector_advanced.message_activity_normal=Monitoring Normal Progress Status -gregtech.cover.activity_detector_advanced.message_activity_inverted=Monitoring Inverted Progress Status +gregtech.cover.detector_base.message_normal_state=Monitoring Status: Normal +gregtech.cover.detector_base.message_inverted_state=Monitoring Status: Inverted gregtech.creative.chest.item=Item gregtech.creative.chest.ipc=Items per Cycle diff --git a/src/main/resources/assets/gregtech/lang/ja_jp.lang b/src/main/resources/assets/gregtech/lang/ja_jp.lang index 6fc307a4adb..7f4cebf0aa7 100644 --- a/src/main/resources/assets/gregtech/lang/ja_jp.lang +++ b/src/main/resources/assets/gregtech/lang/ja_jp.lang @@ -5037,20 +5037,8 @@ gregtech.chat.cape=§5おめでとうございます: 新しいマントを解 gregtech.universal.clear_nbt_recipe.tooltip=§cこれによりすべてのコンテンツが破棄されます! -gregtech.cover.energy_detector.message_electricity_storage_normal=通常 -gregtech.cover.energy_detector.message_electricity_storage_inverted=反転 - -gregtech.cover.fluid_detector.message_fluid_storage_normal=通常 -gregtech.cover.fluid_detector.message_fluid_storage_inverted=反転 - -gregtech.cover.item_detector.message_item_storage_normal=通常 -gregtech.cover.item_detector.message_item_storage_inverted=反転 - -gregtech.cover.activity_detector.message_activity_normal=通常 -gregtech.cover.activity_detector.message_activity_inverted=反転 - -gregtech.cover.activity_detector_advanced.message_activity_normal=通常 -gregtech.cover.activity_detector_advanced.message_activity_inverted=反転 +gregtech.cover.detector_base.message_normal_state=通常 +gregtech.cover.detector_base.message_inverted_state=反転 gregtech.creative.chest.item=アイテム gregtech.creative.chest.ipc=アイテム毎サイクル diff --git a/src/main/resources/assets/gregtech/lang/ru_ru.lang b/src/main/resources/assets/gregtech/lang/ru_ru.lang index cd2358ba9ab..c36410203c4 100644 --- a/src/main/resources/assets/gregtech/lang/ru_ru.lang +++ b/src/main/resources/assets/gregtech/lang/ru_ru.lang @@ -5370,13 +5370,6 @@ gregtech.machine.miner.multi.needsfluid=Требуется буровой рас gregtech.multiblock.pyrolyse_oven.speed=Скорость обработки: %s%% gregtech.multiblock.cracking_unit.energy=Использование энергии: %s%% gregtech.chat.cape=§5Поздравляю: вы только что разблокировали новый плащ! Откройте в терминале Переключатель плащей для подробной информации.§r -gregtech.cover.energy_detector.message_electricity_storage_inverted=Мониторинг за инвертированным энергохранилищем -gregtech.cover.fluid_detector.message_fluid_storage_normal=Мониторинг за резервуаром -gregtech.cover.fluid_detector.message_fluid_storage_inverted=Мониторинг за инвентированным резервуром -gregtech.cover.item_detector.message_item_storage_normal=Мониторинг за хранилищем -gregtech.cover.activity_detector.message_activity_normal=Мониторинг за cтатус деятельности -gregtech.cover.activity_detector.message_activity_inverted=Мониторинг за инвертированным cтатусом деятельности -gregtech.cover.activity_detector_advanced.message_activity_inverted=Мониторинг за инвертированным состоянием прогресса gregtech.creative.chest.item=Предмет gregtech.creative.chest.ipc=Предметов за цикл gregtech.creative.chest.tpc=Тиков в цикле @@ -5418,9 +5411,6 @@ terminal.console.notice=Пожалуйста нажмите Shift+ПКМ на м terminal.console.front=Установить как лицевую сторону terminal.console.items=Установить как предметный выход terminal.console.fluids=Установить как жидкостный выход -gregtech.cover.energy_detector.message_electricity_storage_normal=Мониторинг за энергохранилищем -gregtech.cover.item_detector.message_item_storage_inverted=Мониторинг за инвертированным хранилищем -gregtech.cover.activity_detector_advanced.message_activity_normal=Мониторинг за состоянием прогресса gregtech.creative.activity.on=Включить metaitem.fluid_cell.glass_vial.name=Пробирка (%s) metaitem.battery.charge_unit.second=сек. diff --git a/src/main/resources/assets/gregtech/lang/zh_cn.lang b/src/main/resources/assets/gregtech/lang/zh_cn.lang index 0b70730acc3..a6b8ce954a3 100644 --- a/src/main/resources/assets/gregtech/lang/zh_cn.lang +++ b/src/main/resources/assets/gregtech/lang/zh_cn.lang @@ -5005,21 +5005,6 @@ gregtech.chat.cape=§5恭喜!你刚刚解锁了一件新的披风!在终端 gregtech.universal.clear_nbt_recipe.tooltip=§c该操作将清空所有内容物! -gregtech.cover.energy_detector.message_electricity_storage_normal=正在以普通模式监控电力存储 -gregtech.cover.energy_detector.message_electricity_storage_inverted=正在以反相模式监控电力存储 - -gregtech.cover.fluid_detector.message_fluid_storage_normal=正在以普通模式监控流体存储 -gregtech.cover.fluid_detector.message_fluid_storage_inverted=正在以反相模式监控流体存储 - -gregtech.cover.item_detector.message_item_storage_normal=正在以普通模式监控物品存储 -gregtech.cover.item_detector.message_item_storage_inverted=正在以反相模式监控物品存储 - -gregtech.cover.activity_detector.message_activity_normal=正在以普通模式监控活动状态 -gregtech.cover.activity_detector.message_activity_inverted=正在以反相模式监控活动状态 - -gregtech.cover.activity_detector_advanced.message_activity_normal=正在以普通模式监控处理状态 -gregtech.cover.activity_detector_advanced.message_activity_inverted=正在以反相模式监控处理状态 - gregtech.creative.chest.item=物品 gregtech.creative.chest.ipc=每次输出物品数 gregtech.creative.chest.tpc=每次输出间隔 Tick