Start adding a chest gui system
This commit is contained in:
parent
d237912942
commit
a8048391a0
10 changed files with 357 additions and 16 deletions
|
@ -0,0 +1,55 @@
|
|||
package dev.zontreck.libzontreck.networking.packets;
|
||||
|
||||
import dev.zontreck.libzontreck.events.GUIButtonClickedEvent;
|
||||
import dev.zontreck.libzontreck.vectors.Vector2;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class C2SChestGUIButtonClicked
|
||||
{
|
||||
private ItemStack stack;
|
||||
private ResourceLocation id;
|
||||
private UUID player;
|
||||
|
||||
public C2SChestGUIButtonClicked(ItemStack stack, ResourceLocation id)
|
||||
{
|
||||
this.stack = stack;
|
||||
|
||||
this.id = id;
|
||||
player = Minecraft.getInstance().player.getUUID();
|
||||
}
|
||||
|
||||
public C2SChestGUIButtonClicked(FriendlyByteBuf buf)
|
||||
{
|
||||
stack = buf.readItem();
|
||||
id = buf.readResourceLocation();
|
||||
}
|
||||
|
||||
public void toBytes(FriendlyByteBuf buf)
|
||||
{
|
||||
buf.writeItem(stack);
|
||||
buf.writeResourceLocation(id);
|
||||
}
|
||||
|
||||
public boolean handle(Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
NetworkEvent.Context context = ctx.get();
|
||||
|
||||
context.enqueueWork(()->{
|
||||
// We're on the server now.
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new GUIButtonClickedEvent(stack, id, player));
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -2,9 +2,11 @@ package dev.zontreck.libzontreck.networking.packets;
|
|||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import dev.zontreck.libzontreck.events.OpenGUIEvent;
|
||||
import dev.zontreck.libzontreck.networking.structures.OpenGUIRequest;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
|
||||
/**
|
||||
|
@ -36,6 +38,8 @@ public class ChestGUIOpenC2S {
|
|||
ctx.enqueueWork(()->{
|
||||
// We are on the server!
|
||||
OpenGUIRequest req = new OpenGUIRequest(data);
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new OpenGUIEvent(req.ID, req.playerID));
|
||||
});
|
||||
|
||||
return true;
|
||||
|
|
Reference in a new issue