From 1e62b9e4b4b3d35418d21c0d753c81f67aaba8b7 Mon Sep 17 00:00:00 2001 From: pluto7073 Date: Sun, 17 Dec 2023 19:23:36 -0500 Subject: [PATCH] Fixes for problems caused by downgrading MC Version --- .../blocks/CoffeeBrewerBlock.java | 2 +- .../plutoscoffee/gui/CoffeeBrewerScreen.java | 2 +- .../gui/CoffeeWorkstationScreenHandler.java | 38 +++++---- .../mixins/client/InGameHudMixin.java | 10 +-- .../recipes/CoffeeWorkstationRecipe.java | 73 +++++++++--------- .../plutoscoffee/textures/gui/pc_icons.png | Bin 0 -> 1098 bytes .../gui/sprites/hud/caffeine_content_fill.png | Bin 486 -> 0 bytes .../sprites/hud/caffeine_content_outline.png | Bin 693 -> 0 bytes .../recipes/brewed_coffee_and_caramel.json | 6 +- .../recipes/brewed_coffee_and_milk.json | 6 +- .../recipes/brewed_coffee_and_mocha.json | 6 +- .../recipes/brewed_coffee_and_sugar.json | 6 +- 12 files changed, 85 insertions(+), 64 deletions(-) create mode 100644 src/main/resources/assets/plutoscoffee/textures/gui/pc_icons.png delete mode 100755 src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_fill.png delete mode 100755 src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_outline.png diff --git a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java index 53fb1dd..2b335f7 100755 --- a/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/blocks/CoffeeBrewerBlock.java @@ -52,7 +52,7 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { @Nullable public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { - return world.isClient ? null : validateTicker(type, ModBlocks.COFFEE_BREWER_BLOCK_ENTITY_TYPE, CoffeeBrewerBlockEntity::tick); + return world.isClient ? null : checkType(type, ModBlocks.COFFEE_BREWER_BLOCK_ENTITY_TYPE, CoffeeBrewerBlockEntity::tick); } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java index fb9d9c4..e72d588 100755 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeBrewerScreen.java @@ -24,7 +24,7 @@ protected void init() { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context, mouseX, mouseY, delta); + this.renderBackground(context); super.render(context, mouseX, mouseY, delta); this.drawMouseoverTooltip(context, mouseX, mouseY); } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeWorkstationScreenHandler.java b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeWorkstationScreenHandler.java index 5351f78..cf114bf 100755 --- a/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeWorkstationScreenHandler.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/gui/CoffeeWorkstationScreenHandler.java @@ -8,12 +8,14 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; -import net.minecraft.recipe.RecipeEntry; +import net.minecraft.recipe.SmithingRecipe; import net.minecraft.screen.ForgingScreenHandler; import net.minecraft.screen.ScreenHandlerContext; +import net.minecraft.screen.ScreenHandlerType; import net.minecraft.screen.slot.ForgingSlotsManager; import net.minecraft.screen.slot.Slot; import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -21,8 +23,8 @@ public class CoffeeWorkstationScreenHandler extends ForgingScreenHandler { private final World world; - private RecipeEntry currentRecipe; - private final List> recipes; + private CoffeeWorkstationRecipe currentRecipe; + private final List recipes; public CoffeeWorkstationScreenHandler(int syncId, PlayerInventory playerInventory) { this(syncId, playerInventory, ScreenHandlerContext.EMPTY); @@ -36,7 +38,7 @@ public CoffeeWorkstationScreenHandler(int syncId, PlayerInventory playerInventor @Override protected boolean canTakeOutput(PlayerEntity player, boolean present) { - return currentRecipe != null && currentRecipe.value().matches(input, world); + return currentRecipe != null && currentRecipe.matches(input, world); } @Override @@ -45,10 +47,11 @@ protected void onTakeOutput(PlayerEntity player, ItemStack stack) { this.output.unlockLastRecipe(player, List.of(getSlot(0).getStack(), getSlot(1).getStack())); decrementStack(0, player); decrementStack(1, player); - context.run((world, pos) -> world.syncWorldEvent(10000, pos, 0)); + context.run((world, pos) -> { + world.syncWorldEvent(10000, pos, 0); + }); } - @SuppressWarnings("DataFlowIssue") private void decrementStack(int slot, PlayerEntity player) { ItemStack itemStack = input.getStack(slot); if (itemStack.getCount() == 1) { @@ -73,12 +76,12 @@ protected boolean canUse(BlockState state) { @Override public void updateResult() { - List> list = world.getRecipeManager().getAllMatches(ModMisc.COFFEE_WORK_RECIPE_TYPE, input, world); + List list = world.getRecipeManager().getAllMatches(ModMisc.COFFEE_WORK_RECIPE_TYPE, input, world); if (list.isEmpty()) { output.setStack(0, ItemStack.EMPTY); } else { currentRecipe = list.get(0); - ItemStack stack = currentRecipe.value().craft(input); + ItemStack stack = currentRecipe.craft(input); output.setLastRecipe(currentRecipe); output.setStack(0, stack); } @@ -86,12 +89,15 @@ public void updateResult() { @Override protected ForgingSlotsManager getForgingSlotsManager() { - return ForgingSlotsManager.create() - .input(0, 27, 47, - stack -> this.recipes.stream().anyMatch(recipe -> recipe.value().testBase(stack))) - .input(1, 76, 47, - stack -> this.recipes.stream().anyMatch(recipe -> recipe.value().testAddition(stack))) - .output(2, 134, 47).build(); + return ForgingSlotsManager.create().input(0, 27, 47, stack -> { + return this.recipes.stream().anyMatch(recipe -> { + return recipe.testBase(stack); + }); + }).input(1, 76, 47, stack -> { + return this.recipes.stream().anyMatch(recipe -> { + return recipe.testAddition(stack); + }); + }).output(2, 134, 47).build(); } private static Optional getQuickMoveSlot(CoffeeWorkstationRecipe recipe, ItemStack stack) { @@ -104,7 +110,9 @@ private static Optional getQuickMoveSlot(CoffeeWorkstationRecipe recipe @Override protected boolean isValidIngredient(ItemStack stack) { - return this.recipes.stream().map((recipe) -> getQuickMoveSlot(recipe.value(), stack)).anyMatch(Optional::isPresent); + return this.recipes.stream().map((recipe) -> { + return getQuickMoveSlot(recipe, stack); + }).anyMatch(Optional::isPresent); } @Override diff --git a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java index 7e2671a..7597a4d 100755 --- a/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/mixins/client/InGameHudMixin.java @@ -24,8 +24,9 @@ @Mixin(InGameHud.class) public abstract class InGameHudMixin { - @Unique private static final Identifier CAFFEINE_OUTLINE_TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "hud/caffeine_content_outline"); - @Unique private static final Identifier CAFFEINE_FILL_TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "hud/caffeine_content_fill"); + @Unique private static final Identifier CAFFEINE_OUTLINE_TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/caffeine_content/outline.png"); + @Unique private static final Identifier CAFFEINE_FILL_TEXTURE = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/caffeine_content/fill.png"); + @Unique private static final Identifier ICONS = new Identifier(PlutosCoffee.MOD_ID, "textures/gui/pc_icons.png"); @Shadow @Final private MinecraftClient client; @@ -46,9 +47,8 @@ public void plutoscoffee_renderCaffeineContentDisplay(DrawContext context, Callb float currentCaffeine = Math.min(3000f, Utils.getPlayerCaffeine(playerEntity)); int scaledCaffeineOutput = Math.round(currentCaffeine * (71f/3000f)); - - context.drawGuiTexture(CAFFEINE_OUTLINE_TEXTURE, centerX + 10, baseYValue, 80, 8); - context.drawGuiTexture(CAFFEINE_FILL_TEXTURE, 80, 8, 0, 0, centerX + 10, baseYValue, scaledCaffeineOutput, 8); + context.drawTexture(ICONS, centerX + 10, baseYValue, 0, 0, 80, 8, 80, 16); + context.drawTexture(ICONS, centerX + 10, baseYValue, 0, 9, scaledCaffeineOutput, 8, 80, 16); this.client.getProfiler().pop(); } diff --git a/src/main/java/ml/pluto7073/plutoscoffee/recipes/CoffeeWorkstationRecipe.java b/src/main/java/ml/pluto7073/plutoscoffee/recipes/CoffeeWorkstationRecipe.java index b98edbc..b0adf66 100755 --- a/src/main/java/ml/pluto7073/plutoscoffee/recipes/CoffeeWorkstationRecipe.java +++ b/src/main/java/ml/pluto7073/plutoscoffee/recipes/CoffeeWorkstationRecipe.java @@ -1,22 +1,21 @@ package ml.pluto7073.plutoscoffee.recipes; -import com.mojang.serialization.Codec; -import com.mojang.serialization.MapCodec; -import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.google.gson.JsonObject; import ml.pluto7073.plutoscoffee.Utils; import ml.pluto7073.plutoscoffee.registry.ModBlocks; -import ml.pluto7073.plutoscoffee.registry.ModItems; import ml.pluto7073.plutoscoffee.registry.ModMisc; import net.minecraft.inventory.Inventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.NbtList; import net.minecraft.network.PacketByteBuf; -import net.minecraft.recipe.Ingredient; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.recipe.RecipeType; +import net.minecraft.recipe.*; import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; import net.minecraft.world.World; import java.util.stream.Stream; @@ -25,13 +24,14 @@ public class CoffeeWorkstationRecipe implements Recipe { final Ingredient base; final Ingredient addition; - final CoffeeStackBuilder result; - //public final Identifier id; + final ItemStack result; + private final Identifier id; - public CoffeeWorkstationRecipe(Ingredient base, Ingredient addition, CoffeeStackBuilder result) { + public CoffeeWorkstationRecipe(Identifier id, Ingredient base, Ingredient addition, ItemStack result) { this.base = base; this.addition = addition; this.result = result; + this.id = id; } @Override @@ -45,11 +45,10 @@ public ItemStack craft(Inventory inventory, DynamicRegistryManager registryManag } public ItemStack craft(Inventory inventory) { - ItemStack stack = new ItemStack(ModItems.BREWED_COFFEE, 1); + ItemStack stack = result.copy(); NbtList sourceAdds = inventory.getStack(0).getOrCreateSubNbt("Coffee").getList("Additions", NbtElement.STRING_TYPE); - NbtList resAdds = new NbtList(); + NbtList resAdds = stack.getOrCreateSubNbt("Coffee").getList("Additions", NbtElement.STRING_TYPE); resAdds.addAll(sourceAdds); - resAdds.add(Utils.stringAsNbt(result.addition())); String coffeeType = inventory.getStack(0).getOrCreateSubNbt("Coffee").getString("CoffeeType"); stack.getOrCreateSubNbt("Coffee").put("Additions", resAdds); stack.getOrCreateSubNbt("Coffee").putString("CoffeeType", coffeeType); @@ -63,8 +62,13 @@ public boolean fits(int width, int height) { } @Override - public ItemStack getResult(DynamicRegistryManager registryManager) { - return this.result.example(); + public ItemStack getOutput(DynamicRegistryManager registryManager) { + return this.result; + } + + @Override + public Identifier getId() { + return this.id; } public boolean testAddition(ItemStack stack) { @@ -95,42 +99,35 @@ public boolean isEmpty() { public static class Serializer implements RecipeSerializer { - private static final MapCodec RESULT_STACK_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(Codec.STRING.fieldOf("result").forGetter(CoffeeStackBuilder::addition)).apply(instance, CoffeeStackBuilder::new)); - - private static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group(Ingredient.ALLOW_EMPTY_CODEC.fieldOf("base").forGetter((recipe) -> recipe.base), Ingredient.ALLOW_EMPTY_CODEC.fieldOf("addition").forGetter((recipe) -> recipe.addition), RESULT_STACK_CODEC.forGetter(recipe -> recipe.result)).apply(instance, CoffeeWorkstationRecipe::new)); - public Serializer() {} @Override - public Codec codec() { - return CODEC; + public CoffeeWorkstationRecipe read(Identifier id, JsonObject jsonObject) { + Ingredient ingredient = Ingredient.fromJson(JsonHelper.getObject(jsonObject, "base")); + Ingredient ingredient2 = Ingredient.fromJson(JsonHelper.getObject(jsonObject, "addition")); + JsonObject resultObject = JsonHelper.getObject(jsonObject, "result"); + Item item = ShapedRecipe.getItem(resultObject); + int count = JsonHelper.getInt(resultObject, "count", 1); + ItemStack itemStack = new ItemStack(item, count); + NbtList list = new NbtList(); + list.add(Utils.stringAsNbt(JsonHelper.getString(resultObject, "addition"))); + itemStack.getOrCreateSubNbt("Coffee").put("Additions", list); + return new CoffeeWorkstationRecipe(id, ingredient, ingredient2, itemStack); } @Override - public CoffeeWorkstationRecipe read(PacketByteBuf buf) { + public CoffeeWorkstationRecipe read(Identifier id, PacketByteBuf buf) { Ingredient ingredient = Ingredient.fromPacket(buf); Ingredient ingredient2 = Ingredient.fromPacket(buf); - String result = buf.readString(); - return new CoffeeWorkstationRecipe(ingredient, ingredient2, new CoffeeStackBuilder(result)); + ItemStack itemStack = buf.readItemStack(); + return new CoffeeWorkstationRecipe(id, ingredient, ingredient2, itemStack); } @Override public void write(PacketByteBuf buf, CoffeeWorkstationRecipe recipe) { recipe.base.write(buf); recipe.addition.write(buf); - buf.writeString(recipe.result.addition()); - } - - } - - public record CoffeeStackBuilder(String addition) { - - ItemStack example() { - ItemStack example = new ItemStack(ModItems.BREWED_COFFEE, 1); - NbtList list = new NbtList(); - list.add(Utils.stringAsNbt(addition())); - example.getOrCreateSubNbt("Coffee").put("Additions", list); - return example; + buf.writeItemStack(recipe.result); } } diff --git a/src/main/resources/assets/plutoscoffee/textures/gui/pc_icons.png b/src/main/resources/assets/plutoscoffee/textures/gui/pc_icons.png new file mode 100644 index 0000000000000000000000000000000000000000..fa25618094305460e543a0ea21af7ec5f7e7cfd1 GIT binary patch literal 1098 zcmV-Q1hxB#P)?O`UOZX;y_P3$p0tDm9^B&aw?goLSOw=BzafMn9I-^cI$y5DOAW+O8KUp;VCpcGs`gcn8F`8yCI^XmV( z;5UteTAnlE`4QYe!O02ya&UX!KR6{ATY^4 zskuSF^b@IQOzy(-5Cj~rgp?6fBx8N1fdbjxT;G68Abz=2QJ>cof=FSv9iT^vTd5kb z4B+R#n1KXfb9D(WIoQAGj{#`qEjYyzTCGFW>kDsPE>63E&2~#=92~T;aIX&c{OpbT z#{l}5@fIB9LR+@;HYKivy{#R%?KAOpqpIpofEVW>B^YST*_1@3+56LTT5nd$>hTw! zLMx;U(;NcISTZ=npHx4SA15tRI_GbzwKkO zYGN)=M*<$=lR(0QX0VZEzfJ?qc(5~Q2o z^+>!)d&TqD864X))4$*&fYlnrlpOgbQe;W5WbpX;(SoJc>NY$&M+>HaNox+yLVW+U zr{`x?I70%~?%EpWO9IiLqw=>_e~8-*zzhIR6PW=x1Mrpz+;X{QptOxlMdX&Y{!`1N z%NsiNK{P^`Qa%3QfquMOs}8DbTot+K1|c<>RQ>jj+9*=@D1{uzQI}5*Fqbq*m8o^y zp@ucSC*H}Mx<1__ed*y-ocCNUsCP`?lV3{-NnJoq@V z@fqoT6KAf|mCRk~kJFq^j7&R`)0-;g-V!Z literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_fill.png b/src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_fill.png deleted file mode 100755 index 5e659e161d1e89603e0bd4d21b6863761ee027b1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 486 zcmV@P)Ef_&SgP5oh#S;e)@)ka^Zy^V-qG(LO@VALzr0v$3p(RU|vI!pBgmz25 z{dV@7-&R0&?UaDnX?8XlI6#@V!YqsR1k`t61eXww3~w(lc=lsf9j8*d0tBemBQ|z?y7dk#ZjP4ICVn17M>5Ck1<@I9BtJ-qpo3~Gxamo-9J2< z2iR)V;kbMNIU74ddyS}~J--hoOyF#RokIeta}I{R3`R1g6cmNRBn({GcO;LA=wyfc zW0%QgKO|w3E+%2VQ0%vf7~QX4Ewf)5Szn%lV%~;YrL@{d+*<-ACbiu)B#&*X-h#v@fzgL90(Ed~I#5zF+4t;icDSa(t6<={00y c!vuZ+xCZ?Rbzlu800000NkvXXu0mjf0Lc*57ytkO diff --git a/src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_outline.png b/src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_outline.png deleted file mode 100755 index 973c196964717512251f86d12a35f7d823b0455d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 693 zcmV;m0!safP) zem)!g9?X(>Rrlz2!N6cb*!vj*tisw23x~f#&YQv8-rmH}_YuYM5{?I_`sw4fKZtou52unnW7{=jA80Hu%e*gpwt@Q4k=C zRJ{^XCZI&7{!9Zd$KBoe2%kZGwqBqoYlJ8v9CjlNnYdcffMo#hzA6PWfc3^Yd`@sO znk)fmITpNZ4xP?7R4U~ww@YakuvOe#9_@AqLUMXGoazV~A$7^s$PCXuvy-+tlqW+6|HpFV_k$PDuyB4%v56vO#k4y|Sj zwOW-G$jrqNSSt&GFRN5vDS_h>D=TedT@owCMAlKt-$$cSXX1Q>QOG-s>#}i!(FifW z3Bi+8X9DgJ|%m{M4Du baQg#2+jc;`&8tBG0000 diff --git a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_caramel.json b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_caramel.json index 2ebd015..ada4822 100755 --- a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_caramel.json +++ b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_caramel.json @@ -6,5 +6,9 @@ "addition": { "item": "plutoscoffee:caramel" }, - "result": "plutoscoffee:caramel" + "result": { + "item": "plutoscoffee:brewed_coffee", + "count": 1, + "addition": "plutoscoffee:caramel" + } } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json index fab75bc..b0cd5fe 100755 --- a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json +++ b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_milk.json @@ -6,5 +6,9 @@ "addition": { "item": "plutoscoffee:milk_bottle" }, - "result": "plutoscoffee:milk" + "result": { + "item": "plutoscoffee:brewed_coffee", + "count": 1, + "addition": "plutoscoffee:milk" + } } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_mocha.json b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_mocha.json index 83e398e..67987e8 100755 --- a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_mocha.json +++ b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_mocha.json @@ -6,5 +6,9 @@ "addition": { "item": "plutoscoffee:mocha_syrup" }, - "result": "plutoscoffee:mocha_syrup" + "result": { + "item": "plutoscoffee:brewed_coffee", + "count": 1, + "addition": "plutoscoffee:mocha_syrup" + } } \ No newline at end of file diff --git a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_sugar.json b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_sugar.json index d08cf73..e29352a 100755 --- a/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_sugar.json +++ b/src/main/resources/data/plutoscoffee/recipes/brewed_coffee_and_sugar.json @@ -6,5 +6,9 @@ "addition": { "item": "minecraft:sugar" }, - "result": "plutoscoffee:sugar" + "result": { + "item": "plutoscoffee:brewed_coffee", + "count": 1, + "addition": "plutoscoffee:sugar" + } } \ No newline at end of file