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 0000000..fa25618 Binary files /dev/null and b/src/main/resources/assets/plutoscoffee/textures/gui/pc_icons.png differ 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 5e659e1..0000000 Binary files a/src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_fill.png and /dev/null differ 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 973c196..0000000 Binary files a/src/main/resources/assets/plutoscoffee/textures/gui/sprites/hud/caffeine_content_outline.png and /dev/null differ 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