bunch of work

This commit is contained in:
Ell 2024-09-15 14:23:14 +02:00
parent 68c68ae5b7
commit 2e05cd7b70
29 changed files with 211 additions and 194 deletions

View file

@ -68,24 +68,26 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties; import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod.EventBusSubscriber; import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod.EventBusSubscriber.Bus;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.capabilities.BlockCapability; import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; 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 net.neoforged.neoforge.registries.RegisterEvent;
import java.util.Comparator; import java.util.Comparator;
import java.util.Locale; import java.util.Locale;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import static net.neoforged.fml.common.EventBusSubscriber.*;
@EventBusSubscriber(bus = Bus.MOD) @EventBusSubscriber(bus = Bus.MOD)
public final class Registry { public final class Registry {
public static BlockCapability<IPipeConnectable, Direction> pipeConnectableCapability = BlockCapability.createSided(new ResourceLocation(PrettyPipes.ID, "pipe_connectable"), IPipeConnectable.class); public static BlockCapability<IPipeConnectable, Direction> pipeConnectableCapability = BlockCapability.createSided(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_connectable"), IPipeConnectable.class);
public static Item wrenchItem; public static Item wrenchItem;
public static Item pipeFrameItem; public static Item pipeFrameItem;
@ -119,19 +121,19 @@ public final class Registry {
@SubscribeEvent @SubscribeEvent
public static void register(RegisterEvent event) { public static void register(RegisterEvent event) {
event.register(Registries.BLOCK, h -> { 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(ResourceLocation.fromNamespaceAndPath(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(ResourceLocation.fromNamespaceAndPath(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(ResourceLocation.fromNamespaceAndPath(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, "pressurizer"), Registry.pressurizerBlock = new PressurizerBlock(Properties.of().strength(3).sound(SoundType.STONE)));
}); });
event.register(Registries.ITEM, h -> { event.register(Registries.ITEM, h -> {
h.register(new ResourceLocation(PrettyPipes.ID, "wrench"), Registry.wrenchItem = new WrenchItem()); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "wrench"), Registry.wrenchItem = new WrenchItem());
h.register(new ResourceLocation(PrettyPipes.ID, "blank_module"), new Item(new Item.Properties())); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "blank_module"), new Item(new Item.Properties()));
h.register(new ResourceLocation(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameItem = new PipeFrameItem()); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameItem = new PipeFrameItem());
h.register(new ResourceLocation(PrettyPipes.ID, "stack_size_module"), new StackSizeModuleItem()); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "stack_size_module"), new StackSizeModuleItem());
h.register(new ResourceLocation(PrettyPipes.ID, "redstone_module"), new RedstoneModuleItem()); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "redstone_module"), new RedstoneModuleItem());
h.register(new ResourceLocation(PrettyPipes.ID, "filter_increase_modifier"), new FilterIncreaseModuleItem()); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "filter_increase_modifier"), new FilterIncreaseModuleItem());
Registry.registerTieredModule(h, "extraction_module", ExtractionModuleItem::new); Registry.registerTieredModule(h, "extraction_module", ExtractionModuleItem::new);
Registry.registerTieredModule(h, "filter_module", FilterModuleItem::new); Registry.registerTieredModule(h, "filter_module", FilterModuleItem::new);
@ -143,11 +145,11 @@ public final class Registry {
for (var type : ItemEquality.Type.values()) { for (var type : ItemEquality.Type.values()) {
var name = type.name().toLowerCase(Locale.ROOT) + "_filter_modifier"; 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()) { for (var type : SortingModuleItem.Type.values()) {
var name = type.name().toLowerCase(Locale.ROOT) + "_sorting_modifier"; 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() BuiltInRegistries.BLOCK.entrySet().stream()
@ -156,20 +158,20 @@ public final class Registry {
}); });
event.register(Registries.BLOCK_ENTITY_TYPE, h -> { 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(ResourceLocation.fromNamespaceAndPath(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(ResourceLocation.fromNamespaceAndPath(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(ResourceLocation.fromNamespaceAndPath(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, "pressurizer"), Registry.pressurizerBlockEntity = BlockEntityType.Builder.of(PressurizerBlockEntity::new, Registry.pressurizerBlock).build(null));
}); });
event.register(Registries.ENTITY_TYPE, h -> event.register(Registries.ENTITY_TYPE, h ->
h.register(new ResourceLocation(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameEntity = EntityType.Builder.<PipeFrameEntity>of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame"))); h.register(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "pipe_frame"), Registry.pipeFrameEntity = EntityType.Builder.<PipeFrameEntity>of(PipeFrameEntity::new, MobCategory.MISC).build("pipe_frame")));
event.register(Registries.MENU, h -> { 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(ResourceLocation.fromNamespaceAndPath(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(ResourceLocation.fromNamespaceAndPath(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(ResourceLocation.fromNamespaceAndPath(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, "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.extractionModuleContainer = Registry.registerPipeContainer(h, "extraction_module");
Registry.filterModuleContainer = Registry.registerPipeContainer(h, "filter_module"); Registry.filterModuleContainer = Registry.registerPipeContainer(h, "filter_module");
@ -181,7 +183,7 @@ public final class Registry {
}); });
event.register(BuiltInRegistries.CREATIVE_MODE_TAB.key(), h -> { 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")) .title(Component.translatable("item_group." + PrettyPipes.ID + ".tab"))
.icon(() -> new ItemStack(Registry.wrenchItem)) .icon(() -> new ItemStack(Registry.wrenchItem))
.displayItems((params, output) -> BuiltInRegistries.ITEM.entrySet().stream() .displayItems((params, output) -> BuiltInRegistries.ITEM.entrySet().stream()
@ -192,7 +194,7 @@ public final class Registry {
}); });
event.register(Registries.RECIPE_SERIALIZER, h -> { 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 @SubscribeEvent
public static void registerPayloads(final RegisterPayloadHandlerEvent event) { public static void registerPayloads(final RegisterPayloadHandlersEvent event) {
var registrar = event.registrar(PrettyPipes.ID); var registrar = event.registrar(PrettyPipes.ID);
registrar.play(PacketItemEnterPipe.ID, PacketItemEnterPipe::new, PacketItemEnterPipe::onMessage); registrar.play(PacketItemEnterPipe.ID, PacketItemEnterPipe::new, PacketItemEnterPipe::onMessage);
registrar.play(PacketButton.ID, PacketButton::new, PacketButton::onMessage); registrar.play(PacketButton.ID, PacketButton::new, PacketButton::onMessage);
@ -224,13 +226,13 @@ public final class Registry {
var moduleStack = tile.modules.getStackInSlot(moduleIndex); var moduleStack = tile.modules.getStackInSlot(moduleIndex);
return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, 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; return type;
} }
private static void registerTieredModule(RegisterEvent.RegisterHelper<Item> helper, String name, BiFunction<String, ModuleTier, ModuleItem> item) { private static void registerTieredModule(RegisterEvent.RegisterHelper<Item> helper, String name, BiFunction<String, ModuleTier, ModuleItem> item) {
for (var tier : ModuleTier.values()) 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) @EventBusSubscriber(bus = Bus.MOD, value = Dist.CLIENT)
@ -240,18 +242,21 @@ public final class Registry {
public static void setup(FMLClientSetupEvent event) { public static void setup(FMLClientSetupEvent event) {
BlockEntityRenderers.register(Registry.pipeBlockEntity, PipeRenderer::new); BlockEntityRenderers.register(Registry.pipeBlockEntity, PipeRenderer::new);
EntityRenderers.register(Registry.pipeFrameEntity, PipeFrameRenderer::new); EntityRenderers.register(Registry.pipeFrameEntity, PipeFrameRenderer::new);
}
MenuScreens.register(Registry.pipeContainer, MainPipeGui::new); @SubscribeEvent
MenuScreens.register(Registry.itemTerminalContainer, ItemTerminalGui::new); public static void registerMenuScreens(RegisterMenuScreensEvent event) {
MenuScreens.register(Registry.pressurizerContainer, PressurizerGui::new); event.register(Registry.pipeContainer, MainPipeGui::new);
MenuScreens.register(Registry.craftingTerminalContainer, CraftingTerminalGui::new); event.register(Registry.itemTerminalContainer, ItemTerminalGui::new);
MenuScreens.register(Registry.extractionModuleContainer, ExtractionModuleGui::new); event.register(Registry.pressurizerContainer, PressurizerGui::new);
MenuScreens.register(Registry.filterModuleContainer, FilterModuleGui::new); event.register(Registry.craftingTerminalContainer, CraftingTerminalGui::new);
MenuScreens.register(Registry.retrievalModuleContainer, RetrievalModuleGui::new); event.register(Registry.extractionModuleContainer, ExtractionModuleGui::new);
MenuScreens.register(Registry.stackSizeModuleContainer, StackSizeModuleGui::new); event.register(Registry.filterModuleContainer, FilterModuleGui::new);
MenuScreens.register(Registry.filterIncreaseModuleContainer, FilterIncreaseModuleGui::new); event.register(Registry.retrievalModuleContainer, RetrievalModuleGui::new);
MenuScreens.register(Registry.craftingModuleContainer, CraftingModuleGui::new); event.register(Registry.stackSizeModuleContainer, StackSizeModuleGui::new);
MenuScreens.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new); event.register(Registry.filterIncreaseModuleContainer, FilterIncreaseModuleGui::new);
event.register(Registry.craftingModuleContainer, CraftingModuleGui::new);
event.register(Registry.filterModifierModuleContainer, FilterModifierModuleGui::new);
} }
} }

View file

@ -5,6 +5,7 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -30,6 +31,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@SuppressWarnings("ALL")
public final class Utility { public final class Utility {
public static <T extends BlockEntity> T getBlockEntity(Class<T> type, BlockGetter world, BlockPos pos) { public static <T extends BlockEntity> T getBlockEntity(Class<T> type, BlockGetter world, BlockPos pos) {
@ -104,10 +106,10 @@ public final class Utility {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
public static ListTag serializeAll(Collection<? extends INBTSerializable<CompoundTag>> items) { public static ListTag serializeAll(HolderLookup.Provider provider, Collection<? extends INBTSerializable<CompoundTag>> items) {
var list = new ListTag(); var list = new ListTag();
for (INBTSerializable<CompoundTag> item : items) for (INBTSerializable<CompoundTag> item : items)
list.add(item.serializeNBT()); list.add(item.serializeNBT(provider));
return list; return list;
} }
@ -143,5 +145,7 @@ public final class Utility {
public interface IMergeItemStack { public interface IMergeItemStack {
boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection); boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection);
} }
} }

View file

@ -4,25 +4,21 @@ import de.ellpeck.prettypipes.Registry;
import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemEquality;
import de.ellpeck.prettypipes.packets.PacketCraftingModuleTransfer; import de.ellpeck.prettypipes.packets.PacketCraftingModuleTransfer;
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView; import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.recipe.RecipeIngredientRole; 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.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.entity.player.Player;
import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack; 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 net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
public class CraftingModuleTransferHandler implements IRecipeTransferHandler<CraftingModuleContainer, RecipeHolder<CraftingRecipe>> { public class CraftingModuleTransferHandler implements IUniversalRecipeTransferHandler<CraftingModuleContainer> {
@Override @Override
public Class<CraftingModuleContainer> getContainerClass() { public Class<CraftingModuleContainer> getContainerClass() {
@ -35,21 +31,16 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
} }
@Override @Override
public RecipeType<RecipeHolder<CraftingRecipe>> getRecipeType() { public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, Object recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) {
return RecipeTypes.CRAFTING;
}
@Override
public @Nullable IRecipeTransferError transferRecipe(CraftingModuleContainer container, RecipeHolder<CraftingRecipe> recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
if (!doTransfer) if (!doTransfer)
return null; return null;
var inputs = new ArrayList<ItemStack>(); var inputs = new ArrayList<ItemStack>();
var outputs = new ArrayList<ItemStack>(); var outputs = new ArrayList<ItemStack>();
for (var entry : slots.getSlotViews()) { for (var entry : recipeSlots.getSlotViews()) {
var allIngredients = entry.getIngredients(VanillaTypes.ITEM_STACK).toList(); var allIngredients = entry.getIngredients(VanillaTypes.ITEM_STACK).toList();
if (allIngredients.isEmpty()) if (allIngredients.isEmpty())
continue; continue;
var remain = allIngredients.get(0).copy(); var remain = allIngredients.getFirst().copy();
var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs; var toAdd = entry.getRole() == RecipeIngredientRole.INPUT ? inputs : outputs;
for (var stack : toAdd) { for (var stack : toAdd) {
if (ItemEquality.compareItems(stack, remain)) { if (ItemEquality.compareItems(stack, remain)) {
@ -63,7 +54,7 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
if (!remain.isEmpty()) if (!remain.isEmpty())
toAdd.add(remain); toAdd.add(remain);
} }
PacketDistributor.SERVER.noArg().send(new PacketCraftingModuleTransfer(inputs, outputs)); PacketDistributor.sendToServer(new PacketCraftingModuleTransfer(inputs, outputs));
return null; return null;
} }

View file

@ -47,7 +47,7 @@ public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<C
var ingredients = slots.getSlotViews(RecipeIngredientRole.INPUT); var ingredients = slots.getSlotViews(RecipeIngredientRole.INPUT);
for (var entry : ingredients) for (var entry : ingredients)
stacks.add(new PacketGhostSlot.Entry(player.level(), entry.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toList()))); stacks.add(new PacketGhostSlot.Entry(player.level(), entry.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toList())));
PacketDistributor.SERVER.noArg().send(new PacketGhostSlot(container.getTile().getBlockPos(), stacks)); PacketDistributor.sendToServer(new PacketGhostSlot(container.getTile().getBlockPos(), stacks));
return null; return null;
} }

View file

@ -16,10 +16,10 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.renderer.Rect2i; import net.minecraft.client.renderer.Rect2i;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.bus.api.SubscribeEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,7 +38,7 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
@Override @Override
public ResourceLocation getPluginUid() { public ResourceLocation getPluginUid() {
return new ResourceLocation(PrettyPipes.ID, "jei_plugin"); return ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "jei_plugin");
} }
@Override @Override
@ -103,7 +103,7 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
} }
@SubscribeEvent @SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) { public void onClientTick(ClientTickEvent event) {
if (!PlayerPrefs.get().syncJei) if (!PlayerPrefs.get().syncJei)
return; return;

View file

@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeBlock;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
@ -41,9 +41,9 @@ public class PipeFrameEntity extends ItemFrame implements IEntityWithComplexSpaw
} }
@Override @Override
protected void defineSynchedData() { protected void defineSynchedData(SynchedEntityData.Builder pBuilder) {
super.defineSynchedData(); super.defineSynchedData(pBuilder);
this.entityData.define(PipeFrameEntity.AMOUNT, -1); pBuilder.define(PipeFrameEntity.AMOUNT, -1);
} }
@Override @Override
@ -154,14 +154,15 @@ public class PipeFrameEntity extends ItemFrame implements IEntityWithComplexSpaw
} }
@Override @Override
public void writeSpawnData(FriendlyByteBuf buffer) { public void writeSpawnData(RegistryFriendlyByteBuf buffer) {
buffer.writeBlockPos(this.pos); buffer.writeBlockPos(this.pos);
buffer.writeInt(this.direction.ordinal()); buffer.writeInt(this.direction.ordinal());
} }
@Override @Override
public void readSpawnData(FriendlyByteBuf additionalData) { public void readSpawnData(RegistryFriendlyByteBuf additionalData) {
this.pos = additionalData.readBlockPos(); this.pos = additionalData.readBlockPos();
this.direction = Direction.values()[additionalData.readInt()]; this.direction = Direction.values()[additionalData.readInt()];
} }
} }

View file

@ -13,12 +13,10 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.IItemHandler;
import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Stack; import java.util.Stack;
@ -35,9 +33,9 @@ public abstract class ModuleItem extends Item implements IModule {
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) { public void appendHoverText(ItemStack pStack, TooltipContext pContext, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) {
super.appendHoverText(stack, worldIn, tooltip, flagIn); super.appendHoverText(pStack, pContext, pTooltipComponents, pTooltipFlag);
Utility.addTooltip(this.name, tooltip); Utility.addTooltip(this.name, pTooltipComponents);
} }
@Override @Override
@ -109,4 +107,5 @@ public abstract class ModuleItem extends Item implements IModule {
public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) { public DirectionSelector getDirectionSelector(ItemStack module, PipeBlockEntity tile) {
return null; return null;
} }
} }

View file

@ -15,9 +15,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class PipeFrameItem extends Item { public class PipeFrameItem extends Item {
@ -64,8 +62,9 @@ public class PipeFrameItem extends Item {
} }
@Override @Override
public void appendHoverText(ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, TooltipFlag flagIn) { public void appendHoverText(ItemStack pStack, TooltipContext pContext, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) {
super.appendHoverText(stack, worldIn, tooltip, flagIn); super.appendHoverText(pStack, pContext, pTooltipComponents, pTooltipFlag);
Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), tooltip); Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), pTooltipComponents);
} }
} }

View file

@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeBlock;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents; 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.context.UseOnContext;
import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments; 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.Block;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
@ -107,8 +107,8 @@ public class WrenchItem extends Item {
} }
@Override @Override
public void appendHoverText(ItemStack stack, Level worldIn, List<Component> tooltip, TooltipFlag flagIn) { public void appendHoverText(ItemStack pStack, TooltipContext pContext, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) {
Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), tooltip); Utility.addTooltip(BuiltInRegistries.ITEM.getKey(this).getPath(), pTooltipComponents);
} }
@Override @Override
@ -122,7 +122,7 @@ public class WrenchItem extends Item {
} }
@Override @Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { public boolean supportsEnchantment(ItemStack stack, Holder<Enchantment> enchantment) {
return enchantment == Enchantments.SILK_TOUCH; return enchantment == Enchantments.SILK_TOUCH;
} }

View file

@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.network.PipeNetwork;
import net.minecraft.commands.Commands; import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.neoforged.bus.api.SubscribeEvent; 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 net.neoforged.neoforge.event.server.ServerStartingEvent;
import java.io.IOException; import java.io.IOException;
@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@Mod.EventBusSubscriber @EventBusSubscriber
public final class Events { public final class Events {
@SubscribeEvent @SubscribeEvent

View file

@ -10,6 +10,7 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.inventory.Slot; import net.minecraft.world.inventory.Slot;
@ -130,16 +131,16 @@ public class ItemFilter extends ItemStackHandler {
} }
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT(HolderLookup.Provider provider) {
var nbt = super.serializeNBT(); var nbt = super.serializeNBT(provider);
if (this.canModifyWhitelist) if (this.canModifyWhitelist)
nbt.putBoolean("whitelist", this.isWhitelist); nbt.putBoolean("whitelist", this.isWhitelist);
return nbt; return nbt;
} }
@Override @Override
public void deserializeNBT(CompoundTag nbt) { public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
super.deserializeNBT(nbt); super.deserializeNBT(provider, nbt);
if (this.canModifyWhitelist) if (this.canModifyWhitelist)
this.isWhitelist = nbt.getBoolean("whitelist"); this.isWhitelist = nbt.getBoolean("whitelist");
} }

View file

@ -1,9 +1,7 @@
package de.ellpeck.prettypipes.misc; package de.ellpeck.prettypipes.misc;
import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.IModule;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.HolderLookup;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.*; import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
@ -17,9 +15,10 @@ public class ModuleClearingRecipe extends CustomRecipe {
} }
@Override @Override
public boolean matches(CraftingContainer container, Level level) { public boolean matches(CraftingInput container, Level level) {
var foundModule = false; 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) { if (!foundModule && stack.getItem() instanceof IModule) {
foundModule = true; foundModule = true;
} else if (!stack.isEmpty()) { } else if (!stack.isEmpty()) {
@ -30,11 +29,13 @@ public class ModuleClearingRecipe extends CustomRecipe {
} }
@Override @Override
public ItemStack assemble(CraftingContainer container, RegistryAccess access) { public ItemStack assemble(CraftingInput container, HolderLookup.Provider pRegistries) {
var module = container.getItems().stream().filter(i -> i.getItem() instanceof IModule).findFirst().orElse(ItemStack.EMPTY); for (var i = 0; i < container.size(); i++) {
if (!module.isEmpty()) var stack = container.getItem(i);
module = new ItemStack(module.getItem()); if (stack.getItem() instanceof IModule)
return module; return new ItemStack(stack.getItem());
}
return ItemStack.EMPTY;
} }
@Override @Override

View file

@ -50,4 +50,5 @@ public class PlayerPrefs {
var location = Minecraft.getInstance().gameDirectory; var location = Minecraft.getInstance().gameDirectory;
return new File(location, PrettyPipes.ID + "prefs"); return new File(location, PrettyPipes.ID + "prefs");
} }
} }

View file

@ -1,6 +1,7 @@
package de.ellpeck.prettypipes.network; package de.ellpeck.prettypipes.network;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
@ -18,20 +19,20 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
public NetworkEdge() { public NetworkEdge() {
} }
public NetworkEdge(CompoundTag nbt) { public NetworkEdge(HolderLookup.Provider provider, CompoundTag nbt) {
this.deserializeNBT(nbt); this.deserializeNBT(provider, nbt);
} }
public BlockPos getStartPipe() { public BlockPos getStartPipe() {
return this.pipes.get(0); return this.pipes.getFirst();
} }
public BlockPos getEndPipe() { public BlockPos getEndPipe() {
return this.pipes.get(this.pipes.size() - 1); return this.pipes.getLast();
} }
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT(HolderLookup.Provider provider) {
var nbt = new CompoundTag(); var nbt = new CompoundTag();
var list = new ListTag(); var list = new ListTag();
for (var pos : this.pipes) for (var pos : this.pipes)
@ -41,10 +42,11 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
} }
@Override @Override
public void deserializeNBT(CompoundTag nbt) { public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
this.pipes.clear(); this.pipes.clear();
var list = nbt.getList("pipes", Tag.TAG_COMPOUND); var list = nbt.getList("pipes", Tag.TAG_COMPOUND);
for (var i = 0; i < list.size(); i++) for (var i = 0; i < list.size(); i++)
this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i))); this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i)));
} }
} }

View file

@ -3,6 +3,7 @@ package de.ellpeck.prettypipes.network;
import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemEquality;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -28,8 +29,8 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
this.direction = direction; this.direction = direction;
} }
public NetworkLocation(CompoundTag nbt) { public NetworkLocation(HolderLookup.Provider provider, CompoundTag nbt) {
this.deserializeNBT(nbt); this.deserializeNBT(provider, nbt);
} }
public List<Integer> getStackSlots(Level world, ItemStack stack, ItemEquality... equalityTypes) { public List<Integer> getStackSlots(Level world, ItemStack stack, ItemEquality... equalityTypes) {
@ -91,7 +92,7 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
} }
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT(HolderLookup.Provider provider) {
var nbt = new CompoundTag(); var nbt = new CompoundTag();
nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos)); nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos));
nbt.putInt("direction", this.direction.ordinal()); nbt.putInt("direction", this.direction.ordinal());
@ -99,8 +100,9 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
} }
@Override @Override
public void deserializeNBT(CompoundTag nbt) { public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
this.pipePos = NbtUtils.readBlockPos(nbt.getCompound("pipe_pos")); this.pipePos = NbtUtils.readBlockPos(nbt, "pipe_pos").orElse(null);
this.direction = Direction.values()[nbt.getInt("direction")]; this.direction = Direction.values()[nbt.getInt("direction")];
} }
} }

View file

@ -1,5 +1,6 @@
package de.ellpeck.prettypipes.network; package de.ellpeck.prettypipes.network;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.common.util.INBTSerializable; import net.neoforged.neoforge.common.util.INBTSerializable;
@ -20,24 +21,24 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
this.stack = stack; this.stack = stack;
} }
public NetworkLock(CompoundTag nbt) { public NetworkLock(HolderLookup.Provider provider, CompoundTag nbt) {
this.deserializeNBT(nbt); this.deserializeNBT(provider, nbt);
} }
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT(HolderLookup.Provider provider) {
var nbt = new CompoundTag(); var nbt = new CompoundTag();
nbt.putUUID("id", this.lockId); nbt.putUUID("id", this.lockId);
nbt.put("location", this.location.serializeNBT()); nbt.put("location", this.location.serializeNBT(provider));
nbt.put("stack", this.stack.save(new CompoundTag())); nbt.put("stack", this.stack.save(provider));
return nbt; return nbt;
} }
@Override @Override
public void deserializeNBT(CompoundTag nbt) { public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
this.lockId = nbt.getUUID("id"); this.lockId = nbt.getUUID("id");
this.location = new NetworkLocation(nbt.getCompound("location")); this.location = new NetworkLocation(provider, nbt.getCompound("location"));
this.stack = ItemStack.of(nbt.getCompound("stack")); this.stack = ItemStack.parseOptional(provider, nbt.getCompound("stack"));
} }
@Override @Override
@ -56,4 +57,5 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
public String toString() { public String toString() {
return "NetworkLock{" + "location=" + this.location.pipePos + ", stack=" + this.stack + '}'; return "NetworkLock{" + "location=" + this.location.pipePos + ", stack=" + this.stack + '}';
} }
} }

View file

@ -8,6 +8,7 @@ import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
@ -33,7 +34,7 @@ import java.util.function.Consumer;
public class PipeItem implements IPipeItem { 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 ItemStack stack;
public float speed; public float speed;
@ -63,10 +64,10 @@ public class PipeItem implements IPipeItem {
this(PipeItem.TYPE, stack, speed); this(PipeItem.TYPE, stack, speed);
} }
public PipeItem(ResourceLocation type, CompoundTag nbt) { public PipeItem(HolderLookup.Provider provider, ResourceLocation type, CompoundTag nbt) {
this.type = type; this.type = type;
this.path = new ArrayList<>(); this.path = new ArrayList<>();
this.deserializeNBT(nbt); this.deserializeNBT(provider, nbt);
} }
@Override @Override
@ -221,12 +222,12 @@ public class PipeItem implements IPipeItem {
} }
protected BlockPos getStartPipe() { protected BlockPos getStartPipe() {
return this.path.get(0); return this.path.getFirst();
} }
@Override @Override
public BlockPos getDestPipe() { public BlockPos getDestPipe() {
return this.path.get(this.path.size() - 1); return this.path.getLast();
} }
@Override @Override
@ -240,10 +241,10 @@ public class PipeItem implements IPipeItem {
} }
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT(HolderLookup.Provider provider) {
var nbt = new CompoundTag(); var nbt = new CompoundTag();
nbt.putString("type", this.type.toString()); 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.putFloat("speed", this.speed);
nbt.put("start_inv", NbtUtils.writeBlockPos(this.startInventory)); nbt.put("start_inv", NbtUtils.writeBlockPos(this.startInventory));
nbt.put("dest_inv", NbtUtils.writeBlockPos(this.destInventory)); nbt.put("dest_inv", NbtUtils.writeBlockPos(this.destInventory));
@ -261,12 +262,12 @@ public class PipeItem implements IPipeItem {
} }
@Override @Override
public void deserializeNBT(CompoundTag nbt) { public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) {
this.stack = ItemStack.of(nbt.getCompound("stack")); this.stack = ItemStack.parseOptional(provider, nbt.getCompound("stack"));
this.speed = nbt.getFloat("speed"); this.speed = nbt.getFloat("speed");
this.startInventory = NbtUtils.readBlockPos(nbt.getCompound("start_inv")); this.startInventory = NbtUtils.readBlockPos(nbt, "start_inv").orElse(null);
this.destInventory = NbtUtils.readBlockPos(nbt.getCompound("dest_inv")); this.destInventory = NbtUtils.readBlockPos(nbt, "dest_inv").orElse(null);
this.currGoalPos = NbtUtils.readBlockPos(nbt.getCompound("curr_goal")); this.currGoalPos = NbtUtils.readBlockPos(nbt, "curr_goal").orElse(null);
this.retryOnObstruction = nbt.getBoolean("drop_on_obstruction"); this.retryOnObstruction = nbt.getBoolean("drop_on_obstruction");
this.currentTile = nbt.getInt("tile"); this.currentTile = nbt.getInt("tile");
this.x = nbt.getFloat("x"); this.x = nbt.getFloat("x");
@ -344,7 +345,7 @@ public class PipeItem implements IPipeItem {
// add the single pipe twice if there's only one // add the single pipe twice if there's only one
// this is a dirty hack, but it works fine so eh // this is a dirty hack, but it works fine so eh
for (var i = 0; i < 2; i++) for (var i = 0; i < 2; i++)
ret.add(nodes.get(0)); ret.add(nodes.getFirst());
return ret; return ret;
} }
for (var i = 0; i < nodes.size() - 1; i++) { for (var i = 0; i < nodes.size() - 1; i++) {
@ -368,4 +369,5 @@ public class PipeItem implements IPipeItem {
} }
return ret; return ret;
} }
} }

View file

@ -12,12 +12,14 @@ import de.ellpeck.prettypipes.pipe.PipeBlock;
import de.ellpeck.prettypipes.pipe.PipeBlockEntity; import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.saveddata.SavedData; import net.minecraft.world.level.saveddata.SavedData;
@ -60,17 +62,17 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
this.dijkstra = new DijkstraShortestPath<>(this.graph); this.dijkstra = new DijkstraShortestPath<>(this.graph);
} }
public PipeNetwork(CompoundTag nbt) { public PipeNetwork(CompoundTag nbt, HolderLookup.Provider provider) {
this(); this();
var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND); var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND);
for (var i = 0; i < nodes.size(); i++) for (var i = 0; i < nodes.size(); i++)
this.graph.addVertex(NbtUtils.readBlockPos(nodes.getCompound(i))); this.graph.addVertex(NbtUtils.readBlockPos(nodes.getCompound(i)));
var edges = nbt.getList("edges", Tag.TAG_COMPOUND); var edges = nbt.getList("edges", Tag.TAG_COMPOUND);
for (var i = 0; i < edges.size(); i++) 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)) for (var item : Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load))
this.pipeItems.put(item.getCurrentPipe(), item); 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); this.createNetworkLock(lock);
} }
@ -108,14 +110,14 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
} }
@Override @Override
public CompoundTag save(CompoundTag nbt) { public CompoundTag save(CompoundTag nbt, HolderLookup.Provider provider) {
var nodes = new ListTag(); var nodes = new ListTag();
for (var node : this.graph.vertexSet()) for (var node : this.graph.vertexSet())
nodes.add(NbtUtils.writeBlockPos(node)); nodes.add(NbtUtils.writeBlockPos(node));
nbt.put("nodes", nodes); nbt.put("nodes", nodes);
var edges = new ListTag(); var edges = new ListTag();
for (var edge : this.graph.edgeSet()) for (var edge : this.graph.edgeSet())
edges.add(edge.serializeNBT()); edges.add(edge.serializeNBT(provider));
nbt.put("edges", edges); nbt.put("edges", edges);
nbt.put("items", Utility.serializeAll(this.pipeItems.values())); nbt.put("items", Utility.serializeAll(this.pipeItems.values()));
nbt.put("locks", Utility.serializeAll(this.networkLocks.values())); nbt.put("locks", Utility.serializeAll(this.networkLocks.values()));
@ -199,7 +201,7 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
var item = itemSupplier.apply(startPipe.getItemSpeed(stack)); var item = itemSupplier.apply(startPipe.getItemSpeed(stack));
item.setDestination(startInventory, destInventory, path); item.setDestination(startInventory, destInventory, path);
startPipe.addNewItem(item); startPipe.addNewItem(item);
PacketDistributor.TRACKING_CHUNK.with(this.level.getChunkAt(startPipePos)).send(new PacketItemEnterPipe(startPipePos, item)); PacketDistributor.sendToPlayersTrackingChunk((ServerLevel) this.level, new ChunkPos(startPipePos), new PacketItemEnterPipe(startPipePos, item));
return true; return true;
} }

View file

@ -28,7 +28,7 @@ public class PacketItemEnterPipe implements CustomPacketPayload {
this.tilePos = buf.readBlockPos(); this.tilePos = buf.readBlockPos();
this.item = buf.readNbt(); this.item = buf.readNbt();
} }
@Override @Override
public void write(FriendlyByteBuf buf) { public void write(FriendlyByteBuf buf) {
buf.writeBlockPos(this.tilePos); buf.writeBlockPos(this.tilePos);

View file

@ -11,6 +11,7 @@ import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity; import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -92,9 +93,9 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
} }
@Override @Override
public void saveAdditional(CompoundTag compound) { public void saveAdditional(CompoundTag compound, HolderLookup.Provider provider) {
super.saveAdditional(compound); super.saveAdditional(compound, provider);
compound.put("modules", this.modules.serializeNBT()); compound.put("modules", this.modules.serializeNBT(provider));
compound.putInt("module_drop_check", this.moduleDropCheck); compound.putInt("module_drop_check", this.moduleDropCheck);
compound.put("requests", Utility.serializeAll(this.craftIngredientRequests)); compound.put("requests", Utility.serializeAll(this.craftIngredientRequests));
if (this.cover != null) if (this.cover != null)
@ -103,49 +104,49 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
for (var triple : this.craftResultRequests) { for (var triple : this.craftResultRequests) {
var nbt = new CompoundTag(); var nbt = new CompoundTag();
nbt.putLong("dest_pipe", triple.getLeft().asLong()); nbt.putLong("dest_pipe", triple.getLeft().asLong());
nbt.put("item", triple.getRight().save(new CompoundTag())); nbt.put("item", triple.getRight().save(provider));
results.add(nbt); results.add(nbt);
} }
compound.put("craft_results", results); compound.put("craft_results", results);
} }
@Override @Override
public void load(CompoundTag compound) { public void loadAdditional(CompoundTag compound, HolderLookup.Provider provider) {
this.modules.deserializeNBT(compound.getCompound("modules")); this.modules.deserializeNBT(provider, compound.getCompound("modules"));
this.moduleDropCheck = compound.getInt("module_drop_check"); this.moduleDropCheck = compound.getInt("module_drop_check");
this.cover = compound.contains("cover") ? NbtUtils.readBlockState(this.level != null ? this.level.holderLookup(Registries.BLOCK) : BuiltInRegistries.BLOCK.asLookup(), compound.getCompound("cover")) : null; this.cover = compound.contains("cover") ? NbtUtils.readBlockState(this.level != null ? this.level.holderLookup(Registries.BLOCK) : BuiltInRegistries.BLOCK.asLookup(), compound.getCompound("cover")) : null;
this.craftIngredientRequests.clear(); this.craftIngredientRequests.clear();
this.craftIngredientRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), NetworkLock::new)); this.craftIngredientRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), l -> new NetworkLock(provider, l)));
this.craftResultRequests.clear(); this.craftResultRequests.clear();
var results = compound.getList("craft_results", Tag.TAG_COMPOUND); var results = compound.getList("craft_results", Tag.TAG_COMPOUND);
for (var i = 0; i < results.size(); i++) { for (var i = 0; i < results.size(); i++) {
var nbt = results.getCompound(i); var nbt = results.getCompound(i);
this.craftResultRequests.add(Pair.of( this.craftResultRequests.add(Pair.of(
BlockPos.of(nbt.getLong("dest_pipe")), 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 @Override
public CompoundTag getUpdateTag() { public CompoundTag getUpdateTag(HolderLookup.Provider provider) {
// sync pipe items on load // sync pipe items on load
var nbt = this.saveWithoutMetadata(); var nbt = this.saveWithoutMetadata(provider);
nbt.put("items", Utility.serializeAll(this.getItems())); nbt.put("items", Utility.serializeAll(this.getItems()));
return nbt; return nbt;
} }
@Override @Override
public void handleUpdateTag(CompoundTag nbt) { public void handleUpdateTag(CompoundTag nbt, HolderLookup.Provider provider) {
this.load(nbt); this.loadWithComponents(nbt, provider);
var items = this.getItems(); var items = this.getItems();
items.clear(); items.clear();
items.addAll(Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load)); items.addAll(Utility.deserializeAll(nbt.getList("items", Tag.TAG_COMPOUND), IPipeItem::load));
} }
@Override @Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) {
this.load(pkt.getTag()); this.loadWithComponents(pkt.getTag(), provider);
} }
public List<IPipeItem> getItems() { public List<IPipeItem> getItems() {

View file

@ -20,7 +20,7 @@ import java.util.List;
public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extends AbstractContainerScreen<T> { public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extends AbstractContainerScreen<T> {
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<Tab> tabs = new ArrayList<>(); private final List<Tab> tabs = new ArrayList<>();
private final ItemStack[] lastItems = new ItemStack[this.menu.tile.modules.getSlots()]; private final ItemStack[] lastItems = new ItemStack[this.menu.tile.modules.getSlots()];
@ -144,7 +144,7 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
return false; return false;
if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32) if (mouseX < this.x || mouseY < this.y || mouseX >= this.x + 28 || mouseY >= this.y + 32)
return false; 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)); AbstractPipeGui.this.getMinecraft().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1));
return true; return true;
} }

View file

@ -8,6 +8,7 @@ import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.IPipeConnectable; import de.ellpeck.prettypipes.pipe.IPipeConnectable;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection; import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -51,30 +52,30 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
} }
@Override @Override
public void saveAdditional(CompoundTag compound) { public void saveAdditional(CompoundTag compound, HolderLookup.Provider provider) {
super.saveAdditional(compound); super.saveAdditional(compound, provider);
compound.putInt("energy", this.getEnergy()); compound.putInt("energy", this.getEnergy());
} }
@Override @Override
public void load(CompoundTag nbt) { public void loadAdditional(CompoundTag nbt, HolderLookup.Provider provider) {
this.storage.setEnergyStored(nbt.getInt("energy")); this.storage.setEnergyStored(nbt.getInt("energy"));
super.load(nbt); super.loadAdditional(nbt, provider);
} }
@Override @Override
public CompoundTag getUpdateTag() { public CompoundTag getUpdateTag(HolderLookup.Provider provider) {
return this.saveWithoutMetadata(); return this.saveWithoutMetadata(provider);
} }
@Override @Override
public void handleUpdateTag(CompoundTag tag) { public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider provider) {
this.load(tag); this.loadWithComponents(tag, provider);
} }
@Override @Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) {
this.load(pkt.getTag()); this.loadWithComponents(pkt.getTag(), provider);
} }
@Override @Override

View file

@ -9,7 +9,7 @@ import net.minecraft.world.entity.player.Inventory;
public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer> { public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer> {
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) { public PressurizerGui(PressurizerContainer screenContainer, Inventory inv, Component titleIn) {
super(screenContainer, inv, titleIn); super(screenContainer, inv, titleIn);

View file

@ -16,10 +16,12 @@ import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; 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.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.items.ItemHandlerHelper; import net.neoforged.neoforge.items.ItemHandlerHelper;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
@ -98,7 +100,7 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
List<PacketGhostSlot.Entry> clients = new ArrayList<>(); List<PacketGhostSlot.Entry> clients = new ArrayList<>();
for (var i = 0; i < this.ghostItems.getSlots(); i++) for (var i = 0; i < this.ghostItems.getSlots(); i++)
clients.add(new PacketGhostSlot.Entry(this.level, Collections.singletonList(this.ghostItems.getStackInSlot(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));
} }
} }

View file

@ -7,12 +7,11 @@ import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape; 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.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class ItemTerminalBlock extends BaseEntityBlock { public class ItemTerminalBlock extends BaseEntityBlock {
@ -40,19 +38,19 @@ public class ItemTerminalBlock extends BaseEntityBlock {
} }
@Override @Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) { protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) {
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos); var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, pLevel, pPos);
if (tile == null) if (tile == null)
return InteractionResult.PASS; return InteractionResult.PASS;
var reason = tile.getInvalidTerminalReason(); var reason = tile.getInvalidTerminalReason();
if (reason != null) { if (reason != null) {
if (!worldIn.isClientSide) if (!pLevel.isClientSide)
player.sendSystemMessage(Component.translatable(reason).withStyle(ChatFormatting.RED)); pPlayer.sendSystemMessage(Component.translatable(reason).withStyle(ChatFormatting.RED));
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
if (!worldIn.isClientSide) { if (!pLevel.isClientSide) {
player.openMenu(tile, pos); pPlayer.openMenu(tile, pPos);
tile.updateItems(player); tile.updateItems(pPlayer);
} }
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
@ -79,8 +77,8 @@ public class ItemTerminalBlock extends BaseEntityBlock {
} }
@Override @Override
public void appendHoverText(ItemStack stack, @Nullable BlockGetter worldIn, List<Component> tooltip, TooltipFlag flagIn) { public void appendHoverText(ItemStack pStack, Item.TooltipContext pContext, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) {
Utility.addTooltip(BuiltInRegistries.BLOCK.getKey(this).getPath(), tooltip); Utility.addTooltip(BuiltInRegistries.BLOCK.getKey(this).getPath(), pTooltipComponents);
} }
@org.jetbrains.annotations.Nullable @org.jetbrains.annotations.Nullable

View file

@ -17,6 +17,7 @@ import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -228,18 +229,18 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
} }
@Override @Override
public void saveAdditional(CompoundTag compound) { public void saveAdditional(CompoundTag compound, HolderLookup.Provider pRegistries) {
super.saveAdditional(compound); super.saveAdditional(compound, pRegistries);
compound.put("items", this.items.serializeNBT()); compound.put("items", this.items.serializeNBT(pRegistries));
compound.put("requests", Utility.serializeAll(this.existingRequests)); compound.put("requests", Utility.serializeAll(this.existingRequests));
} }
@Override @Override
public void load(CompoundTag compound) { protected void loadAdditional(CompoundTag compound, HolderLookup.Provider pRegistries) {
this.items.deserializeNBT(compound.getCompound("items")); this.items.deserializeNBT(pRegistries, compound.getCompound("items"));
this.existingRequests.clear(); this.existingRequests.clear();
this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), NetworkLock::new)); this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", Tag.TAG_COMPOUND), l -> new NetworkLock(pRegistries, l)));
super.load(compound); super.loadAdditional(compound, pRegistries);
} }
@Override @Override

View file

@ -48,9 +48,9 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
super.slotsChanged(inventoryIn); super.slotsChanged(inventoryIn);
if (!this.player.level().isClientSide) { if (!this.player.level().isClientSide) {
var ret = ItemStack.EMPTY; 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()) 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); this.craftResult.setItem(0, ret);
((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret)); ((ServerPlayer) this.player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, 0, ret));
} }

View file

@ -13,7 +13,7 @@ import net.neoforged.neoforge.network.PacketDistributor;
public class CraftingTerminalGui extends ItemTerminalGui { 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; private Button requestButton;
public CraftingTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) { public CraftingTerminalGui(ItemTerminalContainer screenContainer, Inventory inv, Component titleIn) {
@ -28,7 +28,7 @@ public class CraftingTerminalGui extends ItemTerminalGui {
var amount = ItemTerminalGui.requestModifier(); var amount = ItemTerminalGui.requestModifier();
// also allow holding backspace instead of alt for people whose alt key is inaccessible (linux?) // 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; 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()); }).bounds(this.leftPos + 8, this.topPos + 100, 50, 20).build());
this.tick(); this.tick();
} }

View file

@ -20,6 +20,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.TooltipFlag;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
@ -29,9 +30,10 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@SuppressWarnings("ALL")
public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContainer> { public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContainer> {
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<ItemStack> currentlyCrafting; public List<ItemStack> currentlyCrafting;
public EditBox search; public EditBox search;
@ -91,7 +93,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
return; return;
var stack = widget.get().stack.copy(); var stack = widget.get().stack.copy();
stack.setCount(1); stack.setCount(1);
PacketDistributor.SERVER.noArg().send(new PacketRequest(this.menu.tile.getBlockPos(), stack, this.requestAmount)); PacketDistributor.sendToServer(new PacketRequest(this.menu.tile.getBlockPos(), stack, this.requestAmount));
this.requestAmount = 1; this.requestAmount = 1;
}).bounds(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20).build()); }).bounds(this.leftPos + this.getXOffset() + 95 - 7 - 25, this.topPos + 115, 50, 20).build());
this.requestButton.active = false; this.requestButton.active = false;
@ -159,7 +161,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
// and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default // and vanilla buttons are activated when the click starts, so we'll always invoke jei accidentally by default
if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) { if (button == 0 && this.cancelCraftingButton.visible && this.cancelCraftingButton.isHovered()) {
if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) { if (this.currentlyCrafting != null && !this.currentlyCrafting.isEmpty()) {
PacketDistributor.SERVER.noArg().send(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING)); PacketDistributor.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
return true; return true;
} }
} }
@ -232,7 +234,7 @@ public class ItemTerminalGui extends AbstractContainerScreen<ItemTerminalContain
search = search.substring(1); search = search.substring(1);
} else if (search.startsWith("#")) { } else if (search.startsWith("#")) {
// search item description // search item description
var hoverText = s.getLeft().getTooltipLines(this.minecraft.player, var hoverText = s.getLeft().getTooltipLines(Item.TooltipContext.of(this.minecraft.level), this.minecraft.player,
this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL); this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL);
toCompare = hoverText.stream().map(Component::getString).collect(Collectors.joining("\n")); toCompare = hoverText.stream().map(Component::getString).collect(Collectors.joining("\n"));
search = search.substring(1); search = search.substring(1);