From 64cd17e9138fbbab4c3a4b2d55688b61f44b4504 Mon Sep 17 00:00:00 2001 From: Seth Tal Date: Thu, 20 Jun 2024 22:42:00 -0700 Subject: [PATCH] Updated codebase to fabric 0.91.6+1.20.2 - refactored Alloy Smelter and Alloy Smelter Recipes - removed un-used classes and their references - changes reflect additions/deprecations/changes introduced in fabric 0.91.6+1.20.2 --- build.gradle | 2 +- gradle.properties | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/net/stal/alloys/StalAlloys.java | 3 - .../net/stal/alloys/StalAlloysClient.java | 5 -- .../stal/alloys/block/AlloySmelterBlock.java | 2 +- .../block/entity/AlloySmelterEntity.java | 48 ++++++++------- .../datagen/StalAlloysRecipeProvider.java | 5 +- .../stal/alloys/event/KeyInputHandler.java | 40 ------------ .../alloys/networking/StalAlloysMessages.java | 31 ---------- .../networking/packet/ExampleC2SPacket.java | 26 -------- .../networking/packet/ExampleS2CPacket.java | 14 ----- .../alloys/recipe/AlloySmelterRecipe.java | 61 +++++++++---------- .../alloys/screen/AlloySmelterScreen.java | 3 +- .../alloys/util/ExamplePersistantData.java | 58 ------------------ 15 files changed, 64 insertions(+), 242 deletions(-) delete mode 100644 src/main/java/net/stal/alloys/event/KeyInputHandler.java delete mode 100644 src/main/java/net/stal/alloys/networking/StalAlloysMessages.java delete mode 100644 src/main/java/net/stal/alloys/networking/packet/ExampleC2SPacket.java delete mode 100644 src/main/java/net/stal/alloys/networking/packet/ExampleS2CPacket.java delete mode 100644 src/main/java/net/stal/alloys/util/ExamplePersistantData.java diff --git a/build.gradle b/build.gradle index a5f8566..a012b6e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.3-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 2434409..e41e846 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.10 +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.4 loader_version=0.15.11 # Mod Properties @@ -15,4 +15,4 @@ archives_base_name=stal-alloys modid=stal-alloys # Dependencies -fabric_version=0.92.2+1.20.1 \ No newline at end of file +fabric_version=0.91.6+1.20.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33..0c85a1f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/stal/alloys/StalAlloys.java b/src/main/java/net/stal/alloys/StalAlloys.java index e912a8c..e3c5e23 100644 --- a/src/main/java/net/stal/alloys/StalAlloys.java +++ b/src/main/java/net/stal/alloys/StalAlloys.java @@ -4,7 +4,6 @@ import net.stal.alloys.item.StalAlloysItemGroup; // import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.stal.alloys.item.StalAlloysItems; -import net.stal.alloys.networking.StalAlloysMessages; import net.stal.alloys.recipe.StalAlloysRecipes; import net.stal.alloys.screen.StalAlloysScreenHandlers; import net.stal.alloys.world.StalAlloysConfiguredFeatures; @@ -43,8 +42,6 @@ public void onInitialize() { StalAlloysRecipes.registerRecipes(); - StalAlloysMessages.registerC2SPackets(); - // Other stuff... // ServerTickEvents.START_SERVER_TICK.register(new PlayerTickHandler()); diff --git a/src/main/java/net/stal/alloys/StalAlloysClient.java b/src/main/java/net/stal/alloys/StalAlloysClient.java index dec8ac2..092b368 100644 --- a/src/main/java/net/stal/alloys/StalAlloysClient.java +++ b/src/main/java/net/stal/alloys/StalAlloysClient.java @@ -2,8 +2,6 @@ import net.fabricmc.api.ClientModInitializer; import net.minecraft.client.gui.screen.ingame.HandledScreens; -import net.stal.alloys.event.KeyInputHandler; -import net.stal.alloys.networking.StalAlloysMessages; import net.stal.alloys.screen.AlloySmelterScreen; import net.stal.alloys.screen.StalAlloysScreenHandlers; @@ -12,9 +10,6 @@ public class StalAlloysClient implements ClientModInitializer { @Override public void onInitializeClient() { HandledScreens.register(StalAlloysScreenHandlers.ALLOY_SMELTER_SCREEN_HANDLER, AlloySmelterScreen::new); - - KeyInputHandler.registerKeyBindings(); - StalAlloysMessages.registerS2CPackets(); } } diff --git a/src/main/java/net/stal/alloys/block/AlloySmelterBlock.java b/src/main/java/net/stal/alloys/block/AlloySmelterBlock.java index 23827ab..04542f7 100644 --- a/src/main/java/net/stal/alloys/block/AlloySmelterBlock.java +++ b/src/main/java/net/stal/alloys/block/AlloySmelterBlock.java @@ -117,6 +117,6 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { @Override public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { - return checkType(type, StalAlloysBlockEntities.ALLOY_SMELTER_ENTITY, AlloySmelterEntity::tick); + return BlockWithEntity.validateTicker(type, StalAlloysBlockEntities.ALLOY_SMELTER_ENTITY, AlloySmelterEntity::tick); } } diff --git a/src/main/java/net/stal/alloys/block/entity/AlloySmelterEntity.java b/src/main/java/net/stal/alloys/block/entity/AlloySmelterEntity.java index fc26271..8288ab1 100644 --- a/src/main/java/net/stal/alloys/block/entity/AlloySmelterEntity.java +++ b/src/main/java/net/stal/alloys/block/entity/AlloySmelterEntity.java @@ -22,7 +22,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; -import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.PropertyDelegate; import net.minecraft.screen.ScreenHandler; @@ -151,12 +151,12 @@ public void readNbt(NbtCompound nbt) { } } - public void setLastRecipe(@Nullable Recipe recipe) { + public void setLastRecipe(@Nullable RecipeEntry recipe) { if (recipe != null) { - Identifier identifier = recipe.getId(); + Identifier identifier = recipe.id(); this.recipesUsed.addTo(identifier, 1); } -} + } public static void tick(World world, BlockPos blockPos, BlockState blockState, AlloySmelterEntity entity) { if (world.isClient()) return; @@ -211,17 +211,20 @@ private static boolean hasRecipe(AlloySmelterEntity entity) { inventory.setStack(i, entity.getStack(i)); } - Optional recipeFromInventory = entity.getWorld() + Optional> recipeFromInventoryOpt = entity.getWorld() .getRecipeManager() .getFirstMatch(AlloySmelterRecipe.Type.INSTANCE, inventory, entity.getWorld()); - if (recipeFromInventory.isPresent()) { - entity.mMaxProgress = recipeFromInventory.get().getCookingTime(); - } + if (recipeFromInventoryOpt.isPresent()) { + AlloySmelterRecipe recipe = recipeFromInventoryOpt.get().value(); + + entity.mMaxProgress = recipe.getCookingTime(); - return recipeFromInventory.isPresent() && - canInsertAmountIntoOutputSlot(inventory) && - canInsertItemIntoOutputSlot(inventory, recipeFromInventory.get().getOutput(null).getItem()); + return canInsertAmountIntoOutputSlot(inventory) && + canInsertItemIntoOutputSlot(inventory, recipe.getResult(null).getItem()); + } + + return false; } private static void craftItem(AlloySmelterEntity entity) { @@ -231,23 +234,25 @@ private static void craftItem(AlloySmelterEntity entity) { inventory.setStack(i, entity.getStack(i)); } - Optional recipeFromInventory = entity.getWorld() + Optional> recipeFromInventoryOpt = entity.getWorld() .getRecipeManager() .getFirstMatch(AlloySmelterRecipe.Type.INSTANCE, inventory, entity.getWorld()); - if (hasRecipe(entity)) { + if (recipeFromInventoryOpt.isPresent() && hasRecipe(entity)) { + AlloySmelterRecipe recipe = recipeFromInventoryOpt.get().value(); + entity.removeStack(AlloySmelterInventorySlots.FIRST.value, 1); entity.removeStack(AlloySmelterInventorySlots.SECOND.value, 1); entity.setStack( AlloySmelterInventorySlots.THIRD.value, new ItemStack( - recipeFromInventory.get().getOutput(null).getItem(), + recipe.getResult(null).getItem(), entity.getStack(AlloySmelterInventorySlots.THIRD.value).getCount() + 1 ) ); - entity.setLastRecipe(recipeFromInventory.get()); + entity.setLastRecipe(recipeFromInventoryOpt.get()); entity.resetProgress(); } @@ -264,17 +269,18 @@ private static boolean canInsertAmountIntoOutputSlot(SimpleInventory inventory) } public void dropExperienceForRecipesUsed(ServerPlayerEntity player) { - List> list = this.getRecipesUsedAndDropExperience(player.getServerWorld(), player.getPos()); - player.unlockRecipes(list); + List> recipes = this.getRecipesUsedAndDropExperience(player.getServerWorld(), player.getPos()); + player.unlockRecipes(recipes); this.recipesUsed.clear(); } -public List> getRecipesUsedAndDropExperience(ServerWorld world, Vec3d pos) { - ArrayList> list = Lists.newArrayList(); +@SuppressWarnings("unchecked") +public List> getRecipesUsedAndDropExperience(ServerWorld world, Vec3d pos) { + ArrayList> list = Lists.newArrayList(); for (Object2IntMap.Entry entry : this.recipesUsed.object2IntEntrySet()) { world.getRecipeManager().get((Identifier)entry.getKey()).ifPresent(recipe -> { - list.add((Recipe)recipe); - AlloySmelterEntity.dropExperience(world, pos, entry.getIntValue(), ((AlloySmelterRecipe)recipe).getExperience()); + list.add((RecipeEntry)recipe); + AlloySmelterEntity.dropExperience(world, pos, entry.getIntValue(), ((RecipeEntry)recipe).value().getExperience()); }); } return list; diff --git a/src/main/java/net/stal/alloys/datagen/StalAlloysRecipeProvider.java b/src/main/java/net/stal/alloys/datagen/StalAlloysRecipeProvider.java index 5a6ce24..136ecc4 100644 --- a/src/main/java/net/stal/alloys/datagen/StalAlloysRecipeProvider.java +++ b/src/main/java/net/stal/alloys/datagen/StalAlloysRecipeProvider.java @@ -1,11 +1,10 @@ package net.stal.alloys.datagen; import java.util.List; -import java.util.function.Consumer; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; -import net.minecraft.data.server.recipe.RecipeJsonProvider; +import net.minecraft.data.server.recipe.RecipeExporter; import net.minecraft.data.server.recipe.ShapedRecipeJsonBuilder; import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder; import net.minecraft.item.ItemConvertible; @@ -28,7 +27,7 @@ public StalAlloysRecipeProvider(FabricDataOutput output) { } @Override - public void generate(Consumer exporter) { + public void generate(RecipeExporter exporter) { // Smelting recipes offerSmelting(exporter, CHROMIUM_SMELTABLES, RecipeCategory.MISC, StalAlloysItems.CHROMIUM_INGOT, 1.0F, 360, "chromium_ingot"); offerSmelting(exporter, NICKEL_SMELTABLES, RecipeCategory.MISC, StalAlloysItems.NICKEL_INGOT, 1.0F, 200, "nickel_ingot"); diff --git a/src/main/java/net/stal/alloys/event/KeyInputHandler.java b/src/main/java/net/stal/alloys/event/KeyInputHandler.java deleted file mode 100644 index 0e49076..0000000 --- a/src/main/java/net/stal/alloys/event/KeyInputHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.stal.alloys.event; - -import org.lwjgl.glfw.GLFW; - -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.stal.alloys.StalAlloys; -import net.stal.alloys.networking.StalAlloysMessages; - -public class KeyInputHandler { - public static final String KEY_CATEGORY_EXAMPLE = "key.category." + StalAlloys.MOD_ID + ".example"; - public static final String KEY_EXAMPLE = "key." + StalAlloys.MOD_ID + ".example"; - - public static KeyBinding exampleKey; - - public static void registerKeyInputs() { - StalAlloys.LOGGER.debug("Registering key inputs for " + StalAlloys.MOD_ID); - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (exampleKey.wasPressed()) { - ClientPlayNetworking.send(StalAlloysMessages.C2S_EXAMPLE_ID, PacketByteBufs.create()); - } - }); - } - - public static void registerKeyBindings() { - exampleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding( - KEY_EXAMPLE, // Translatable Key Name - InputUtil.Type.KEYSYM, // Key Type - GLFW.GLFW_KEY_O, // Default Key Literal (i.e. the "o" key on the keyboard) - KEY_CATEGORY_EXAMPLE // Key Category - )); - - registerKeyInputs(); - } -} diff --git a/src/main/java/net/stal/alloys/networking/StalAlloysMessages.java b/src/main/java/net/stal/alloys/networking/StalAlloysMessages.java deleted file mode 100644 index 0cee374..0000000 --- a/src/main/java/net/stal/alloys/networking/StalAlloysMessages.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.stal.alloys.networking; - -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.util.Identifier; -import net.stal.alloys.StalAlloys; -import net.stal.alloys.networking.packet.*; - -public class StalAlloysMessages { - public static final Identifier C2S_EXAMPLE_ID = new Identifier(StalAlloys.MOD_ID, "example"); - public static final Identifier S2C_EXAMPLE_ID = new Identifier(StalAlloys.MOD_ID, "example_sync"); - - /** - * Register Client to Server packets - */ - public static void registerC2SPackets() { - StalAlloys.LOGGER.debug("Registering Client to Server packets for " + StalAlloys.MOD_ID); - - ServerPlayNetworking.registerGlobalReceiver(C2S_EXAMPLE_ID, ExampleC2SPacket::receive); - } - - - /** - * Register Server to Client packets - */ - public static void registerS2CPackets() { - StalAlloys.LOGGER.debug("Registering Server to Client packets for " + StalAlloys.MOD_ID); - - ClientPlayNetworking.registerGlobalReceiver(S2C_EXAMPLE_ID, ExampleS2CPacket::recieve); - } -} diff --git a/src/main/java/net/stal/alloys/networking/packet/ExampleC2SPacket.java b/src/main/java/net/stal/alloys/networking/packet/ExampleC2SPacket.java deleted file mode 100644 index e14b9f4..0000000 --- a/src/main/java/net/stal/alloys/networking/packet/ExampleC2SPacket.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.stal.alloys.networking.packet; - -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -// import net.minecraft.text.Style; -// import net.minecraft.text.Text; -// import net.minecraft.util.Formatting; -// import net.stal.alloys.util.ExamplePersistantData; -// import net.stal.alloys.util.IEntityDataSaver; - -public class ExampleC2SPacket { - public static void receive(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, - PacketByteBuf buf, PacketSender responseSender) { - // // Everything here happens on the server - // ExamplePersistantData.addData(((IEntityDataSaver) player), 1); - - // // player.sendMessage(Text.literal("Add -> amount = 1").fillStyle(Style.EMPTY.withColor(Formatting.GRAY))); - // player.sendMessage(Text.literal("Example Data: " + ((IEntityDataSaver) player).getPersistantData().getInt(ExamplePersistantData.DATA_ID)).fillStyle(Style.EMPTY.withColor(Formatting.GOLD)), true); - - // // Sync data with server - // ExamplePersistantData.syncExamplePersistantData(((IEntityDataSaver) player).getPersistantData().getInt(ExamplePersistantData.DATA_ID), player); - } -} diff --git a/src/main/java/net/stal/alloys/networking/packet/ExampleS2CPacket.java b/src/main/java/net/stal/alloys/networking/packet/ExampleS2CPacket.java deleted file mode 100644 index 9826874..0000000 --- a/src/main/java/net/stal/alloys/networking/packet/ExampleS2CPacket.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.stal.alloys.networking.packet; - -import net.fabricmc.fabric.api.networking.v1.PacketSender; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.PacketByteBuf; -import net.stal.alloys.util.ExamplePersistantData; -import net.stal.alloys.util.IEntityDataSaver; - -public class ExampleS2CPacket { - public static void recieve(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { - ((IEntityDataSaver) client.player).getPersistantData().putInt(ExamplePersistantData.DATA_ID, buf.readInt()); - } -} diff --git a/src/main/java/net/stal/alloys/recipe/AlloySmelterRecipe.java b/src/main/java/net/stal/alloys/recipe/AlloySmelterRecipe.java index cb240c6..14a453b 100644 --- a/src/main/java/net/stal/alloys/recipe/AlloySmelterRecipe.java +++ b/src/main/java/net/stal/alloys/recipe/AlloySmelterRecipe.java @@ -1,26 +1,26 @@ package net.stal.alloys.recipe; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.inventory.SimpleInventory; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; -import net.minecraft.recipe.Ingredient; import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.recipe.*; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.collection.DefaultedList; import net.minecraft.world.World; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.dynamic.Codecs; + +import java.util.List; public class AlloySmelterRecipe implements Recipe { - private final Identifier mID; private final ItemStack mOutput; private final int mCookingTime; private final int mExperience; - private final DefaultedList mRecipeItems; + private final List mRecipeItems; private enum AlloySmelterRecipeAttributes { INGREDIENTS("ingredients"), @@ -37,8 +37,7 @@ private AlloySmelterRecipeAttributes(String value) { private static final int mNumberOfInputs = 2; // private static final int mNumberOfOutputs = 1; - public AlloySmelterRecipe(Identifier id, ItemStack output, DefaultedList recipeItems, int cookingtime, int experience) { - mID = id; + public AlloySmelterRecipe(ItemStack output, List recipeItems, int cookingtime, int experience) { mOutput = output; mRecipeItems = recipeItems; mCookingTime = cookingtime; @@ -70,7 +69,7 @@ public boolean fits(int width, int height) { } @Override - public ItemStack getOutput(DynamicRegistryManager dynamicRegistryManager) { + public ItemStack getResult(DynamicRegistryManager dynamicRegistryManager) { return mOutput.copy(); } @@ -82,11 +81,6 @@ public int getExperience() { return mExperience; } - @Override - public Identifier getId() { - return mID; - } - @Override public RecipeSerializer getSerializer() { return Serializer.INSTANCE; @@ -107,23 +101,21 @@ public static class Serializer implements RecipeSerializer { public static final Serializer INSTANCE = new Serializer(); public static final String ID = "alloy_smelter"; // name given in the json file - @Override - public AlloySmelterRecipe read(Identifier id, JsonObject json) { - DefaultedList inputs = DefaultedList.ofSize(mNumberOfInputs, Ingredient.EMPTY); - ItemStack output = ShapedRecipe.outputFromJson(JsonHelper.getObject(json, AlloySmelterRecipeAttributes.RESULT.value)); - JsonArray ingredients = JsonHelper.getArray(json, AlloySmelterRecipeAttributes.INGREDIENTS.value); - int cookingtime = JsonHelper.getInt(json, AlloySmelterRecipeAttributes.COOKINGTIME.value); - int experience = JsonHelper.getInt(json, AlloySmelterRecipeAttributes.EXPERIENCE.value); - - for (int i = 0; i < inputs.size(); i++) { - inputs.set(i, Ingredient.fromJson(ingredients.get(i))); - } - - return new AlloySmelterRecipe(id, output, inputs, cookingtime, experience); + public static final Codec CODEC = RecordCodecBuilder.create(in -> in.group( + RecipeCodecs.CRAFTING_RESULT.fieldOf(AlloySmelterRecipeAttributes.RESULT.value).forGetter(r -> r.mOutput), + validateAmount(Ingredient.DISALLOW_EMPTY_CODEC, mNumberOfInputs).fieldOf(AlloySmelterRecipeAttributes.INGREDIENTS.value).forGetter(AlloySmelterRecipe::getIngredients), + Codecs.NONNEGATIVE_INT.fieldOf(AlloySmelterRecipeAttributes.COOKINGTIME.value).forGetter(AlloySmelterRecipe::getCookingTime), + Codecs.NONNEGATIVE_INT.fieldOf(AlloySmelterRecipeAttributes.EXPERIENCE.value).forGetter(AlloySmelterRecipe::getExperience) + ).apply(in, AlloySmelterRecipe::new)); + + private static Codec> validateAmount(Codec delegate, int max) { + return Codecs.validate(Codecs.validate( + delegate.listOf(), list -> list.size() > max ? DataResult.error(() -> "Recipe has too many ingredients!") : DataResult.success(list) + ), list -> list.isEmpty() ? DataResult.error(() -> "Recipe has no ingredients!") : DataResult.success(list)); } @Override - public AlloySmelterRecipe read(Identifier id, PacketByteBuf buf) { + public AlloySmelterRecipe read(PacketByteBuf buf) { DefaultedList inputs = DefaultedList.ofSize(buf.readInt(), Ingredient.EMPTY); int cookingtime = buf.readInt(); int experience = buf.readInt(); @@ -132,7 +124,7 @@ public AlloySmelterRecipe read(Identifier id, PacketByteBuf buf) { inputs.set(i, Ingredient.fromPacket(buf)); } - return new AlloySmelterRecipe(id, /* output --> */ buf.readItemStack(), inputs, cookingtime, experience); + return new AlloySmelterRecipe(/* output --> */ buf.readItemStack(), inputs, cookingtime, experience); } @Override @@ -143,12 +135,15 @@ public void write(PacketByteBuf buf, AlloySmelterRecipe recipe) { ingredient.write(buf); } - buf.writeItemStack(recipe.getOutput(null)); + buf.writeItemStack(recipe.getResult(null)); buf.writeInt(recipe.getCookingTime()); buf.writeInt(recipe.getExperience()); } - + @Override + public Codec codec() { + return CODEC; + } } } diff --git a/src/main/java/net/stal/alloys/screen/AlloySmelterScreen.java b/src/main/java/net/stal/alloys/screen/AlloySmelterScreen.java index dcde84e..e3ce3c0 100644 --- a/src/main/java/net/stal/alloys/screen/AlloySmelterScreen.java +++ b/src/main/java/net/stal/alloys/screen/AlloySmelterScreen.java @@ -1,7 +1,6 @@ package net.stal.alloys.screen; import com.mojang.blaze3d.systems.RenderSystem; - import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.GameRenderer; @@ -76,7 +75,7 @@ private void renderProgressionArrow(DrawContext context, int x, int y) { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - renderBackground(context); + renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); drawMouseoverTooltip(context, mouseX, mouseY); } diff --git a/src/main/java/net/stal/alloys/util/ExamplePersistantData.java b/src/main/java/net/stal/alloys/util/ExamplePersistantData.java deleted file mode 100644 index 1ccbd6a..0000000 --- a/src/main/java/net/stal/alloys/util/ExamplePersistantData.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.stal.alloys.util; - -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.server.network.ServerPlayerEntity; -import net.stal.alloys.networking.StalAlloysMessages; - -public class ExamplePersistantData { - public static final String DATA_ID = "example_data"; - - public static int addData(IEntityDataSaver player, int amount) { - NbtCompound nbt = player.getPersistantData(); - - // Get and mutate the data (add) - int data = nbt.getInt(DATA_ID); - - if (data + amount > 10) { - data = 10; - } else { - data += amount; - } - - nbt.putInt(DATA_ID, data); - - syncExamplePersistantData(data, ((ServerPlayerEntity) player)); - - return data; - } - - public static int removeData(IEntityDataSaver player, int amount) { - NbtCompound nbt = player.getPersistantData(); - - // Get and mutate the data (remove) - int data = nbt.getInt(DATA_ID); - - if (data - amount < 0) { - data = 0; - } else { - data -= amount; - } - - nbt.putInt(DATA_ID, data); - - syncExamplePersistantData(data, ((ServerPlayerEntity) player)); - - return data; - } - - public static void syncExamplePersistantData(int data, ServerPlayerEntity player) { - PacketByteBuf buf = PacketByteBufs.create(); - - buf.writeInt(data); - - ServerPlayNetworking.send(player, StalAlloysMessages.S2C_EXAMPLE_ID, buf); - } -}