diff options
author | HoleFish <48403212+HoleFish@users.noreply.github.com> | 2024-08-31 01:48:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-30 17:48:23 +0000 |
commit | 9fee35c065e197199f57ef1df31ac303e94d1d50 (patch) | |
tree | 66437da0c2422d10ddfc9211040ebbd180af5f54 /src/main/java/gregtech/api/recipe | |
parent | 55ebcb3bdf0f54b76642c03b3a58112081138c10 (diff) | |
download | GT5-Unofficial-9fee35c065e197199f57ef1df31ac303e94d1d50.tar.gz GT5-Unofficial-9fee35c065e197199f57ef1df31ac303e94d1d50.tar.bz2 GT5-Unofficial-9fee35c065e197199f57ef1df31ac303e94d1d50.zip |
Add duration since last shutdown (#2977)
* machine message
* fix & prass channel
* machine message
* fix & prass channel
* fix machines that dont use regular onPostTick
* follow error fixes and fix hatch check
* oops
* sa
---------
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: boubou19 <miisterunknown@gmail.com>
Diffstat (limited to 'src/main/java/gregtech/api/recipe')
8 files changed, 120 insertions, 50 deletions
diff --git a/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java b/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java index 8af5c58f5e..60436b9c3e 100644 --- a/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java +++ b/src/main/java/gregtech/api/recipe/check/CheckRecipeResult.java @@ -1,8 +1,6 @@ package gregtech.api.recipe.check; -import javax.annotation.Nonnull; - -import net.minecraft.network.PacketBuffer; +import gregtech.api.util.IMachineMessage; /** * Class to indicate the result of recipe check in the machine. It doesn't need to be actual result of recipemap check, @@ -10,13 +8,7 @@ import net.minecraft.network.PacketBuffer; * <p> * Sample instance must be registered to {@link CheckRecipeResultRegistry}. */ -public interface CheckRecipeResult { - - /** - * @return Unique registry ID - */ - @Nonnull - String getID(); +public interface CheckRecipeResult extends IMachineMessage<CheckRecipeResult> { /** * @return If recipe check is successful @@ -24,28 +16,6 @@ public interface CheckRecipeResult { boolean wasSuccessful(); /** - * @return Actual text to show on client GUI - */ - @Nonnull - String getDisplayString(); - - /** - * Create new instance to receive packet. - */ - @Nonnull - CheckRecipeResult newInstance(); - - /** - * Encode value to sync. - */ - void encode(@Nonnull PacketBuffer buffer); - - /** - * Decode synced value. - */ - void decode(PacketBuffer buffer); - - /** * @return If this message should stay on GUI when the machine is shut down. */ default boolean persistsOnShutdown() { diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java index 26c3530ba3..9383abad9d 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientHeat.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.util.GT_Utility; @@ -20,7 +23,7 @@ public class ResultInsufficientHeat implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_heat"; } @@ -31,7 +34,7 @@ public class ResultInsufficientHeat implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_heat", @@ -40,8 +43,19 @@ public class ResultInsufficientHeat implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientHeat(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java index 742eb3ef7a..1fb2183edb 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientMachineTier.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.util.GT_Utility; public class ResultInsufficientMachineTier implements CheckRecipeResult { @@ -19,7 +22,7 @@ public class ResultInsufficientMachineTier implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_machine_tier"; } @@ -30,7 +33,7 @@ public class ResultInsufficientMachineTier implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_machine_tier", @@ -38,8 +41,19 @@ public class ResultInsufficientMachineTier implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientMachineTier(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java index fdc06c0c07..45b50aebf6 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientPower.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.util.GT_Utility; public class ResultInsufficientPower implements CheckRecipeResult { @@ -19,7 +22,7 @@ public class ResultInsufficientPower implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_power"; } @@ -30,7 +33,7 @@ public class ResultInsufficientPower implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_power", @@ -39,8 +42,19 @@ public class ResultInsufficientPower implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setLong("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getLong("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientPower(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java index 62d2dd1fb2..c33e9bfff1 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPower.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import gregtech.api.util.GT_Utility; public class ResultInsufficientStartupPower implements CheckRecipeResult { @@ -19,7 +22,7 @@ public class ResultInsufficientStartupPower implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "insufficient_startup_power"; } @@ -30,7 +33,7 @@ public class ResultInsufficientStartupPower implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( StatCollector.translateToLocalFormatted( "GT5U.gui.text.insufficient_startup_power", @@ -38,8 +41,19 @@ public class ResultInsufficientStartupPower implements CheckRecipeResult { } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setInteger("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getInteger("required"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultInsufficientStartupPower(0); } diff --git a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java index 6a719b3c9c..f4b186c9a1 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java +++ b/src/main/java/gregtech/api/recipe/check/ResultInsufficientStartupPowerBigInt.java @@ -5,6 +5,7 @@ import static util.Util.toStandardForm; import java.math.BigInteger; import java.util.Objects; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; @@ -36,6 +37,17 @@ public class ResultInsufficientStartupPowerBigInt implements CheckRecipeResult { StatCollector.translateToLocalFormatted("GT5U.gui.text.insufficient_startup_power", required)); } + @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setString("required", required); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + required = tag.getString("required"); + } + @NotNull @Override public CheckRecipeResult newInstance() { diff --git a/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java b/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java index 868d664109..db4ea2ba41 100644 --- a/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java +++ b/src/main/java/gregtech/api/recipe/check/ResultMissingItem.java @@ -7,8 +7,11 @@ import javax.annotation.Nullable; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; +import org.jetbrains.annotations.NotNull; + import cpw.mods.fml.common.network.ByteBufUtils; public class ResultMissingItem implements CheckRecipeResult { @@ -26,7 +29,7 @@ public class ResultMissingItem implements CheckRecipeResult { @Override @Nonnull - public String getID() { + public @NotNull String getID() { return "missing_item"; } @@ -37,14 +40,25 @@ public class ResultMissingItem implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull( I18n.format("GT5U.gui.text.missing_item", itemStack != null ? itemStack.getDisplayName() : "null")); } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + if (itemStack != null) return itemStack.writeToNBT(tag); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + itemStack = ItemStack.loadItemStackFromNBT(tag); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new ResultMissingItem(itemStack != null ? itemStack.copy() : null); } diff --git a/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java b/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java index 58c85bbe9d..ed998e93d9 100644 --- a/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java +++ b/src/main/java/gregtech/api/recipe/check/SimpleCheckRecipeResult.java @@ -4,9 +4,12 @@ import java.util.Objects; import javax.annotation.Nonnull; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.util.StatCollector; +import org.jetbrains.annotations.NotNull; + import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; /** @@ -25,7 +28,7 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { } @Override - public String getID() { + public @NotNull String getID() { return "simple_result"; } @@ -36,13 +39,28 @@ public class SimpleCheckRecipeResult implements CheckRecipeResult { @Override @Nonnull - public String getDisplayString() { + public @NotNull String getDisplayString() { return Objects.requireNonNull(StatCollector.translateToLocal("GT5U.gui.text." + key)); } @Override + public @NotNull NBTTagCompound writeToNBT(@NotNull NBTTagCompound tag) { + tag.setBoolean("success", success); + tag.setString("key", key); + tag.setBoolean("persistsOnShutdown", persistsOnShutdown); + return tag; + } + + @Override + public void readFromNBT(@NotNull NBTTagCompound tag) { + success = tag.getBoolean("success"); + key = tag.getString("key"); + persistsOnShutdown = tag.getBoolean("persistsOnShutdown"); + } + + @Override @Nonnull - public CheckRecipeResult newInstance() { + public @NotNull CheckRecipeResult newInstance() { return new SimpleCheckRecipeResult(false, "", false); } |