From 2e05cd7b700ed29a4f010791dbac542636a26c3d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 15 Sep 2024 14:23:14 +0200 Subject: [PATCH] bunch of work --- .../java/de/ellpeck/prettypipes/Registry.java | 87 ++++++++++--------- .../java/de/ellpeck/prettypipes/Utility.java | 8 +- .../jei/CraftingModuleTransferHandler.java | 21 ++--- .../jei/CraftingTerminalTransferHandler.java | 2 +- .../compat/jei/JEIPrettyPipesPlugin.java | 8 +- .../prettypipes/entities/PipeFrameEntity.java | 13 +-- .../ellpeck/prettypipes/items/ModuleItem.java | 9 +- .../prettypipes/items/PipeFrameItem.java | 9 +- .../ellpeck/prettypipes/items/WrenchItem.java | 8 +- .../de/ellpeck/prettypipes/misc/Events.java | 4 +- .../ellpeck/prettypipes/misc/ItemFilter.java | 9 +- .../misc/ModuleClearingRecipe.java | 21 ++--- .../ellpeck/prettypipes/misc/PlayerPrefs.java | 1 + .../prettypipes/network/NetworkEdge.java | 14 +-- .../prettypipes/network/NetworkLocation.java | 12 +-- .../prettypipes/network/NetworkLock.java | 18 ++-- .../ellpeck/prettypipes/network/PipeItem.java | 28 +++--- .../prettypipes/network/PipeNetwork.java | 14 +-- .../packets/PacketItemEnterPipe.java | 2 +- .../prettypipes/pipe/PipeBlockEntity.java | 31 +++---- .../pipe/containers/AbstractPipeGui.java | 4 +- .../pressurizer/PressurizerBlockEntity.java | 21 ++--- .../pressurizer/PressurizerGui.java | 2 +- .../terminal/CraftingTerminalBlockEntity.java | 4 +- .../terminal/ItemTerminalBlock.java | 22 +++-- .../terminal/ItemTerminalBlockEntity.java | 15 ++-- .../containers/CraftingTerminalContainer.java | 4 +- .../containers/CraftingTerminalGui.java | 4 +- .../terminal/containers/ItemTerminalGui.java | 10 ++- 29 files changed, 211 insertions(+), 194 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/Registry.java b/src/main/java/de/ellpeck/prettypipes/Registry.java index 572204c..38119df 100644 --- a/src/main/java/de/ellpeck/prettypipes/Registry.java +++ b/src/main/java/de/ellpeck/prettypipes/Registry.java @@ -68,24 +68,26 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour.Properties; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod.EventBusSubscriber; -import net.neoforged.fml.common.Mod.EventBusSubscriber.Bus; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.neoforged.neoforge.capabilities.BlockCapability; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.registries.RegisterEvent; import java.util.Comparator; import java.util.Locale; import java.util.function.BiFunction; +import static net.neoforged.fml.common.EventBusSubscriber.*; + @EventBusSubscriber(bus = Bus.MOD) public final class Registry { - public static BlockCapability pipeConnectableCapability = BlockCapability.createSided(new ResourceLocation(PrettyPipes.ID, "pipe_connectable"), IPipeConnectable.class); + public static BlockCapability pipeConnectableCapability = BlockCapability.createSided(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_connectable"), IPipeConnectable.class); public static Item wrenchItem; public static Item pipeFrameItem; @@ -119,19 +121,19 @@ public final class Registry { @SubscribeEvent public static void register(RegisterEvent event) { event.register(Registries.BLOCK, h -> { - h.register(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeBlock = new PipeBlock(Properties.of().strength(2).sound(SoundType.STONE).noOcclusion())); - h.register(new ResourceLocation(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalBlock = new ItemTerminalBlock(Properties.of().strength(3).sound(SoundType.STONE))); - h.register(new ResourceLocation(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalBlock = new CraftingTerminalBlock(Properties.of().strength(3).sound(SoundType.STONE))); - h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlock = new PressurizerBlock(Properties.of().strength(3).sound(SoundType.STONE))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe"), Registry.pipeBlock = new PipeBlock(Properties.of().strength(2).sound(SoundType.STONE).noOcclusion())); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalBlock = new ItemTerminalBlock(Properties.of().strength(3).sound(SoundType.STONE))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalBlock = new CraftingTerminalBlock(Properties.of().strength(3).sound(SoundType.STONE))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlock = new PressurizerBlock(Properties.of().strength(3).sound(SoundType.STONE))); }); event.register(Registries.ITEM, h -> { - h.register(new ResourceLocation(PrettyPipes.ID, "wrench"), Registry.wrenchItem = new WrenchItem()); - h.register(new ResourceLocation(PrettyPipes.ID, "blank_module"), new Item(new Item.Properties())); - h.register(new ResourceLocation(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameItem = new PipeFrameItem()); - h.register(new ResourceLocation(PrettyPipes.ID, "stack_size_module"), new StackSizeModuleItem()); - h.register(new ResourceLocation(PrettyPipes.ID, "redstone_module"), new RedstoneModuleItem()); - h.register(new ResourceLocation(PrettyPipes.ID, "filter_increase_modifier"), new FilterIncreaseModuleItem()); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "wrench"), Registry.wrenchItem = new WrenchItem()); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "blank_module"), new Item(new Item.Properties())); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameItem = new PipeFrameItem()); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "stack_size_module"), new StackSizeModuleItem()); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "redstone_module"), new RedstoneModuleItem()); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "filter_increase_modifier"), new FilterIncreaseModuleItem()); Registry.registerTieredModule(h, "extraction_module", ExtractionModuleItem::new); Registry.registerTieredModule(h, "filter_module", FilterModuleItem::new); @@ -143,11 +145,11 @@ public final class Registry { for (var type : ItemEquality.Type.values()) { var name = type.name().toLowerCase(Locale.ROOT) + "_filter_modifier"; - h.register(new ResourceLocation(PrettyPipes.ID, name), new FilterModifierModuleItem(name, type)); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, name), new FilterModifierModuleItem(name, type)); } for (var type : SortingModuleItem.Type.values()) { var name = type.name().toLowerCase(Locale.ROOT) + "_sorting_modifier"; - h.register(new ResourceLocation(PrettyPipes.ID, name), new SortingModuleItem(name, type)); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, name), new SortingModuleItem(name, type)); } BuiltInRegistries.BLOCK.entrySet().stream() @@ -156,20 +158,20 @@ public final class Registry { }); event.register(Registries.BLOCK_ENTITY_TYPE, h -> { - h.register(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeBlockEntity = BlockEntityType.Builder.of(PipeBlockEntity::new, Registry.pipeBlock).build(null)); - h.register(new ResourceLocation(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalBlockEntity = BlockEntityType.Builder.of(ItemTerminalBlockEntity::new, Registry.itemTerminalBlock).build(null)); - h.register(new ResourceLocation(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalBlockEntity = BlockEntityType.Builder.of(CraftingTerminalBlockEntity::new, Registry.craftingTerminalBlock).build(null)); - h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlockEntity = BlockEntityType.Builder.of(PressurizerBlockEntity::new, Registry.pressurizerBlock).build(null)); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe"), Registry.pipeBlockEntity = BlockEntityType.Builder.of(PipeBlockEntity::new, Registry.pipeBlock).build(null)); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalBlockEntity = BlockEntityType.Builder.of(ItemTerminalBlockEntity::new, Registry.itemTerminalBlock).build(null)); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalBlockEntity = BlockEntityType.Builder.of(CraftingTerminalBlockEntity::new, Registry.craftingTerminalBlock).build(null)); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlockEntity = BlockEntityType.Builder.of(PressurizerBlockEntity::new, Registry.pressurizerBlock).build(null)); }); event.register(Registries.ENTITY_TYPE, h -> - h.register(new ResourceLocation(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameEntity = EntityType.Builder.of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame"))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameEntity = EntityType.Builder.of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame"))); event.register(Registries.MENU, h -> { - h.register(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeContainer = IMenuTypeExtension.create((windowId, inv, data) -> new MainPipeContainer(Registry.pipeContainer, windowId, inv.player, data.readBlockPos()))); - h.register(new ResourceLocation(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalContainer = IMenuTypeExtension.create((windowId, inv, data) -> new ItemTerminalContainer(Registry.itemTerminalContainer, windowId, inv.player, data.readBlockPos()))); - h.register(new ResourceLocation(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalContainer = IMenuTypeExtension.create((windowId, inv, data) -> new CraftingTerminalContainer(Registry.craftingTerminalContainer, windowId, inv.player, data.readBlockPos()))); - h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerContainer = IMenuTypeExtension.create((windowId, inv, data) -> new PressurizerContainer(Registry.pressurizerContainer, windowId, inv.player, data.readBlockPos()))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe"), Registry.pipeContainer = IMenuTypeExtension.create((windowId, inv, data) -> new MainPipeContainer(Registry.pipeContainer, windowId, inv.player, data.readBlockPos()))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "item_terminal"), Registry.itemTerminalContainer = IMenuTypeExtension.create((windowId, inv, data) -> new ItemTerminalContainer(Registry.itemTerminalContainer, windowId, inv.player, data.readBlockPos()))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "crafting_terminal"), Registry.craftingTerminalContainer = IMenuTypeExtension.create((windowId, inv, data) -> new CraftingTerminalContainer(Registry.craftingTerminalContainer, windowId, inv.player, data.readBlockPos()))); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pressurizer"), Registry.pressurizerContainer = IMenuTypeExtension.create((windowId, inv, data) -> new PressurizerContainer(Registry.pressurizerContainer, windowId, inv.player, data.readBlockPos()))); Registry.extractionModuleContainer = Registry.registerPipeContainer(h, "extraction_module"); Registry.filterModuleContainer = Registry.registerPipeContainer(h, "filter_module"); @@ -181,7 +183,7 @@ public final class Registry { }); event.register(BuiltInRegistries.CREATIVE_MODE_TAB.key(), h -> { - h.register(new ResourceLocation(PrettyPipes.ID, "tab"), CreativeModeTab.builder() + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "tab"), CreativeModeTab.builder() .title(Component.translatable("item_group." + PrettyPipes.ID + ".tab")) .icon(() -> new ItemStack(Registry.wrenchItem)) .displayItems((params, output) -> BuiltInRegistries.ITEM.entrySet().stream() @@ -192,7 +194,7 @@ public final class Registry { }); event.register(Registries.RECIPE_SERIALIZER, h -> { - h.register(new ResourceLocation(PrettyPipes.ID, "module_clearing"), ModuleClearingRecipe.SERIALIZER); + h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "module_clearing"), ModuleClearingRecipe.SERIALIZER); }); } @@ -207,7 +209,7 @@ public final class Registry { } @SubscribeEvent - public static void registerPayloads(final RegisterPayloadHandlerEvent event) { + public static void registerPayloads(final RegisterPayloadHandlersEvent event) { var registrar = event.registrar(PrettyPipes.ID); registrar.play(PacketItemEnterPipe.ID, PacketItemEnterPipe::new, PacketItemEnterPipe::onMessage); registrar.play(PacketButton.ID, PacketButton::new, PacketButton::onMessage); @@ -224,13 +226,13 @@ public final class Registry { var moduleStack = tile.modules.getStackInSlot(moduleIndex); return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, moduleIndex); }); - helper.register(new ResourceLocation(PrettyPipes.ID, name), type); + helper.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, name), type); return type; } private static void registerTieredModule(RegisterEvent.RegisterHelper helper, String name, BiFunction item) { for (var tier : ModuleTier.values()) - helper.register(new ResourceLocation(PrettyPipes.ID, tier.name().toLowerCase(Locale.ROOT) + "_" + name), item.apply(name, tier)); + helper.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, tier.name().toLowerCase(Locale.ROOT) + "_" + name), item.apply(name, tier)); } @EventBusSubscriber(bus = Bus.MOD, value = Dist.CLIENT) @@ -240,18 +242,21 @@ public final class Registry { public static void setup(FMLClientSetupEvent event) { BlockEntityRenderers.register(Registry.pipeBlockEntity, PipeRenderer::new); EntityRenderers.register(Registry.pipeFrameEntity, PipeFrameRenderer::new); + } - MenuScreens.register(Registry.pipeContainer, MainPipeGui::new); - MenuScreens.register(Registry.itemTerminalContainer, ItemTerminalGui::new); - MenuScreens.register(Registry.pressurizerContainer, PressurizerGui::new); - MenuScreens.register(Registry.craftingTerminalContainer, CraftingTerminalGui::new); - MenuScreens.register(Registry.extractionModuleContainer, ExtractionModuleGui::new); - MenuScreens.register(Registry.filterModuleContainer, FilterModuleGui::new); - MenuScreens.register(Registry.retrievalModuleContainer, RetrievalModuleGui::new); - MenuScreens.register(Registry.stackSizeModuleContainer, StackSizeModuleGui::new); - MenuScreens.register(Registry.filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); - MenuScreens.register(Registry.craftingModuleContainer, CraftingModuleGui::new); - MenuScreens.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new); + @SubscribeEvent + public static void registerMenuScreens(RegisterMenuScreensEvent event) { + event.register(Registry.pipeContainer, MainPipeGui::new); + event.register(Registry.itemTerminalContainer, ItemTerminalGui::new); + event.register(Registry.pressurizerContainer, PressurizerGui::new); + event.register(Registry.craftingTerminalContainer, CraftingTerminalGui::new); + event.register(Registry.extractionModuleContainer, ExtractionModuleGui::new); + event.register(Registry.filterModuleContainer, FilterModuleGui::new); + event.register(Registry.retrievalModuleContainer, RetrievalModuleGui::new); + event.register(Registry.stackSizeModuleContainer, StackSizeModuleGui::new); + event.register(Registry.filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); + event.register(Registry.craftingModuleContainer, CraftingModuleGui::new); + event.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new); } } diff --git a/src/main/java/de/ellpeck/prettypipes/Utility.java b/src/main/java/de/ellpeck/prettypipes/Utility.java index a762b67..857f94a 100644 --- a/src/main/java/de/ellpeck/prettypipes/Utility.java +++ b/src/main/java/de/ellpeck/prettypipes/Utility.java @@ -5,6 +5,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; @@ -30,6 +31,7 @@ import java.util.Collection; import java.util.List; import java.util.function.Function; +@SuppressWarnings("ALL") public final class Utility { public static T getBlockEntity(Class type, BlockGetter world, BlockPos pos) { @@ -104,10 +106,10 @@ public final class Utility { return ItemStack.EMPTY; } - public static ListTag serializeAll(Collection> items) { + public static ListTag serializeAll(HolderLookup.Provider provider, Collection> items) { var list = new ListTag(); for (INBTSerializable item : items) - list.add(item.serializeNBT()); + list.add(item.serializeNBT(provider)); return list; } @@ -143,5 +145,7 @@ public final class Utility { public interface IMergeItemStack { boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection); + } + } diff --git a/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java b/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java index aba67b1..7cde3cf 100644 --- a/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java +++ b/src/main/java/de/ellpeck/prettypipes/compat/jei/CraftingModuleTransferHandler.java @@ -4,25 +4,21 @@ import de.ellpeck.prettypipes.Registry; import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.packets.PacketCraftingModuleTransfer; import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; -import mezz.jei.api.constants.RecipeTypes; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; import mezz.jei.api.recipe.transfer.IRecipeTransferError; -import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; +import mezz.jei.api.recipe.transfer.IUniversalRecipeTransferHandler; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.CraftingRecipe; -import net.minecraft.world.item.crafting.RecipeHolder; import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Optional; -public class CraftingModuleTransferHandler implements IRecipeTransferHandler> { +public class CraftingModuleTransferHandler implements IUniversalRecipeTransferHandler { @Override public Class getContainerClass() { @@ -35,21 +31,16 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler> getRecipeType() { - return RecipeTypes.CRAFTING; - } - - @Override - public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, RecipeHolder recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) { + public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, Object recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) { if (!doTransfer) return null; var inputs = new ArrayList(); var outputs = new ArrayList(); - for (var entry : slots.getSlotViews()) { + for (var entry : recipeSlots.getSlotViews()) { var allIngredients = entry.getIngredients(VanillaTypes.ITEM_STACK).toList(); if (allIngredients.isEmpty()) continue; - var remain = allIngredients.get(0).copy(); + var remain = allIngredients.getFirst().copy(); var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs; for (var stack : toAdd) { if (ItemEquality.compareItems(stack, remain)) { @@ -63,7 +54,7 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler tooltip, TooltipFlag flagIn) { - super.appendHoverText(stack, worldIn, tooltip, flagIn); - Utility.addTooltip(this.name, tooltip); + public void appendHoverText(ItemStack pStack, TooltipContext pContext, List pTooltipComponents, TooltipFlag pTooltipFlag) { + super.appendHoverText(pStack, pContext, pTooltipComponents, pTooltipFlag); + Utility.addTooltip(this.name, pTooltipComponents); } @Override @@ -109,4 +107,5 @@ public abstract class ModuleItem extends Item implements IModule { public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) { return null; } + } diff --git a/src/main/java/de/ellpeck/prettypipes/items/PipeFrameItem.java b/src/main/java/de/ellpeck/prettypipes/items/PipeFrameItem.java index 7ff2576..f2d1a90 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/PipeFrameItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/PipeFrameItem.java @@ -15,9 +15,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; -import net.minecraft.world.level.Level; -import javax.annotation.Nullable; import java.util.List; public class PipeFrameItem extends Item { @@ -64,8 +62,9 @@ public class PipeFrameItem extends Item { } @Override - public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List tooltip, TooltipFlag flagIn) { - super.appendHoverText(stack, worldIn, tooltip, flagIn); - Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), tooltip); + public void appendHoverText(ItemStack pStack, TooltipContext pContext, List pTooltipComponents, TooltipFlag pTooltipFlag) { + super.appendHoverText(pStack, pContext, pTooltipComponents, pTooltipFlag); + Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), pTooltipComponents); } + } diff --git a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java index b0bfd1b..2bc84d6 100644 --- a/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java +++ b/src/main/java/de/ellpeck/prettypipes/items/WrenchItem.java @@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeBlockEntity; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundEvents; @@ -17,7 +18,6 @@ import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; @@ -107,8 +107,8 @@ public class WrenchItem extends Item { } @Override - public void appendHoverText(ItemStack stack, Level worldIn, List tooltip, TooltipFlag flagIn) { - Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), tooltip); + public void appendHoverText(ItemStack pStack, TooltipContext pContext, List pTooltipComponents, TooltipFlag pTooltipFlag) { + Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), pTooltipComponents); } @Override @@ -122,7 +122,7 @@ public class WrenchItem extends Item { } @Override - public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { + public boolean supportsEnchantment(ItemStack stack, Holder enchantment) { return enchantment == Enchantments.SILK_TOUCH; } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/Events.java b/src/main/java/de/ellpeck/prettypipes/misc/Events.java index 9c2fd7f..5fc373a 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/Events.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/Events.java @@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.network.PipeNetwork; import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.event.server.ServerStartingEvent; import java.io.IOException; @@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -@Mod.EventBusSubscriber +@EventBusSubscriber public final class Events { @SubscribeEvent diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java index a3c1a63..368d577 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ItemFilter.java @@ -10,6 +10,7 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.Slot; @@ -130,16 +131,16 @@ public class ItemFilter extends ItemStackHandler { } @Override - public CompoundTag serializeNBT() { - var nbt = super.serializeNBT(); + public CompoundTag serializeNBT(HolderLookup.Provider provider) { + var nbt = super.serializeNBT(provider); if (this.canModifyWhitelist) nbt.putBoolean("whitelist", this.isWhitelist); return nbt; } @Override - public void deserializeNBT(CompoundTag nbt) { - super.deserializeNBT(nbt); + public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { + super.deserializeNBT(provider, nbt); if (this.canModifyWhitelist) this.isWhitelist = nbt.getBoolean("whitelist"); } diff --git a/src/main/java/de/ellpeck/prettypipes/misc/ModuleClearingRecipe.java b/src/main/java/de/ellpeck/prettypipes/misc/ModuleClearingRecipe.java index 21f7bfc..2a350f2 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/ModuleClearingRecipe.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/ModuleClearingRecipe.java @@ -1,9 +1,7 @@ package de.ellpeck.prettypipes.misc; import de.ellpeck.prettypipes.items.IModule; -import net.minecraft.core.RegistryAccess; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.core.HolderLookup; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.*; import net.minecraft.world.level.Level; @@ -17,9 +15,10 @@ public class ModuleClearingRecipe extends CustomRecipe { } @Override - public boolean matches(CraftingContainer container, Level level) { + public boolean matches(CraftingInput container, Level level) { var foundModule = false; - for (var stack : container.getItems()) { + for (var i = 0; i < container.size(); i++) { + var stack = container.getItem(i); if (!foundModule && stack.getItem() instanceof IModule) { foundModule = true; } else if (!stack.isEmpty()) { @@ -30,11 +29,13 @@ public class ModuleClearingRecipe extends CustomRecipe { } @Override - public ItemStack assemble(CraftingContainer container, RegistryAccess access) { - var module = container.getItems().stream().filter(i -> i.getItem() instanceof IModule).findFirst().orElse(ItemStack.EMPTY); - if (!module.isEmpty()) - module = new ItemStack(module.getItem()); - return module; + public ItemStack assemble(CraftingInput container, HolderLookup.Provider pRegistries) { + for (var i = 0; i < container.size(); i++) { + var stack = container.getItem(i); + if (stack.getItem() instanceof IModule) + return new ItemStack(stack.getItem()); + } + return ItemStack.EMPTY; } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/misc/PlayerPrefs.java b/src/main/java/de/ellpeck/prettypipes/misc/PlayerPrefs.java index 6181a7a..96235bc 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/PlayerPrefs.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/PlayerPrefs.java @@ -50,4 +50,5 @@ public class PlayerPrefs { var location = Minecraft.getInstance().gameDirectory; return new File(location, PrettyPipes.ID + "prefs"); } + } diff --git a/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java b/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java index 754edca..c52d435 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java +++ b/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java @@ -1,6 +1,7 @@ package de.ellpeck.prettypipes.network; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtUtils; @@ -18,20 +19,20 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable public NetworkEdge() { } - public NetworkEdge(CompoundTag nbt) { - this.deserializeNBT(nbt); + public NetworkEdge(HolderLookup.Provider provider, CompoundTag nbt) { + this.deserializeNBT(provider, nbt); } public BlockPos getStartPipe() { - return this.pipes.get(0); + return this.pipes.getFirst(); } public BlockPos getEndPipe() { - return this.pipes.get(this.pipes.size() - 1); + return this.pipes.getLast(); } @Override - public CompoundTag serializeNBT() { + public CompoundTag serializeNBT(HolderLookup.Provider provider) { var nbt = new CompoundTag(); var list = new ListTag(); for (var pos : this.pipes) @@ -41,10 +42,11 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable } @Override - public void deserializeNBT(CompoundTag nbt) { + public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { this.pipes.clear(); var list = nbt.getList("pipes", Tag.TAG_COMPOUND); for (var i = 0; i < list.size(); i++) this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i))); } + } diff --git a/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java b/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java index 5f22d9b..3a2fc77 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java +++ b/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java @@ -3,6 +3,7 @@ package de.ellpeck.prettypipes.network; import de.ellpeck.prettypipes.misc.ItemEquality; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.world.item.ItemStack; @@ -28,8 +29,8 @@ public class NetworkLocation implements INBTSerializable { this.direction = direction; } - public NetworkLocation(CompoundTag nbt) { - this.deserializeNBT(nbt); + public NetworkLocation(HolderLookup.Provider provider, CompoundTag nbt) { + this.deserializeNBT(provider, nbt); } public List getStackSlots(Level world, ItemStack stack, ItemEquality... equalityTypes) { @@ -91,7 +92,7 @@ public class NetworkLocation implements INBTSerializable { } @Override - public CompoundTag serializeNBT() { + public CompoundTag serializeNBT(HolderLookup.Provider provider) { var nbt = new CompoundTag(); nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos)); nbt.putInt("direction", this.direction.ordinal()); @@ -99,8 +100,9 @@ public class NetworkLocation implements INBTSerializable { } @Override - public void deserializeNBT(CompoundTag nbt) { - this.pipePos = NbtUtils.readBlockPos(nbt.getCompound("pipe_pos")); + public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { + this.pipePos = NbtUtils.readBlockPos(nbt, "pipe_pos").orElse(null); this.direction = Direction.values()[nbt.getInt("direction")]; } + } diff --git a/src/main/java/de/ellpeck/prettypipes/network/NetworkLock.java b/src/main/java/de/ellpeck/prettypipes/network/NetworkLock.java index 5f73b78..3790086 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/NetworkLock.java +++ b/src/main/java/de/ellpeck/prettypipes/network/NetworkLock.java @@ -1,5 +1,6 @@ package de.ellpeck.prettypipes.network; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.common.util.INBTSerializable; @@ -20,24 +21,24 @@ public class NetworkLock implements INBTSerializable { this.stack = stack; } - public NetworkLock(CompoundTag nbt) { - this.deserializeNBT(nbt); + public NetworkLock(HolderLookup.Provider provider, CompoundTag nbt) { + this.deserializeNBT(provider, nbt); } @Override - public CompoundTag serializeNBT() { + public CompoundTag serializeNBT(HolderLookup.Provider provider) { var nbt = new CompoundTag(); nbt.putUUID("id", this.lockId); - nbt.put("location", this.location.serializeNBT()); - nbt.put("stack", this.stack.save(new CompoundTag())); + nbt.put("location", this.location.serializeNBT(provider)); + nbt.put("stack", this.stack.save(provider)); return nbt; } @Override - public void deserializeNBT(CompoundTag nbt) { + public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { this.lockId = nbt.getUUID("id"); - this.location = new NetworkLocation(nbt.getCompound("location")); - this.stack = ItemStack.of(nbt.getCompound("stack")); + this.location = new NetworkLocation(provider, nbt.getCompound("location")); + this.stack = ItemStack.parseOptional(provider, nbt.getCompound("stack")); } @Override @@ -56,4 +57,5 @@ public class NetworkLock implements INBTSerializable { public String toString() { return "NetworkLock{" + "location=" + this.location.pipePos + ", stack=" + this.stack + '}'; } + } diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java index ef18b81..43ff11e 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java @@ -8,6 +8,7 @@ import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtUtils; @@ -33,7 +34,7 @@ import java.util.function.Consumer; public class PipeItem implements IPipeItem { - public static final ResourceLocation TYPE = new ResourceLocation(PrettyPipes.ID, "pipe_item"); + public static final ResourceLocation TYPE = ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_item"); public ItemStack stack; public float speed; @@ -63,10 +64,10 @@ public class PipeItem implements IPipeItem { this(PipeItem.TYPE, stack, speed); } - public PipeItem(ResourceLocation type, CompoundTag nbt) { + public PipeItem(HolderLookup.Provider provider, ResourceLocation type, CompoundTag nbt) { this.type = type; this.path = new ArrayList<>(); - this.deserializeNBT(nbt); + this.deserializeNBT(provider, nbt); } @Override @@ -221,12 +222,12 @@ public class PipeItem implements IPipeItem { } protected BlockPos getStartPipe() { - return this.path.get(0); + return this.path.getFirst(); } @Override public BlockPos getDestPipe() { - return this.path.get(this.path.size() - 1); + return this.path.getLast(); } @Override @@ -240,10 +241,10 @@ public class PipeItem implements IPipeItem { } @Override - public CompoundTag serializeNBT() { + public CompoundTag serializeNBT(HolderLookup.Provider provider) { var nbt = new CompoundTag(); nbt.putString("type", this.type.toString()); - nbt.put("stack", this.stack.save(new CompoundTag())); + nbt.put("stack", this.stack.save(provider)); nbt.putFloat("speed", this.speed); nbt.put("start_inv", NbtUtils.writeBlockPos(this.startInventory)); nbt.put("dest_inv", NbtUtils.writeBlockPos(this.destInventory)); @@ -261,12 +262,12 @@ public class PipeItem implements IPipeItem { } @Override - public void deserializeNBT(CompoundTag nbt) { - this.stack = ItemStack.of(nbt.getCompound("stack")); + public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { + this.stack = ItemStack.parseOptional(provider, nbt.getCompound("stack")); this.speed = nbt.getFloat("speed"); - this.startInventory = NbtUtils.readBlockPos(nbt.getCompound("start_inv")); - this.destInventory = NbtUtils.readBlockPos(nbt.getCompound("dest_inv")); - this.currGoalPos = NbtUtils.readBlockPos(nbt.getCompound("curr_goal")); + this.startInventory = NbtUtils.readBlockPos(nbt, "start_inv").orElse(null); + this.destInventory = NbtUtils.readBlockPos(nbt, "dest_inv").orElse(null); + this.currGoalPos = NbtUtils.readBlockPos(nbt, "curr_goal").orElse(null); this.retryOnObstruction = nbt.getBoolean("drop_on_obstruction"); this.currentTile = nbt.getInt("tile"); this.x = nbt.getFloat("x"); @@ -344,7 +345,7 @@ public class PipeItem implements IPipeItem { // add the single pipe twice if there's only one // this is a dirty hack, but it works fine so eh for (var i = 0; i < 2; i++) - ret.add(nodes.get(0)); + ret.add(nodes.getFirst()); return ret; } for (var i = 0; i < nodes.size() - 1; i++) { @@ -368,4 +369,5 @@ public class PipeItem implements IPipeItem { } return ret; } + } diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index a6f0490..e748aed 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -12,12 +12,14 @@ import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.Tag; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.saveddata.SavedData; @@ -60,17 +62,17 @@ public class PipeNetwork extends SavedData implements GraphListener(this.graph); } - public PipeNetwork(CompoundTag nbt) { + public PipeNetwork(CompoundTag nbt, HolderLookup.Provider provider) { this(); var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND); for (var i = 0; i < nodes.size(); i++) this.graph.addVertex(NbtUtils.readBlockPos(nodes.getCompound(i))); var edges = nbt.getList("edges", Tag.TAG_COMPOUND); for (var i = 0; i < edges.size(); i++) - this.addEdge(new NetworkEdge(edges.getCompound(i))); + this.addEdge(new NetworkEdge(provider, edges.getCompound(i))); for (var item : Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load)) this.pipeItems.put(item.getCurrentPipe(), item); - for (var lock : Utility.deserializeAll(nbt.getList("locks", Tag.TAG_COMPOUND), NetworkLock::new)) + for (var lock : Utility.deserializeAll(nbt.getList("locks", Tag.TAG_COMPOUND), t -> new NetworkLock(provider, t))) this.createNetworkLock(lock); } @@ -108,14 +110,14 @@ public class PipeNetwork extends SavedData implements GraphListener new NetworkLock(provider, l))); this.craftResultRequests.clear(); var results = compound.getList("craft_results", Tag.TAG_COMPOUND); for (var i = 0; i < results.size(); i++) { var nbt = results.getCompound(i); this.craftResultRequests.add(Pair.of( BlockPos.of(nbt.getLong("dest_pipe")), - ItemStack.of(nbt.getCompound("item")))); + ItemStack.parseOptional(provider, nbt.getCompound("item")))); } - super.load(compound); + super.loadAdditional(compound, provider); } @Override - public CompoundTag getUpdateTag() { + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { // sync pipe items on load - var nbt = this.saveWithoutMetadata(); + var nbt = this.saveWithoutMetadata(provider); nbt.put("items", Utility.serializeAll(this.getItems())); return nbt; } @Override - public void handleUpdateTag(CompoundTag nbt) { - this.load(nbt); + public void handleUpdateTag(CompoundTag nbt, HolderLookup.Provider provider) { + this.loadWithComponents(nbt, provider); var items = this.getItems(); items.clear(); items.addAll(Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load)); } @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { - this.load(pkt.getTag()); + public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) { + this.loadWithComponents(pkt.getTag(), provider); } public List getItems() { diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java index 2ac8025..a88cc3c 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/containers/AbstractPipeGui.java @@ -20,7 +20,7 @@ import java.util.List; public abstract class AbstractPipeGui> extends AbstractContainerScreen { - protected static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pipe.png"); + protected static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "textures/gui/pipe.png"); private final List tabs = new ArrayList<>(); private final ItemStack[] lastItems = new ItemStack[this.menu.tile.modules.getSlots()]; @@ -144,7 +144,7 @@ public abstract class AbstractPipeGui> extend return false; if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32) return false; - PacketDistributor.SERVER.noArg().send(new PacketButton(AbstractPipeGui.this.menu.tile.getBlockPos(), PacketButton.ButtonResult.PIPE_TAB, this.index)); + PacketDistributor.sendToServer(new PacketButton(AbstractPipeGui.this.menu.tile.getBlockPos(), PacketButton.ButtonResult.PIPE_TAB, this.index)); AbstractPipeGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1)); return true; } diff --git a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java index 08d29fc..69e5f5d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlockEntity.java @@ -8,6 +8,7 @@ import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.IPipeConnectable; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; @@ -51,30 +52,30 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider, } @Override - public void saveAdditional(CompoundTag compound) { - super.saveAdditional(compound); + public void saveAdditional(CompoundTag compound, HolderLookup.Provider provider) { + super.saveAdditional(compound, provider); compound.putInt("energy", this.getEnergy()); } @Override - public void load(CompoundTag nbt) { + public void loadAdditional(CompoundTag nbt, HolderLookup.Provider provider) { this.storage.setEnergyStored(nbt.getInt("energy")); - super.load(nbt); + super.loadAdditional(nbt, provider); } @Override - public CompoundTag getUpdateTag() { - return this.saveWithoutMetadata(); + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { + return this.saveWithoutMetadata(provider); } @Override - public void handleUpdateTag(CompoundTag tag) { - this.load(tag); + public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider provider) { + this.loadWithComponents(tag, provider); } @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { - this.load(pkt.getTag()); + public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) { + this.loadWithComponents(pkt.getTag(), provider); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerGui.java b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerGui.java index 4d07821..eeee780 100644 --- a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerGui.java +++ b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerGui.java @@ -9,7 +9,7 @@ import net.minecraft.world.entity.player.Inventory; public class PressurizerGui extends AbstractContainerScreen { - private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pressurizer.png"); + private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "textures/gui/pressurizer.png"); public PressurizerGui(PressurizerContainer screenContainer, Inventory inv, Component titleIn) { super(screenContainer, inv, titleIn); diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java index 9a7ea6e..1c581ef 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/CraftingTerminalBlockEntity.java @@ -16,10 +16,12 @@ import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.ItemStackHandler; @@ -98,7 +100,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity { List clients = new ArrayList<>(); for (var i = 0; i < this.ghostItems.getSlots(); i++) clients.add(new PacketGhostSlot.Entry(this.level, Collections.singletonList(this.ghostItems.getStackInSlot(i)))); - PacketDistributor.TRACKING_CHUNK.with(this.level.getChunkAt(this.getBlockPos())).send(new PacketGhostSlot(this.getBlockPos(), clients)); + PacketDistributor.sendToPlayersTrackingChunk((ServerLevel) this.level, new ChunkPos(this.getBlockPos()), new PacketGhostSlot(this.getBlockPos(), clients)); } } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java index 2ab7ae3..877e786 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlock.java @@ -7,12 +7,11 @@ import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.RenderShape; @@ -23,7 +22,6 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; -import javax.annotation.Nullable; import java.util.List; public class ItemTerminalBlock extends BaseEntityBlock { @@ -40,19 +38,19 @@ public class ItemTerminalBlock extends BaseEntityBlock { } @Override - public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) { - var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos); + protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) { + var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, pLevel, pPos); if (tile == null) return InteractionResult.PASS; var reason = tile.getInvalidTerminalReason(); if (reason != null) { - if (!worldIn.isClientSide) - player.sendSystemMessage(Component.translatable(reason).withStyle(ChatFormatting.RED)); + if (!pLevel.isClientSide) + pPlayer.sendSystemMessage(Component.translatable(reason).withStyle(ChatFormatting.RED)); return InteractionResult.SUCCESS; } - if (!worldIn.isClientSide) { - player.openMenu(tile, pos); - tile.updateItems(player); + if (!pLevel.isClientSide) { + pPlayer.openMenu(tile, pPos); + tile.updateItems(pPlayer); } return InteractionResult.SUCCESS; } @@ -79,8 +77,8 @@ public class ItemTerminalBlock extends BaseEntityBlock { } @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List tooltip, TooltipFlag flagIn) { - Utility.addTooltip(BuiltInRegistries.BLOCK.getKey(this).getPath(), tooltip); + public void appendHoverText(ItemStack pStack, Item.TooltipContext pContext, List pTooltipComponents, TooltipFlag pTooltipFlag) { + Utility.addTooltip(BuiltInRegistries.BLOCK.getKey(this).getPath(), pTooltipComponents); } @org.jetbrains.annotations.Nullable diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java index bd2ad98..e5e19f0 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/ItemTerminalBlockEntity.java @@ -17,6 +17,7 @@ import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; @@ -228,18 +229,18 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect } @Override - public void saveAdditional(CompoundTag compound) { - super.saveAdditional(compound); - compound.put("items", this.items.serializeNBT()); + public void saveAdditional(CompoundTag compound, HolderLookup.Provider pRegistries) { + super.saveAdditional(compound, pRegistries); + compound.put("items", this.items.serializeNBT(pRegistries)); compound.put("requests", Utility.serializeAll(this.existingRequests)); } @Override - public void load(CompoundTag compound) { - this.items.deserializeNBT(compound.getCompound("items")); + protected void loadAdditional(CompoundTag compound, HolderLookup.Provider pRegistries) { + this.items.deserializeNBT(pRegistries, compound.getCompound("items")); this.existingRequests.clear(); - this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), NetworkLock::new)); - super.load(compound); + this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), l -> new NetworkLock(pRegistries, l))); + super.loadAdditional(compound, pRegistries); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java index da06087..fd35adb 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalContainer.java @@ -48,9 +48,9 @@ public class CraftingTerminalContainer extends ItemTerminalContainer { super.slotsChanged(inventoryIn); if (!this.player.level().isClientSide) { var ret = ItemStack.EMPTY; - var optional = this.player.level().getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level()); + var optional = this.player.level().getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory.asCraftInput(), this.player.level()); if (optional.isPresent()) - ret = optional.get().value().assemble(this.craftInventory, this.player.level().registryAccess()); + ret = optional.get().value().assemble(this.craftInventory.asCraftInput(), this.player.level().registryAccess()); this.craftResult.setItem(0, ret); ((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret)); } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java index 2abfbc9..726d7cf 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/CraftingTerminalGui.java @@ -13,7 +13,7 @@ import net.neoforged.neoforge.network.PacketDistributor; public class CraftingTerminalGui extends ItemTerminalGui { - private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/crafting_terminal.png"); + private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "textures/gui/crafting_terminal.png"); private Button requestButton; public CraftingTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) { @@ -28,7 +28,7 @@ public class CraftingTerminalGui extends ItemTerminalGui { var amount = ItemTerminalGui.requestModifier(); // also allow holding backspace instead of alt for people whose alt key is inaccessible (linux?) var force = Screen.hasAltDown() || InputConstants.isKeyDown(this.minecraft.getWindow().getWindow(), 259) ? 1 : 0; - PacketDistributor.SERVER.noArg().send(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force)); + PacketDistributor.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CRAFT_TERMINAL_REQUEST, amount, force)); }).bounds(this.leftPos + 8, this.topPos + 100, 50, 20).build()); this.tick(); } diff --git a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java index 466b7db..9d3cc1c 100644 --- a/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java +++ b/src/main/java/de/ellpeck/prettypipes/terminal/containers/ItemTerminalGui.java @@ -20,6 +20,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.neoforged.neoforge.network.PacketDistributor; @@ -29,9 +30,10 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +@SuppressWarnings("ALL") public class ItemTerminalGui extends AbstractContainerScreen { - private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/item_terminal.png"); + private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "textures/gui/item_terminal.png"); public List currentlyCrafting; public EditBox search; @@ -91,7 +93,7 @@ public class ItemTerminalGui extends AbstractContainerScreen