From efa96f7cb95eab41f2f30040166c2b28b3c6dd55 Mon Sep 17 00:00:00 2001 From: azzy Date: Wed, 2 Nov 2022 20:49:23 -0500 Subject: [PATCH] Prep for final release. --- gradle.properties | 2 +- .../recipe/matchbook/BooleanMatch.java | 64 +++++++++++++++++++ .../recipe/matchbook/ByteMatch.java | 64 +++++++++++++++++++ .../recipe/matchbook/FloatMatch.java | 1 - .../recipe/matchbook/IncubusMatches.java | 4 ++ .../recipe/matchbook/IntMatch.java | 1 - .../recipe/matchbook/IntRangeMatch.java | 1 - .../recipe/matchbook/LongMatch.java | 64 +++++++++++++++++++ .../incubus_core/recipe/matchbook/Match.java | 1 + .../recipe/matchbook/ShortMatch.java | 64 +++++++++++++++++++ .../recipe/matchbook/StringMatch.java | 1 - 11 files changed, 262 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/id/incubus_core/recipe/matchbook/BooleanMatch.java create mode 100644 src/main/java/net/id/incubus_core/recipe/matchbook/ByteMatch.java create mode 100644 src/main/java/net/id/incubus_core/recipe/matchbook/LongMatch.java create mode 100644 src/main/java/net/id/incubus_core/recipe/matchbook/ShortMatch.java diff --git a/gradle.properties b/gradle.properties index ba09d28..96f015f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ max_errors=400 fabric_version=0.58.0+1.18.2 # Mod Properties - mod_version = 1.7.2.INDEV-4 + mod_version = 1.7.2 # todo change maven_group = azzy.fabric archives_base_name = incubus-core diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/BooleanMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/BooleanMatch.java new file mode 100644 index 0000000..d36bbfc --- /dev/null +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/BooleanMatch.java @@ -0,0 +1,64 @@ +package net.id.incubus_core.recipe.matchbook; + +import com.google.gson.JsonObject; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; + +public class BooleanMatch extends Match { + + private boolean booleanValue; + + public BooleanMatch(String name, String key) { + super(name, key); + } + + @Override + boolean matches(ItemStack stack) { + var nbt = stack.getOrCreateNbt(); + + if(nbt.contains(key)) { + return nbt.getBoolean(key) == booleanValue; + } + + return false; + } + + @Override + void configure(JsonObject json) { + booleanValue = json.get("value").getAsBoolean(); + } + + @Override + void configure(PacketByteBuf buf) { + booleanValue = buf.readBoolean(); + } + + @Override + void write(PacketByteBuf buf) { + buf.writeBoolean(booleanValue); + } + + public static class Factory extends MatchFactory { + + public Factory() { + super("boolean"); + } + + @Override + public BooleanMatch create(String key, JsonObject object) { + var match = new BooleanMatch(name, key); + match.configure(object); + + return match; + } + + @Override + public BooleanMatch fromPacket(PacketByteBuf buf) { + var match = new BooleanMatch(name, buf.readString()); + match.configure(buf); + + return match; + } + } + +} diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/ByteMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/ByteMatch.java new file mode 100644 index 0000000..22494a7 --- /dev/null +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/ByteMatch.java @@ -0,0 +1,64 @@ +package net.id.incubus_core.recipe.matchbook; + +import com.google.gson.JsonObject; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; + +public class ByteMatch extends Match { + + private byte targetByte; + + public ByteMatch(String name, String key) { + super(name, key); + } + + @Override + boolean matches(ItemStack stack) { + var nbt = stack.getOrCreateNbt(); + + if(nbt.contains(key)) { + return nbt.getByte(key) == targetByte; + } + + return false; + } + + @Override + void configure(JsonObject json) { + targetByte = json.get("target").getAsByte(); + } + + @Override + void configure(PacketByteBuf buf) { + targetByte = buf.readByte(); + } + + @Override + void write(PacketByteBuf buf) { + buf.writeByte(targetByte); + } + + public static class Factory extends MatchFactory { + + public Factory() { + super("byte"); + } + + @Override + public ByteMatch create(String key, JsonObject object) { + var match = new ByteMatch(name, key); + match.configure(object); + + return match; + } + + @Override + public ByteMatch fromPacket(PacketByteBuf buf) { + var match = new ByteMatch(name, buf.readString()); + match.configure(buf); + + return match; + } + } + +} diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/FloatMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/FloatMatch.java index 322b41d..5180535 100644 --- a/src/main/java/net/id/incubus_core/recipe/matchbook/FloatMatch.java +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/FloatMatch.java @@ -42,7 +42,6 @@ void configure(PacketByteBuf buf) { @Override void write(PacketByteBuf buf) { - buf.writeString(key); buf.writeFloat(min); buf.writeFloat(max); } diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/IncubusMatches.java b/src/main/java/net/id/incubus_core/recipe/matchbook/IncubusMatches.java index 30ac5bf..4878bc5 100644 --- a/src/main/java/net/id/incubus_core/recipe/matchbook/IncubusMatches.java +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/IncubusMatches.java @@ -6,6 +6,10 @@ public static void init() { MatchRegistry.registerInternal("int", new IntMatch.Factory()); MatchRegistry.registerInternal("intRange", new IntRangeMatch.Factory()); MatchRegistry.registerInternal("float", new FloatMatch.Factory()); + MatchRegistry.registerInternal("long", new LongMatch.Factory()); + MatchRegistry.registerInternal("short", new ShortMatch.Factory()); + MatchRegistry.registerInternal("byte", new ByteMatch.Factory()); MatchRegistry.registerInternal("string", new StringMatch.Factory()); + MatchRegistry.registerInternal("boolean", new BooleanMatch.Factory()); } } diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/IntMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/IntMatch.java index 1e0d806..35c3aa2 100644 --- a/src/main/java/net/id/incubus_core/recipe/matchbook/IntMatch.java +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/IntMatch.java @@ -35,7 +35,6 @@ void configure(PacketByteBuf buf) { @Override void write(PacketByteBuf buf) { - buf.writeString(key); buf.writeInt(targetInt); } diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/IntRangeMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/IntRangeMatch.java index 839d596..4b83bf1 100644 --- a/src/main/java/net/id/incubus_core/recipe/matchbook/IntRangeMatch.java +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/IntRangeMatch.java @@ -42,7 +42,6 @@ void configure(PacketByteBuf buf) { @Override void write(PacketByteBuf buf) { - buf.writeString(key); buf.writeInt(min); buf.writeInt(max); } diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/LongMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/LongMatch.java new file mode 100644 index 0000000..9296506 --- /dev/null +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/LongMatch.java @@ -0,0 +1,64 @@ +package net.id.incubus_core.recipe.matchbook; + +import com.google.gson.JsonObject; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; + +public class LongMatch extends Match { + + private long targetLong; + + public LongMatch(String name, String key) { + super(name, key); + } + + @Override + boolean matches(ItemStack stack) { + var nbt = stack.getOrCreateNbt(); + + if(nbt.contains(key)) { + return nbt.getLong(key) == targetLong; + } + + return false; + } + + @Override + void configure(JsonObject json) { + targetLong = json.get("target").getAsLong(); + } + + @Override + void configure(PacketByteBuf buf) { + targetLong = buf.readLong(); + } + + @Override + void write(PacketByteBuf buf) { + buf.writeLong(targetLong); + } + + public static class Factory extends MatchFactory { + + public Factory() { + super("long"); + } + + @Override + public LongMatch create(String key, JsonObject object) { + var match = new LongMatch(name, key); + match.configure(object); + + return match; + } + + @Override + public LongMatch fromPacket(PacketByteBuf buf) { + var match = new LongMatch(name, buf.readString()); + match.configure(buf); + + return match; + } + } + +} diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/Match.java b/src/main/java/net/id/incubus_core/recipe/matchbook/Match.java index fa0b46a..7a2cf3f 100644 --- a/src/main/java/net/id/incubus_core/recipe/matchbook/Match.java +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/Match.java @@ -29,6 +29,7 @@ public String getName() { public void writeInternal(PacketByteBuf buf) { buf.writeString(name); + buf.writeString(key); write(buf); } diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/ShortMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/ShortMatch.java new file mode 100644 index 0000000..e010b93 --- /dev/null +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/ShortMatch.java @@ -0,0 +1,64 @@ +package net.id.incubus_core.recipe.matchbook; + +import com.google.gson.JsonObject; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; + +public class ShortMatch extends Match { + + private short targetShort; + + public ShortMatch(String name, String key) { + super(name, key); + } + + @Override + boolean matches(ItemStack stack) { + var nbt = stack.getOrCreateNbt(); + + if(nbt.contains(key)) { + return nbt.getShort(key) == targetShort; + } + + return false; + } + + @Override + void configure(JsonObject json) { + targetShort = json.get("target").getAsShort(); + } + + @Override + void configure(PacketByteBuf buf) { + targetShort = buf.readShort(); + } + + @Override + void write(PacketByteBuf buf) { + buf.writeShort(targetShort); + } + + public static class Factory extends MatchFactory { + + public Factory() { + super("short"); + } + + @Override + public ShortMatch create(String key, JsonObject object) { + var match = new ShortMatch(name, key); + match.configure(object); + + return match; + } + + @Override + public ShortMatch fromPacket(PacketByteBuf buf) { + var match = new ShortMatch(name, buf.readString()); + match.configure(buf); + + return match; + } + } + +} diff --git a/src/main/java/net/id/incubus_core/recipe/matchbook/StringMatch.java b/src/main/java/net/id/incubus_core/recipe/matchbook/StringMatch.java index 9e3e4c3..c3c37e4 100644 --- a/src/main/java/net/id/incubus_core/recipe/matchbook/StringMatch.java +++ b/src/main/java/net/id/incubus_core/recipe/matchbook/StringMatch.java @@ -35,7 +35,6 @@ void configure(PacketByteBuf buf) { @Override void write(PacketByteBuf buf) { - buf.writeString(key); buf.writeString(targetString); }