mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-28 05:58:33 +01:00
Compare commits
No commits in common. "4914c5f3c00ac559cc0f6ddd85a4b4e6c4bda6f2" and "75cd73470f8d680b1e877cf5c7f4529f8294f26e" have entirely different histories.
4914c5f3c0
...
75cd73470f
22 changed files with 302 additions and 286 deletions
|
@ -1,18 +1,18 @@
|
||||||
package de.ellpeck.prettypipes;
|
package de.ellpeck.prettypipes;
|
||||||
|
|
||||||
import net.neoforged.api.distmarker.Dist;
|
import net.neoforged.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.fml.DistExecutor;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.loading.FMLEnvironment;
|
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
|
|
||||||
@Mod(PrettyPipes.ID)
|
@Mod(PrettyPipes.ID)
|
||||||
public final class PrettyPipes {
|
public final class PrettyPipes {
|
||||||
|
|
||||||
public static final String ID = "prettypipes";
|
public static final String ID = "prettypipes";
|
||||||
|
|
||||||
public PrettyPipes(IEventBus eventBus) {
|
public PrettyPipes() {
|
||||||
if (FMLEnvironment.dist == Dist.CLIENT)
|
var bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
eventBus.addListener(Registry.Client::setup);
|
bus.addListener(Registry::setup);
|
||||||
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> bus.addListener(Registry.Client::setup));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import de.ellpeck.prettypipes.entities.PipeFrameRenderer;
|
||||||
import de.ellpeck.prettypipes.items.*;
|
import de.ellpeck.prettypipes.items.*;
|
||||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||||
import de.ellpeck.prettypipes.misc.ModuleClearingRecipe;
|
import de.ellpeck.prettypipes.misc.ModuleClearingRecipe;
|
||||||
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||||
|
@ -62,14 +64,13 @@ import net.minecraft.world.item.CreativeModeTab;
|
||||||
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.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.SoundType;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
import net.neoforged.neoforge.capabilities.BlockCapability;
|
||||||
|
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.neoforged.neoforge.capabilities.BlockCapability;
|
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
|
||||||
import net.neoforged.neoforge.registries.RegisterEvent;
|
import net.neoforged.neoforge.registries.RegisterEvent;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -116,10 +117,10 @@ 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(new ResourceLocation(PrettyPipes.ID, "pipe"), Registry.pipeBlock = new PipeBlock());
|
||||||
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, "item_terminal"), Registry.itemTerminalBlock = new ItemTerminalBlock());
|
||||||
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, "crafting_terminal"), Registry.craftingTerminalBlock = new CraftingTerminalBlock());
|
||||||
h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlock = new PressurizerBlock(Properties.of().strength(3).sound(SoundType.STONE)));
|
h.register(new ResourceLocation(PrettyPipes.ID, "pressurizer"), Registry.pressurizerBlock = new PressurizerBlock());
|
||||||
});
|
});
|
||||||
|
|
||||||
event.register(Registries.ITEM, h -> {
|
event.register(Registries.ITEM, h -> {
|
||||||
|
@ -209,6 +210,10 @@ public final class Registry {
|
||||||
helper.register(new ResourceLocation(PrettyPipes.ID, tier.name().toLowerCase(Locale.ROOT) + "_" + name), item.apply(name, tier));
|
helper.register(new ResourceLocation(PrettyPipes.ID, tier.name().toLowerCase(Locale.ROOT) + "_" + name), item.apply(name, tier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setup(FMLCommonSetupEvent event) {
|
||||||
|
PacketHandler.setup();
|
||||||
|
}
|
||||||
|
|
||||||
public static final class Client {
|
public static final class Client {
|
||||||
|
|
||||||
public static void setup(FMLClientSetupEvent event) {
|
public static void setup(FMLClientSetupEvent event) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.ellpeck.prettypipes.compat.jei;
|
||||||
import de.ellpeck.prettypipes.Registry;
|
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.packets.PacketHandler;
|
||||||
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.RecipeTypes;
|
||||||
import mezz.jei.api.constants.VanillaTypes;
|
import mezz.jei.api.constants.VanillaTypes;
|
||||||
|
@ -16,7 +17,6 @@ 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.CraftingRecipe;
|
||||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -63,7 +63,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));
|
PacketHandler.sendToServer(new PacketCraftingModuleTransfer(inputs, outputs));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package de.ellpeck.prettypipes.compat.jei;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
||||||
import mezz.jei.api.constants.RecipeTypes;
|
import mezz.jei.api.constants.RecipeTypes;
|
||||||
import mezz.jei.api.constants.VanillaTypes;
|
import mezz.jei.api.constants.VanillaTypes;
|
||||||
|
@ -14,7 +15,6 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -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));
|
PacketHandler.sendToServer(new PacketGhostSlot(container.getTile().getBlockPos(), stacks));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,15 @@ package de.ellpeck.prettypipes.misc;
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
import de.ellpeck.prettypipes.packets.*;
|
|
||||||
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.minecraft.resources.ResourceLocation;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.minecraft.world.level.Level;
|
||||||
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.event.server.ServerStartingEvent;
|
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
||||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.Mod;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -61,15 +61,4 @@ public final class Events {
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onPayloadRegister(final RegisterPayloadHandlerEvent event) {
|
|
||||||
var registrar = event.registrar(PrettyPipes.ID);
|
|
||||||
registrar.play(PacketItemEnterPipe.ID, PacketItemEnterPipe::new, PacketItemEnterPipe::onMessage);
|
|
||||||
registrar.play(PacketButton.ID, PacketButton::new, PacketButton::onMessage);
|
|
||||||
registrar.play(PacketCraftingModuleTransfer.ID, PacketCraftingModuleTransfer::new, PacketCraftingModuleTransfer::onMessage);
|
|
||||||
registrar.play(PacketGhostSlot.ID, PacketGhostSlot::new, PacketGhostSlot::onMessage);
|
|
||||||
registrar.play(PacketNetworkItems.ID, PacketNetworkItems::new, PacketNetworkItems::onMessage);
|
|
||||||
registrar.play(PacketRequest.ID, PacketRequest::new, PacketRequest::onMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.google.common.collect.Streams;
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.misc.ItemEquality;
|
import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.packets.PacketItemEnterPipe;
|
import de.ellpeck.prettypipes.packets.PacketItemEnterPipe;
|
||||||
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
import de.ellpeck.prettypipes.pipe.PipeBlock;
|
||||||
|
@ -21,7 +22,6 @@ import net.minecraft.world.item.ItemStack;
|
||||||
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;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.jgrapht.ListenableGraph;
|
import org.jgrapht.ListenableGraph;
|
||||||
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
|
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
|
||||||
|
@ -206,7 +206,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));
|
PacketHandler.sendToAllLoaded(this.level, startPipePos, new PacketItemEnterPipe(startPipePos, item));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package de.ellpeck.prettypipes.packets;
|
package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.items.IModule;
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||||
|
@ -15,27 +14,23 @@ import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.MenuProvider;
|
import net.minecraft.world.MenuProvider;
|
||||||
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.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
|
||||||
import org.apache.logging.log4j.util.TriConsumer;
|
import org.apache.logging.log4j.util.TriConsumer;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static de.ellpeck.prettypipes.misc.DirectionSelector.IDirectionContainer;
|
import static de.ellpeck.prettypipes.misc.DirectionSelector.IDirectionContainer;
|
||||||
|
|
||||||
public class PacketButton implements CustomPacketPayload {
|
public class PacketButton {
|
||||||
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(PrettyPipes.ID, "button");
|
private BlockPos pos;
|
||||||
|
private ButtonResult result;
|
||||||
private final BlockPos pos;
|
private int[] data;
|
||||||
private final ButtonResult result;
|
|
||||||
private final int[] data;
|
|
||||||
|
|
||||||
public PacketButton(BlockPos pos, ButtonResult result, int... data) {
|
public PacketButton(BlockPos pos, ButtonResult result, int... data) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
|
@ -43,33 +38,38 @@ public class PacketButton implements CustomPacketPayload {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketButton(FriendlyByteBuf buf) {
|
private PacketButton() {
|
||||||
this.pos = buf.readBlockPos();
|
|
||||||
this.result = ButtonResult.values()[buf.readByte()];
|
|
||||||
this.data = buf.readVarIntArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PacketButton fromBytes(FriendlyByteBuf buf) {
|
||||||
|
var packet = new PacketButton();
|
||||||
|
packet.pos = buf.readBlockPos();
|
||||||
|
packet.result = ButtonResult.values()[buf.readByte()];
|
||||||
|
packet.data = buf.readVarIntArray();
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toBytes(PacketButton packet, FriendlyByteBuf buf) {
|
||||||
|
buf.writeBlockPos(packet.pos);
|
||||||
|
buf.writeByte(packet.result.ordinal());
|
||||||
|
buf.writeVarIntArray(packet.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Convert2Lambda")
|
||||||
|
public static void onMessage(PacketButton message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void write(FriendlyByteBuf buf) {
|
public void run() {
|
||||||
buf.writeBlockPos(this.pos);
|
Player player = ctx.get().getSender();
|
||||||
buf.writeByte(this.result.ordinal());
|
|
||||||
buf.writeVarIntArray(this.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id() {
|
|
||||||
return PacketButton.ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onMessage(PacketButton message, PlayPayloadContext ctx) {
|
|
||||||
ctx.workHandler().execute(() -> {
|
|
||||||
var player = ctx.player().orElseThrow();
|
|
||||||
message.result.action.accept(message.pos, message.data, player);
|
message.result.action.accept(message.pos, message.data, player);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendAndExecute(BlockPos pos, ButtonResult result, int... data) {
|
public static void sendAndExecute(BlockPos pos, ButtonResult result, int... data) {
|
||||||
PacketDistributor.SERVER.noArg().send(new PacketButton(pos, result, data));
|
PacketHandler.sendToServer(new PacketButton(pos, result, data));
|
||||||
result.action.accept(pos, data, Minecraft.getInstance().player);
|
result.action.accept(pos, data, Minecraft.getInstance().player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,10 +77,10 @@ public class PacketButton implements CustomPacketPayload {
|
||||||
PIPE_TAB((pos, data, player) -> {
|
PIPE_TAB((pos, data, player) -> {
|
||||||
var tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level(), pos);
|
var tile = Utility.getBlockEntity(PipeBlockEntity.class, player.level(), pos);
|
||||||
if (data[0] < 0) {
|
if (data[0] < 0) {
|
||||||
player.openMenu(tile, pos);
|
NetworkHooks.openScreen((ServerPlayer) player, tile, pos);
|
||||||
} else {
|
} else {
|
||||||
var stack = tile.modules.getStackInSlot(data[0]);
|
var stack = tile.modules.getStackInSlot(data[0]);
|
||||||
player.openMenu(new MenuProvider() {
|
NetworkHooks.openScreen((ServerPlayer) player, new MenuProvider() {
|
||||||
@Override
|
@Override
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
return stack.getHoverName();
|
return stack.getHoverName();
|
||||||
|
@ -133,5 +133,4 @@ public class PacketButton implements CustomPacketPayload {
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +1,66 @@
|
||||||
package de.ellpeck.prettypipes.packets;
|
package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
|
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||||
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
import net.neoforged.neoforge.network.NetworkEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PacketCraftingModuleTransfer implements CustomPacketPayload {
|
public class PacketCraftingModuleTransfer {
|
||||||
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(PrettyPipes.ID, "crafting_module_transfer");
|
private List<ItemStack> inputs;
|
||||||
|
private List<ItemStack> outputs;
|
||||||
private final List<ItemStack> inputs;
|
|
||||||
private final List<ItemStack> outputs;
|
|
||||||
|
|
||||||
public PacketCraftingModuleTransfer(List<ItemStack> inputs, List<ItemStack> outputs) {
|
public PacketCraftingModuleTransfer(List<ItemStack> inputs, List<ItemStack> outputs) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
this.outputs = outputs;
|
this.outputs = outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketCraftingModuleTransfer(FriendlyByteBuf buf) {
|
private PacketCraftingModuleTransfer() {
|
||||||
this.inputs = new ArrayList<>();
|
|
||||||
for (var i = buf.readInt(); i > 0; i--)
|
|
||||||
this.inputs.add(buf.readItem());
|
|
||||||
this.outputs = new ArrayList<>();
|
|
||||||
for (var i = buf.readInt(); i > 0; i--)
|
|
||||||
this.outputs.add(buf.readItem());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static PacketCraftingModuleTransfer fromBytes(FriendlyByteBuf buf) {
|
||||||
public void write(FriendlyByteBuf buf) {
|
var packet = new PacketCraftingModuleTransfer();
|
||||||
buf.writeInt(this.inputs.size());
|
packet.inputs = new ArrayList<>();
|
||||||
for (var stack : this.inputs)
|
for (var i = buf.readInt(); i > 0; i--)
|
||||||
|
packet.inputs.add(buf.readItem());
|
||||||
|
packet.outputs = new ArrayList<>();
|
||||||
|
for (var i = buf.readInt(); i > 0; i--)
|
||||||
|
packet.outputs.add(buf.readItem());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toBytes(PacketCraftingModuleTransfer packet, FriendlyByteBuf buf) {
|
||||||
|
buf.writeInt(packet.inputs.size());
|
||||||
|
for (var stack : packet.inputs)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
buf.writeInt(this.outputs.size());
|
buf.writeInt(packet.outputs.size());
|
||||||
for (var stack : this.outputs)
|
for (var stack : packet.outputs)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Convert2Lambda")
|
||||||
|
public static void onMessage(PacketCraftingModuleTransfer message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public void run() {
|
||||||
return PacketCraftingModuleTransfer.ID;
|
Player player = ctx.get().getSender();
|
||||||
}
|
|
||||||
|
|
||||||
public static void onMessage(PacketCraftingModuleTransfer message, PlayPayloadContext ctx) {
|
|
||||||
ctx.workHandler().execute(() -> {
|
|
||||||
var player = ctx.player().orElseThrow();
|
|
||||||
if (player.containerMenu instanceof CraftingModuleContainer container) {
|
if (player.containerMenu instanceof CraftingModuleContainer container) {
|
||||||
PacketCraftingModuleTransfer.copy(container.input, message.inputs);
|
PacketCraftingModuleTransfer.copy(container.input, message.inputs);
|
||||||
PacketCraftingModuleTransfer.copy(container.output, message.outputs);
|
PacketCraftingModuleTransfer.copy(container.output, message.outputs);
|
||||||
container.modified = true;
|
container.modified = true;
|
||||||
container.broadcastChanges();
|
container.broadcastChanges();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
||||||
|
@ -67,5 +69,4 @@ public class PacketCraftingModuleTransfer implements CustomPacketPayload {
|
||||||
for (var stack : contents)
|
for (var stack : contents)
|
||||||
ItemHandlerHelper.insertItem(container, stack, false);
|
ItemHandlerHelper.insertItem(container, stack, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,62 +2,86 @@ package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlockEntity;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
|
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.Items;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
import net.neoforged.neoforge.network.NetworkEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PacketGhostSlot implements CustomPacketPayload {
|
public class PacketGhostSlot {
|
||||||
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(PrettyPipes.ID, "ghost_slot");
|
private BlockPos pos;
|
||||||
|
private List<Entry> stacks;
|
||||||
private final BlockPos pos;
|
|
||||||
private final List<Entry> stacks;
|
|
||||||
|
|
||||||
public PacketGhostSlot(BlockPos pos, List<Entry> stacks) {
|
public PacketGhostSlot(BlockPos pos, List<Entry> stacks) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.stacks = stacks;
|
this.stacks = stacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketGhostSlot(FriendlyByteBuf buf) {
|
private PacketGhostSlot() {
|
||||||
this.pos = buf.readBlockPos();
|
|
||||||
this.stacks = new ArrayList<>();
|
|
||||||
for (var i = buf.readInt(); i > 0; i--)
|
|
||||||
this.stacks.add(new Entry(buf));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static PacketGhostSlot fromBytes(FriendlyByteBuf buf) {
|
||||||
public void write(FriendlyByteBuf buf) {
|
var packet = new PacketGhostSlot();
|
||||||
buf.writeBlockPos(this.pos);
|
packet.pos = buf.readBlockPos();
|
||||||
buf.writeInt(this.stacks.size());
|
packet.stacks = new ArrayList<>();
|
||||||
for (var entry : this.stacks)
|
for (var i = buf.readInt(); i > 0; i--)
|
||||||
|
packet.stacks.add(new Entry(buf));
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toBytes(PacketGhostSlot packet, FriendlyByteBuf buf) {
|
||||||
|
buf.writeBlockPos(packet.pos);
|
||||||
|
buf.writeInt(packet.stacks.size());
|
||||||
|
for (var entry : packet.stacks)
|
||||||
entry.write(buf);
|
entry.write(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("Convert2Lambda")
|
||||||
public ResourceLocation id() {
|
public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
return PacketGhostSlot.ID;
|
var doIt = (Consumer<Player>) p -> {
|
||||||
}
|
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.level(), message.pos);
|
||||||
|
|
||||||
public static void onMessage(PacketGhostSlot message, PlayPayloadContext ctx) {
|
|
||||||
var player = ctx.player().orElseThrow();
|
|
||||||
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, player.level(), message.pos);
|
|
||||||
if (tile != null)
|
if (tile != null)
|
||||||
tile.setGhostItems(message.stacks);
|
tile.setGhostItems(message.stacks);
|
||||||
|
};
|
||||||
|
|
||||||
|
// this whole thing is a dirty hack for allowing the same packet to be used
|
||||||
|
// both client -> server and server -> client without any classloading issues
|
||||||
|
Player player = ctx.get().getSender();
|
||||||
|
// are we on the client?
|
||||||
|
if (player == null) {
|
||||||
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
doIt.accept(Minecraft.getInstance().player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
doIt.accept(player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
|
@ -91,12 +115,12 @@ public class PacketGhostSlot implements CustomPacketPayload {
|
||||||
public List<ItemStack> getStacks(Level level) {
|
public List<ItemStack> getStacks(Level level) {
|
||||||
if (this.stacks != null)
|
if (this.stacks != null)
|
||||||
return this.stacks;
|
return this.stacks;
|
||||||
return Streams.stream(level.registryAccess().registry(Registries.ITEM).orElseThrow().getTagOrEmpty(this.tag).iterator())
|
return Streams.stream(level.registryAccess().registry(Registries.ITEM).get().getTagOrEmpty(this.tag).iterator())
|
||||||
.filter(h -> h.value() != null & h.value() != Items.AIR)
|
.filter(h -> h.value() != null & h.value() != Items.AIR)
|
||||||
.map(h -> new ItemStack(h.value())).collect(Collectors.toList());
|
.map(h -> new ItemStack(h.value())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(FriendlyByteBuf buf) {
|
public FriendlyByteBuf write(FriendlyByteBuf buf) {
|
||||||
if (this.stacks != null) {
|
if (this.stacks != null) {
|
||||||
buf.writeBoolean(true);
|
buf.writeBoolean(true);
|
||||||
buf.writeInt(this.stacks.size());
|
buf.writeInt(this.stacks.size());
|
||||||
|
@ -106,10 +130,11 @@ public class PacketGhostSlot implements CustomPacketPayload {
|
||||||
buf.writeBoolean(false);
|
buf.writeBoolean(false);
|
||||||
buf.writeUtf(this.tag.location().toString());
|
buf.writeUtf(this.tag.location().toString());
|
||||||
}
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TagKey<Item> getTagForStacks(Level level, List<ItemStack> stacks) {
|
private static TagKey<Item> getTagForStacks(Level level, List<ItemStack> stacks) {
|
||||||
return level.registryAccess().registry(Registries.ITEM).orElseThrow().getTags().filter(e -> {
|
return level.registryAccess().registry(Registries.ITEM).get().getTags().filter(e -> {
|
||||||
var tag = e.getSecond();
|
var tag = e.getSecond();
|
||||||
if (tag.size() != stacks.size())
|
if (tag.size() != stacks.size())
|
||||||
return false;
|
return false;
|
||||||
|
@ -120,7 +145,5 @@ public class PacketGhostSlot implements CustomPacketPayload {
|
||||||
return true;
|
return true;
|
||||||
}).map(Pair::getFirst).findFirst().orElse(null);
|
}).map(Pair::getFirst).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
|
import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
import net.neoforged.neoforge.network.simple.SimpleChannel;
|
||||||
|
import net.neoforged.neoforge.network.NetworkRegistry;
|
||||||
|
|
||||||
|
public final class PacketHandler {
|
||||||
|
|
||||||
|
private static final String VERSION = "1";
|
||||||
|
private static SimpleChannel network;
|
||||||
|
|
||||||
|
public static void setup() {
|
||||||
|
PacketHandler.network = NetworkRegistry.newSimpleChannel(new ResourceLocation(PrettyPipes.ID, "network"), () -> PacketHandler.VERSION, PacketHandler.VERSION::equals, PacketHandler.VERSION::equals);
|
||||||
|
PacketHandler.network.registerMessage(0, PacketItemEnterPipe.class, PacketItemEnterPipe::toBytes, PacketItemEnterPipe::fromBytes, PacketItemEnterPipe::onMessage);
|
||||||
|
PacketHandler.network.registerMessage(1, PacketButton.class, PacketButton::toBytes, PacketButton::fromBytes, PacketButton::onMessage);
|
||||||
|
PacketHandler.network.registerMessage(2, PacketNetworkItems.class, PacketNetworkItems::toBytes, PacketNetworkItems::fromBytes, PacketNetworkItems::onMessage);
|
||||||
|
PacketHandler.network.registerMessage(3, PacketRequest.class, PacketRequest::toBytes, PacketRequest::fromBytes, PacketRequest::onMessage);
|
||||||
|
PacketHandler.network.registerMessage(4, PacketGhostSlot.class, PacketGhostSlot::toBytes, PacketGhostSlot::fromBytes, PacketGhostSlot::onMessage);
|
||||||
|
PacketHandler.network.registerMessage(5, PacketCraftingModuleTransfer.class, PacketCraftingModuleTransfer::toBytes, PacketCraftingModuleTransfer::fromBytes, PacketCraftingModuleTransfer::onMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendToAllLoaded(Level world, BlockPos pos, Object message) {
|
||||||
|
PacketHandler.network.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunkAt(pos)), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendTo(Player player, Object message) {
|
||||||
|
PacketHandler.network.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendToServer(Object message) {
|
||||||
|
PacketHandler.network.send(PacketDistributor.SERVER.noArg(), message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package de.ellpeck.prettypipes.packets;
|
package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
import de.ellpeck.prettypipes.pipe.IPipeItem;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||||
|
@ -8,40 +7,41 @@ import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.neoforged.neoforge.network.NetworkEvent;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
|
||||||
|
|
||||||
public class PacketItemEnterPipe implements CustomPacketPayload {
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(PrettyPipes.ID, "item_enter_pipe");
|
public class PacketItemEnterPipe {
|
||||||
|
|
||||||
private final BlockPos tilePos;
|
private BlockPos tilePos;
|
||||||
private final CompoundTag item;
|
private CompoundTag item;
|
||||||
|
|
||||||
public PacketItemEnterPipe(BlockPos tilePos, IPipeItem item) {
|
public PacketItemEnterPipe(BlockPos tilePos, IPipeItem item) {
|
||||||
this.tilePos = tilePos;
|
this.tilePos = tilePos;
|
||||||
this.item = item.serializeNBT();
|
this.item = item.serializeNBT();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketItemEnterPipe(FriendlyByteBuf buf) {
|
private PacketItemEnterPipe() {
|
||||||
this.tilePos = buf.readBlockPos();
|
|
||||||
this.item = buf.readNbt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PacketItemEnterPipe fromBytes(FriendlyByteBuf buf) {
|
||||||
|
var client = new PacketItemEnterPipe();
|
||||||
|
client.tilePos = buf.readBlockPos();
|
||||||
|
client.item = buf.readNbt();
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toBytes(PacketItemEnterPipe packet, FriendlyByteBuf buf) {
|
||||||
|
buf.writeBlockPos(packet.tilePos);
|
||||||
|
buf.writeNbt(packet.item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Convert2Lambda")
|
||||||
|
public static void onMessage(PacketItemEnterPipe message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void write(FriendlyByteBuf buf) {
|
public void run() {
|
||||||
buf.writeBlockPos(this.tilePos);
|
|
||||||
buf.writeNbt(this.item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id() {
|
|
||||||
return PacketItemEnterPipe.ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onMessage(PacketItemEnterPipe message, PlayPayloadContext ctx) {
|
|
||||||
ctx.workHandler().execute(() -> {
|
|
||||||
var mc = Minecraft.getInstance();
|
var mc = Minecraft.getInstance();
|
||||||
if (mc.level == null)
|
if (mc.level == null)
|
||||||
return;
|
return;
|
||||||
|
@ -49,7 +49,8 @@ public class PacketItemEnterPipe implements CustomPacketPayload {
|
||||||
var pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
|
var pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
|
||||||
if (pipe != null)
|
if (pipe != null)
|
||||||
pipe.getItems().add(item);
|
pipe.getItems().add(item);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
package de.ellpeck.prettypipes.packets;
|
package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
import net.neoforged.neoforge.network.NetworkEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PacketNetworkItems implements CustomPacketPayload {
|
public class PacketNetworkItems {
|
||||||
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(PrettyPipes.ID, "network_items");
|
private List<ItemStack> items;
|
||||||
|
private List<ItemStack> craftables;
|
||||||
private final List<ItemStack> items;
|
private List<ItemStack> currentlyCrafting;
|
||||||
private final List<ItemStack> craftables;
|
|
||||||
private final List<ItemStack> currentlyCrafting;
|
|
||||||
|
|
||||||
public PacketNetworkItems(List<ItemStack> items, List<ItemStack> craftables, List<ItemStack> currentlyCrafting) {
|
public PacketNetworkItems(List<ItemStack> items, List<ItemStack> craftables, List<ItemStack> currentlyCrafting) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
|
@ -26,46 +22,46 @@ public class PacketNetworkItems implements CustomPacketPayload {
|
||||||
this.currentlyCrafting = currentlyCrafting;
|
this.currentlyCrafting = currentlyCrafting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketNetworkItems(FriendlyByteBuf buf) {
|
private PacketNetworkItems() {
|
||||||
this.items = new ArrayList<>();
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PacketNetworkItems fromBytes(FriendlyByteBuf buf) {
|
||||||
|
var client = new PacketNetworkItems();
|
||||||
|
client.items = new ArrayList<>();
|
||||||
for (var i = buf.readVarInt(); i > 0; i--) {
|
for (var i = buf.readVarInt(); i > 0; i--) {
|
||||||
var stack = buf.readItem();
|
var stack = buf.readItem();
|
||||||
stack.setCount(buf.readVarInt());
|
stack.setCount(buf.readVarInt());
|
||||||
this.items.add(stack);
|
client.items.add(stack);
|
||||||
}
|
}
|
||||||
this.craftables = new ArrayList<>();
|
client.craftables = new ArrayList<>();
|
||||||
for (var i = buf.readVarInt(); i > 0; i--)
|
for (var i = buf.readVarInt(); i > 0; i--)
|
||||||
this.craftables.add(buf.readItem());
|
client.craftables.add(buf.readItem());
|
||||||
this.currentlyCrafting = new ArrayList<>();
|
client.currentlyCrafting = new ArrayList<>();
|
||||||
for (var i = buf.readVarInt(); i > 0; i--)
|
for (var i = buf.readVarInt(); i > 0; i--)
|
||||||
this.currentlyCrafting.add(buf.readItem());
|
client.currentlyCrafting.add(buf.readItem());
|
||||||
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void toBytes(PacketNetworkItems packet, FriendlyByteBuf buf) {
|
||||||
public void write(FriendlyByteBuf buf) {
|
buf.writeVarInt(packet.items.size());
|
||||||
buf.writeVarInt(this.items.size());
|
for (var stack : packet.items) {
|
||||||
for (var stack : this.items) {
|
|
||||||
var copy = stack.copy();
|
var copy = stack.copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
buf.writeItem(copy);
|
buf.writeItem(copy);
|
||||||
buf.writeVarInt(stack.getCount());
|
buf.writeVarInt(stack.getCount());
|
||||||
}
|
}
|
||||||
buf.writeVarInt(this.craftables.size());
|
buf.writeVarInt(packet.craftables.size());
|
||||||
for (var stack : this.craftables)
|
for (var stack : packet.craftables)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
buf.writeVarInt(this.currentlyCrafting.size());
|
buf.writeVarInt(packet.currentlyCrafting.size());
|
||||||
for (var stack : this.currentlyCrafting)
|
for (var stack : packet.currentlyCrafting)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResourceLocation id() {
|
|
||||||
return PacketNetworkItems.ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("Convert2Lambda")
|
@SuppressWarnings("Convert2Lambda")
|
||||||
public static void onMessage(PacketNetworkItems message, PlayPayloadContext ctx) {
|
public static void onMessage(PacketNetworkItems message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
ctx.workHandler().execute(new Runnable() {
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
var mc = Minecraft.getInstance();
|
var mc = Minecraft.getInstance();
|
||||||
|
@ -73,6 +69,6 @@ public class PacketNetworkItems implements CustomPacketPayload {
|
||||||
terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting);
|
terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,62 +1,61 @@
|
||||||
package de.ellpeck.prettypipes.packets;
|
package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
import de.ellpeck.prettypipes.terminal.ItemTerminalBlockEntity;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
|
import net.neoforged.neoforge.network.NetworkEvent;
|
||||||
|
|
||||||
public class PacketRequest implements CustomPacketPayload {
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public static final ResourceLocation ID = new ResourceLocation(PrettyPipes.ID, "request");
|
public class PacketRequest {
|
||||||
|
|
||||||
private final BlockPos pos;
|
private BlockPos pos;
|
||||||
private final ItemStack stack;
|
private ItemStack stack;
|
||||||
private final int nbtHash;
|
private int nbtHash;
|
||||||
private final int amount;
|
private int amount;
|
||||||
|
|
||||||
public PacketRequest(BlockPos pos, ItemStack stack, int amount) {
|
public PacketRequest(BlockPos pos, ItemStack stack, int amount) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.nbtHash = stack.hasTag() ? stack.getTag().hashCode() : 0;
|
if (stack.hasTag())
|
||||||
|
this.nbtHash = stack.getTag().hashCode();
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketRequest(FriendlyByteBuf buf) {
|
private PacketRequest() {
|
||||||
this.pos = buf.readBlockPos();
|
|
||||||
this.stack = buf.readItem();
|
|
||||||
this.nbtHash = buf.readVarInt();
|
|
||||||
this.amount = buf.readVarInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static PacketRequest fromBytes(FriendlyByteBuf buf) {
|
||||||
public void write(FriendlyByteBuf buf) {
|
var packet = new PacketRequest();
|
||||||
buf.writeBlockPos(this.pos);
|
packet.pos = buf.readBlockPos();
|
||||||
buf.writeItem(this.stack);
|
packet.stack = buf.readItem();
|
||||||
buf.writeVarInt(this.nbtHash);
|
packet.nbtHash = buf.readVarInt();
|
||||||
buf.writeVarInt(this.amount);
|
packet.amount = buf.readVarInt();
|
||||||
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void toBytes(PacketRequest packet, FriendlyByteBuf buf) {
|
||||||
public ResourceLocation id() {
|
buf.writeBlockPos(packet.pos);
|
||||||
return PacketRequest.ID;
|
buf.writeItem(packet.stack);
|
||||||
|
buf.writeVarInt(packet.nbtHash);
|
||||||
|
buf.writeVarInt(packet.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("Convert2Lambda")
|
@SuppressWarnings("Convert2Lambda")
|
||||||
public static void onMessage(PacketRequest message, PlayPayloadContext ctx) {
|
public static void onMessage(PacketRequest message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
ctx.workHandler().execute(new Runnable() {
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
var player = ctx.player().orElseThrow();
|
Player player = ctx.get().getSender();
|
||||||
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level(), message.pos);
|
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level(), message.pos);
|
||||||
message.stack.setCount(message.amount);
|
message.stack.setCount(message.amount);
|
||||||
tile.requestItem(player, message.stack, message.nbtHash);
|
tile.requestItem(player, message.stack, message.nbtHash);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package de.ellpeck.prettypipes.pipe;
|
package de.ellpeck.prettypipes.pipe;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.mojang.serialization.MapCodec;
|
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.items.IModule;
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.tags.FluidTags;
|
import net.minecraft.tags.FluidTags;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
|
@ -22,7 +22,6 @@ import net.minecraft.world.level.block.*;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
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.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
@ -47,8 +46,6 @@ import java.util.function.Function;
|
||||||
|
|
||||||
public class PipeBlock extends BaseEntityBlock {
|
public class PipeBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
public static final MapCodec<PipeBlock> CODEC = BlockBehaviour.simpleCodec(PipeBlock::new);
|
|
||||||
|
|
||||||
public static final Map<Direction, EnumProperty<ConnectionType>> DIRECTIONS = new HashMap<>();
|
public static final Map<Direction, EnumProperty<ConnectionType>> DIRECTIONS = new HashMap<>();
|
||||||
private static final Map<Pair<BlockState, BlockState>, VoxelShape> SHAPE_CACHE = new HashMap<>();
|
private static final Map<Pair<BlockState, BlockState>, VoxelShape> SHAPE_CACHE = new HashMap<>();
|
||||||
private static final Map<Pair<BlockState, BlockState>, VoxelShape> COLL_SHAPE_CACHE = new HashMap<>();
|
private static final Map<Pair<BlockState, BlockState>, VoxelShape> COLL_SHAPE_CACHE = new HashMap<>();
|
||||||
|
@ -67,8 +64,8 @@ public class PipeBlock extends BaseEntityBlock {
|
||||||
PipeBlock.DIRECTIONS.put(dir, EnumProperty.create(dir.getName(), ConnectionType.class));
|
PipeBlock.DIRECTIONS.put(dir, EnumProperty.create(dir.getName(), ConnectionType.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PipeBlock(Block.Properties properties) {
|
public PipeBlock() {
|
||||||
super(properties);
|
super(Block.Properties.of().strength(2).sound(SoundType.STONE).noOcclusion());
|
||||||
|
|
||||||
var state = this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false);
|
var state = this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false);
|
||||||
for (var prop : PipeBlock.DIRECTIONS.values())
|
for (var prop : PipeBlock.DIRECTIONS.values())
|
||||||
|
@ -94,7 +91,7 @@ public class PipeBlock extends BaseEntityBlock {
|
||||||
}
|
}
|
||||||
} else if (handIn == InteractionHand.MAIN_HAND && stack.isEmpty()) {
|
} else if (handIn == InteractionHand.MAIN_HAND && stack.isEmpty()) {
|
||||||
if (!worldIn.isClientSide)
|
if (!worldIn.isClientSide)
|
||||||
player.openMenu(tile, pos);
|
NetworkHooks.openScreen((ServerPlayer) player, tile, pos);
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
|
@ -297,11 +294,6 @@ public class PipeBlock extends BaseEntityBlock {
|
||||||
return new PipeBlockEntity(pos, state);
|
return new PipeBlockEntity(pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
|
||||||
return PipeBlock.CODEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderShape getRenderShape(BlockState state) {
|
public RenderShape getRenderShape(BlockState state) {
|
||||||
return RenderShape.MODEL;
|
return RenderShape.MODEL;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.items.IModule;
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
|
@ -13,7 +14,6 @@ import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -152,7 +152,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));
|
PacketHandler.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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package de.ellpeck.prettypipes.pressurizer;
|
package de.ellpeck.prettypipes.pressurizer;
|
||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
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.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
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;
|
||||||
|
@ -15,6 +15,7 @@ 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;
|
||||||
|
import net.minecraft.world.level.block.SoundType;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
@ -27,15 +28,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class PressurizerBlock extends BaseEntityBlock {
|
public class PressurizerBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
public static final MapCodec<PressurizerBlock> CODEC = BlockBehaviour.simpleCodec(PressurizerBlock::new);
|
public PressurizerBlock() {
|
||||||
|
super(BlockBehaviour.Properties.of().strength(3).sound(SoundType.STONE));
|
||||||
public PressurizerBlock(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
|
||||||
return PressurizerBlock.CODEC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,7 +38,7 @@ public class PressurizerBlock extends BaseEntityBlock {
|
||||||
if (tile == null)
|
if (tile == null)
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
if (!worldIn.isClientSide)
|
if (!worldIn.isClientSide)
|
||||||
player.openMenu(tile, pos);
|
NetworkHooks.openScreen((ServerPlayer) player, tile, pos);
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package de.ellpeck.prettypipes.terminal;
|
package de.ellpeck.prettypipes.terminal;
|
||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
@ -8,22 +7,10 @@ import net.minecraft.world.level.block.BaseEntityBlock;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
public class CraftingTerminalBlock extends ItemTerminalBlock {
|
public class CraftingTerminalBlock extends ItemTerminalBlock {
|
||||||
|
|
||||||
public static final MapCodec<CraftingTerminalBlock> CODEC = BlockBehaviour.simpleCodec(CraftingTerminalBlock::new);
|
|
||||||
|
|
||||||
public CraftingTerminalBlock(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
|
||||||
return CraftingTerminalBlock.CODEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @org.jetbrains.annotations.Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
public @org.jetbrains.annotations.Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||||
return new CraftingTerminalBlockEntity(pos, state);
|
return new CraftingTerminalBlockEntity(pos, state);
|
||||||
|
@ -34,5 +21,4 @@ public class CraftingTerminalBlock extends ItemTerminalBlock {
|
||||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
||||||
return BaseEntityBlock.createTickerHelper(type, Registry.craftingTerminalBlockEntity, ItemTerminalBlockEntity::tick);
|
return BaseEntityBlock.createTickerHelper(type, Registry.craftingTerminalBlockEntity, ItemTerminalBlockEntity::tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import de.ellpeck.prettypipes.misc.ItemEquality;
|
||||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
import de.ellpeck.prettypipes.pipe.PipeBlockEntity;
|
||||||
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
@ -23,7 +24,6 @@ import net.minecraft.world.item.ItemStack;
|
||||||
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;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
import org.apache.commons.lang3.mutable.MutableInt;
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -98,7 +98,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));
|
PacketHandler.sendToAllLoaded(this.level, this.getBlockPos(), new PacketGhostSlot(this.getBlockPos(), clients));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,5 +244,4 @@ public class CraftingTerminalBlockEntity extends ItemTerminalBlockEntity {
|
||||||
}
|
}
|
||||||
return lowestAvailable;
|
return lowestAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package de.ellpeck.prettypipes.terminal;
|
package de.ellpeck.prettypipes.terminal;
|
||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
|
||||||
import de.ellpeck.prettypipes.Registry;
|
import de.ellpeck.prettypipes.Registry;
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import net.minecraft.ChatFormatting;
|
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.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
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;
|
||||||
|
@ -16,10 +16,10 @@ 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;
|
||||||
|
import net.minecraft.world.level.block.SoundType;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -28,15 +28,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class ItemTerminalBlock extends BaseEntityBlock {
|
public class ItemTerminalBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
public static final MapCodec<ItemTerminalBlock> CODEC = BlockBehaviour.simpleCodec(ItemTerminalBlock::new);
|
public ItemTerminalBlock() {
|
||||||
|
super(Properties.of().strength(3).sound(SoundType.STONE));
|
||||||
public ItemTerminalBlock(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
|
||||||
return ItemTerminalBlock.CODEC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,7 +44,7 @@ public class ItemTerminalBlock extends BaseEntityBlock {
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
if (!worldIn.isClientSide) {
|
if (!worldIn.isClientSide) {
|
||||||
player.openMenu(tile, pos);
|
NetworkHooks.openScreen((ServerPlayer) player, tile, pos);
|
||||||
tile.updateItems(player);
|
tile.updateItems(player);
|
||||||
}
|
}
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import de.ellpeck.prettypipes.network.NetworkItem;
|
||||||
import de.ellpeck.prettypipes.network.NetworkLocation;
|
import de.ellpeck.prettypipes.network.NetworkLocation;
|
||||||
import de.ellpeck.prettypipes.network.NetworkLock;
|
import de.ellpeck.prettypipes.network.NetworkLock;
|
||||||
import de.ellpeck.prettypipes.network.PipeNetwork;
|
import de.ellpeck.prettypipes.network.PipeNetwork;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.packets.PacketNetworkItems;
|
import de.ellpeck.prettypipes.packets.PacketNetworkItems;
|
||||||
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
import de.ellpeck.prettypipes.pipe.ConnectionType;
|
||||||
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
|
||||||
|
@ -21,7 +22,6 @@ 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;
|
||||||
import net.minecraft.network.chat.Style;
|
import net.minecraft.network.chat.Style;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.MenuProvider;
|
import net.minecraft.world.MenuProvider;
|
||||||
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;
|
||||||
|
@ -141,7 +141,7 @@ public class ItemTerminalBlockEntity extends BlockEntity implements IPipeConnect
|
||||||
continue;
|
continue;
|
||||||
if (container.tile != this)
|
if (container.tile != this)
|
||||||
continue;
|
continue;
|
||||||
((ServerPlayer) player).connection.send(new PacketNetworkItems(clientItems, clientCraftables, currentlyCrafting));
|
PacketHandler.sendTo(player, new PacketNetworkItems(clientItems, clientCraftables, currentlyCrafting));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,13 @@ package de.ellpeck.prettypipes.terminal.containers;
|
||||||
import com.mojang.blaze3d.platform.InputConstants;
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
import de.ellpeck.prettypipes.PrettyPipes;
|
import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.neoforged.neoforge.network.PacketDistributor;
|
|
||||||
|
|
||||||
public class CraftingTerminalGui extends ItemTerminalGui {
|
public class CraftingTerminalGui extends ItemTerminalGui {
|
||||||
|
|
||||||
|
@ -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));
|
PacketHandler.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();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
|
||||||
super.renderLabels(graphics, mouseX, mouseY);
|
super.renderLabels(graphics, mouseX, mouseY);
|
||||||
|
@ -81,5 +82,4 @@ public class CraftingTerminalGui extends ItemTerminalGui {
|
||||||
protected CraftingTerminalContainer getCraftingContainer() {
|
protected CraftingTerminalContainer getCraftingContainer() {
|
||||||
return (CraftingTerminalContainer) this.menu;
|
return (CraftingTerminalContainer) this.menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import de.ellpeck.prettypipes.PrettyPipes;
|
||||||
import de.ellpeck.prettypipes.misc.ItemTerminalWidget;
|
import de.ellpeck.prettypipes.misc.ItemTerminalWidget;
|
||||||
import de.ellpeck.prettypipes.misc.PlayerPrefs;
|
import de.ellpeck.prettypipes.misc.PlayerPrefs;
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||||
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import de.ellpeck.prettypipes.packets.PacketRequest;
|
import de.ellpeck.prettypipes.packets.PacketRequest;
|
||||||
import joptsimple.internal.Strings;
|
import joptsimple.internal.Strings;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
@ -22,7 +23,6 @@ import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
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 org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -91,7 +91,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));
|
PacketHandler.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 +159,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));
|
PacketHandler.sendToServer(new PacketButton(this.menu.tile.getBlockPos(), PacketButton.ButtonResult.CANCEL_CRAFTING));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue