Jump to content

MrMarnic

Members
  • Posts

    39
  • Joined

  • Last visited

Posts posted by MrMarnic

  1. Firstly you forgot the semicolon at the end of this line 

    public static final RegistryObject<Item> TESTITEM = ITEMS.register("testitem", () -> new TestItem(new Item.Properties()))

    The second thing:

    In this line here:

    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);

    You are using the variable MODID but you have never created it.

    You need to create it like this:

    public static final String MODID = "<your modid>";

    Then it should work

  2. @LexManos and @diesieben07 I have found the real reason for the error message. It was the formatting of drive.

    Steps to reproduce (on Windows):

    • Use a working drive/flash drive.
    • Format it with NTFS => put the project folder on it => everything works fine
    • Format it with ExFAT or FAT32 => put the project folder on it => I get the error message

    I have tested it out with a working usb stick.

    On NTFS => everything is working

    ON FAT32/ExFat =>I get the error

     

    I don't know why this is happening, but this seems to be the reason.

  3. 3 minutes ago, Draco18s said:

    I'm not sure that this can be fixed. The client has authoratative control over their inventory when in creative mode (that's literally how it works, the client says "yeah, this slot is X now"). As such moving an item from one slot to another has the effect of destroying and recreating the stack (pickup: "this slot is now air", place: "this slot is now a backpack"). Unless the client knew about the capability (and its data), then the capability gets reset (and even then, the client would have to know to send that cap data to the server).

    Ok I undestand that. But can I maybe send the capability trough getShareTag() ? Or is this not possible at all and I can not create a Backpack item with capabilites?

  4. I have attached an inventory to an item with the slot size of one (At the beggining the slot is empty).

    When you right click with this item a gold ingot will be set in the slot.

    If you sneak and right click the Display name of the inserted item will be printed. (At first "Air" because not item is set)

     

    The issue was already adressed here, but there was never as solution.

    Old issue

    public class InventoryTestItem extends Item {
        public InventoryTestItem(Properties properties) {
            super(properties);
            setRegistryName("inv_test");
        }
    
        @Override
        public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
            if(playerIn.isSneaking()) {
                playerIn.getHeldItem(handIn).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,null).ifPresent((h)-> {
                    ItemStackHandler handler = (ItemStackHandler) h;
                    handler.setStackInSlot(0,new ItemStack(Items.GOLD_INGOT));
                });
            }else {
                playerIn.getHeldItem(handIn).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,null).ifPresent((h)-> {
                    ItemStackHandler handler = (ItemStackHandler) h;
                    System.out.println(handler.getStackInSlot(0).getDisplayName());
                });
            }
            return super.onItemRightClick(worldIn, playerIn, handIn);
        }
    
        @Nullable
        @Override
        public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
            return new InventoryTestProvider();
        }
    
        public class InventoryTestProvider implements ICapabilityProvider, ICapabilitySerializable<CompoundNBT> {
    
            public ItemStackHandler handler;
    
            public InventoryTestProvider() {
                this.handler = new ItemStackHandler(1);
            }
    
            @Nonnull
            @Override
            public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction side) {
                if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
                    return LazyOptional.of(()->(T)handler);
                }
                return LazyOptional.empty();
            }
    
            @Override
            public CompoundNBT serializeNBT() {
                CompoundNBT tag = new CompoundNBT();
                tag.put("itemHandler",handler.serializeNBT());
                return tag;
            }
    
            @Override
            public void deserializeNBT(CompoundNBT nbt) {
                handler.deserializeNBT(nbt.getCompound("itemHandler"));
            }
        }
    }

     

    The ItemStack will always keep the Gold Ingot (if set), even when moved in inventories (like chests).

    But when I move the Item in the Creative Inventory (for example from slot 1 to 2) the capability is reset and the "Air" is printed as Displayname.

  5. Hello,

    I have a custom Item which needs to be synced with the client. To do that I have looked up several threads and they suggested to override getNBTShareTag.

    But when I try to use it in the addInformation method the stack never has the values which are in getNBTShareTag.

    Item class:

    public class BasicBow extends Item {
    
        @Override
        public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    		if(stack.hasTagCompound()) {
                System.out.println(stack.getTagCompound().hasKey("test"));
            }
    
            System.out.println(getNBTShareTag(stack).hasKey("test"));
        }
    
        @Override
        public boolean getShareTag() {
            return true;
        }
    
        @Nullable
        @Override
        public NBTTagCompound getNBTShareTag(ItemStack stack) {
            NBTTagCompound tag = super.getNBTShareTag(stack);
    
            if(tag == null) {
                tag = new NBTTagCompound();
            }
    
            tag.setString("test","Hello world");
            return tag;
        }
    }

    But the "test" key specified in getNBTShareTag is always empty in addInformation.

    I hope you can help me.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.