
-
[1.16.4] How to prevent hoppers/other similar item extractors from accessing my container
I forgot to do it! Thanks for the help everyone!
-
[1.16.4] How to prevent hoppers/other similar item extractors from accessing my container
If I return the empty LazyOptional, hoppers still can steal items out of it. The same happens if I don't override it.
-
[1.16.4] How to prevent hoppers/other similar item extractors from accessing my container
Could you please explain how do I do that? I have this: @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nonnull Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return itemHandler.cast(); } return super.getCapability(cap, side); } private IItemHandlerModifiable createHandler() { return new InvWrapper(this); } @Override public void remove() { super.remove(); if(itemHandler != null) { itemHandler.invalidate(); } } What should I do now? I tried to make the getCapability to return null, but it crashed. (I'm sorry, I'm still a begginer)
-
[1.16.4] How to prevent hoppers/other similar item extractors from accessing my container
I know that it has something to do with getCapability function in the container class, but I am not sure what it should return for the hoppers to be unable to access it. I've seen a similar topic for 1.12, but how do I make it work with 1.16?
-
[1.16.4] Send new TileEntity NBT to the server
If I understand correctly, the last parameter of the registerMessage() function is the method that handles the data, right? I'm not sure if I understood the documentation.
-
[1.16.4] Send new TileEntity NBT to the server
Okay, I think It might work now, but I still have no idea when to register them. Should it be done from the main mod class or is there a registry event for that? also, how do I make it actually handle it? I may be not experienced enough to understand it, but I don't think that just putting a "handle()" method will work.
-
[1.16.4] Send new TileEntity NBT to the server
INSTANCE.registerMessage(0, CSendNBTPacket.class ,CSendNBTPacket::encode, CSendNBTPacket::decode, CSendNBTPacket::ctx); public class CSendNBTPacket { public PacketBuffer encode(CSendNBTPacket packet) { return null; } public CSendNBTPacket decode(PacketBuffer buffer) { } public Supplier<NetworkEvent.Context> ctx() { return null; } } What am I doing wrong here? (ignoring the "return null;" part)
-
[1.16.4] Send new TileEntity NBT to the server
So.. how do I exactly handle it? And register it? I don't understand the docs, especially the "Registering Packets". I understand that the packet class should have functions for encoding and decoding the packets, but I don't really know how they should work.
-
[1.16.4] Send new TileEntity NBT to the server
I saw how it is made for the CommandBlockScreen, but I am not sure how to handle these packets. Also, the button just sends a TextField to the server, and it is checked again there - I just need to send two integers. I tried implementing it with SimpleChannels, but I saw that Minecraft uses a custom packet.
-
[1.16.4] Send new TileEntity NBT to the server
I am trying to send a NBT update to the client when a GUI button is clicked. I tried just setting the value, but it looks like it is only set for the client TileEntity, and not the server one. How can I send the value to the server? I've seen that Minecraft uses a custom packet for that, but I have no idea how to use them, and I don't understand the documetion.
-
[1.16.4] Register recipe type - cannot join server
Thank you! I somehow overlooked that in my code and spent a few hours searching for the solution.
-
[1.16.4] Register recipe type - cannot join server
I'm posting this in a different thread, because it is a little different then just creating a recipe. So I managed to make my custom recipe work, but it only works for singleplayer. When I try to join a server, the client throws Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException I am registering the recipe here: @SubscribeEvent public static void onRecipeRegistry(final RegistryEvent.Register<IRecipeSerializer<?>> recipeRegistryEvent) { LOGGER.info("Recipe registry!"); SpecialRecipeSerializer<MusicCloningRecipe> musicCloningRecipe = (SpecialRecipeSerializer<MusicCloningRecipe>) new SpecialRecipeSerializer<>(MusicCloningRecipe::new).setRegistryName("crafting_special_musiccloning"); recipeRegistryEvent.getRegistry().register( musicCloningRecipe ); } And it is kept here: @ObjectHolder("musicblock") class Recipes { public static final SpecialRecipeSerializer<MusicCloningRecipe> CRAFTING_SPECIAL_MUSICCLONING = null; } The recipe code: package xyz.bajtix.musicblock; import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.item.WrittenBookItem; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.SpecialRecipe; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class MusicCloningRecipe extends SpecialRecipe { public MusicCloningRecipe(ResourceLocation idIn) { super(idIn); } public boolean matches(CraftingInventory inv, World worldIn) { int i = 0; boolean oneHasData = false; for(int j = 0; j < inv.getSizeInventory(); ++j) { if(inv.getStackInSlot(j).getItem() == ItemList.musicBlock) { i++; if(inv.getStackInSlot(j).hasTag() && inv.getStackInSlot(j).getTag().contains("music")) oneHasData = !oneHasData; } } return i == 2 && oneHasData; } /** * Returns an Item that is the result of this recipe * * @param inv */ @Override public ItemStack getCraftingResult(CraftingInventory inv) { int i = 0; CompoundNBT data = null; for(int j = 0; j < inv.getSizeInventory(); ++j) { if(inv.getStackInSlot(j).getItem() == ItemList.musicBlock) { i++; if(inv.getStackInSlot(j).hasTag() && inv.getStackInSlot(j).getTag().contains("music")) data = inv.getStackInSlot(j).getTag(); } } if(data == null) return null; ItemStack stack = new ItemStack(ItemList.musicBlock,1,data); stack.setTag(data); return stack; } @Override public NonNullList<ItemStack> getRemainingItems(CraftingInventory inv) { NonNullList<ItemStack> itemlist = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY); for(int i = 0; i < itemlist.size(); ++i) { ItemStack itemstack = inv.getStackInSlot(i); if (itemstack.hasContainerItem()) { itemlist.set(i, itemstack.getContainerItem()); } else if (itemstack.getItem() == ItemList.musicBlock) { ItemStack itemstack1 = itemstack.copy(); itemstack1.setCount(1); itemlist.set(i, itemstack1); break; } } return itemlist; } /** * Used to determine if this recipe can fit in a grid of the given width/height * * @param width * @param height */ @Override public boolean canFit(int width, int height) { return width >= 2 && height >= 2; } @Override public IRecipeSerializer<?> getSerializer() { return null; } } And it is registered in an @OjectHolder class Could someone please tell me what am I doing wrong? I couldn't really find a good documentation for it.
-
[1.16.4] How to copy NBT between recipe ingredients and result?
So I managed to make it work, but it only works for singleplayer. When I try to join a server, the client throws Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException I am registering the recipe here: @SubscribeEvent public static void onRecipeRegistry(final RegistryEvent.Register<IRecipeSerializer<?>> recipeRegistryEvent) { LOGGER.info("Recipe registry!"); SpecialRecipeSerializer<MusicCloningRecipe> musicCloningRecipe = (SpecialRecipeSerializer<MusicCloningRecipe>) new SpecialRecipeSerializer<>(MusicCloningRecipe::new).setRegistryName("crafting_special_musiccloning"); recipeRegistryEvent.getRegistry().register( musicCloningRecipe ); } And it is kept here: @ObjectHolder("musicblock") class Recipes { public static final SpecialRecipeSerializer<MusicCloningRecipe> CRAFTING_SPECIAL_MUSICCLONING = null; } Could someone please tell me what am I doing wrong? I couldn't really find a good documentation for it.
-
[SOLVED] [1.16.4] Send chat message from remote world
I managed to resolve the issue now, with the debugger. The problem was that altough the method PlayerEntity#sendMessage with null as the sender ID works just fine on singleplayer server, but when run on a remote server throws an exception. The solution that worked was just giving the player's UUID as the senderID. Thanks for the help!
-
[SOLVED] [1.16.4] Send chat message from remote world
After rebooting my PC and reinstalling gradle it finally worked, so maybe it was some problem with an application already using the port? I have no idea, but now the server runs. I was also able to use the debugger; The function runs and the player is not null, everything looks like it should work but the chat message still isn't sent.
IPS spam blocked by CleanTalk.