Jump to content

Xander402

Members
  • Posts

    53
  • Joined

  • Last visited

Posts posted by Xander402

  1. Since I need my own implementation of crafting container, I should be able to set which items can be used in crafting with this block, right?
    I tried to initiate the crafting matrix like this (the only difference between this and the vanilla class is the slot class name):

            for (i = 0; i < 3; ++i) {
                for (j = 0; j < 3; ++j) {
                    this.addSlot(new FoodSlot(this.inventory, j + i * 3,
                            30 + j * 18, 17 + i * 18));
                }
            }

    But the game actually doesn't reject any item even if the FoodSlot class looks like this:

    package ...
    
    import ...
    
    public class FoodSlot extends Slot {
        public FoodSlot(IInventory inventory, int p1, int p2, int p3) {
            super(inventory, p1, p2, p3);
        }
    
        @Override
        public boolean isItemValid(ItemStack item) {
            return false;
        }
    }

    Instead, it moves the entire content of the matrix back to the inventory after several clicks.

  2. I tried the following:

        @Override
        public boolean onBlockActivated(BlockState state, World world, BlockPos pos,
                PlayerEntity player, Hand hand, BlockRayTraceResult result) {
            player.openContainer(state.getContainer(world, pos));
            return true;
        }
    
        @Override
        public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos) {
            return new SimpleNamedContainerProvider((i, playerInventory, playerEntity)
                    -> new WorkbenchContainer(0, playerInventory), TEXT_COMPONENT);
        }

    This opens a crafting GUI, but does some mess in the inventory when opening - some items disappear, some get moved to other slot or duplicated, and everything returns back after leaving the GUI and clicking on any item in the inventory. What am I doing wrong?

  3. Yeah, right. I think this is actually a pretty common mistake..
    Here is something that works:

    package ...
    
    import ...
    
    @Mod.EventBusSubscriber
    public class CropRightClickHandler {
    
        @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
        public static void handleCropRightClick(final PlayerInteractEvent.RightClickBlock event) {
          ...
        }
    }

    Two new things. The method handleCropRightClick is now static and the event was changed from PlayerInteractEvent to PlayerInteractEvent.RightClickBlock not to get triggered unnecessarily.

  4. Alright. I found own what to do my own. My RightClickEventHandler.java:

    package ...
    
    import ...
    
    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public class RightClickCropStickHandler {
    
        @SubscribeEvent
        public void handleCropRightClick(PlayerInteractEvent event) {
            Mod.LOGGER.warn("PlayerInteractEvent triggered!");
            ...
        }
    }

    But there's one little problem. The event is actually never called (PlayerInteractEvent triggered! never appears in the console).

  5. 10 hours ago, athy said:

    I added custom crops and seeds to my mod, now I need those seeds to drop from the in-world grass.

    How about just adding a new loot table with pools only with your mod seeds items instead of overriding the entire grass loot table? Overriding would block others potential opportunity to make their own seeds that drop from vanilla grass.

  6. Yes, I know that. ? I don't blame you. I've been playing around with modding, adding some basic items and blocks ever since 1.9, and I had to deal with all the changes (not only in naming), too.

    Quote

    Just it is attemptDamageItem(), not tryDamageItem().

    That's just for people who would potentially come to this post not willing to do research and expecting everything to be expounded exactly as it is.

  7. 2 hours ago, Xander402 said:

    Some mods apply damage to a tool item when it's used to craft something.

    For somebody who would like to know how to do it, here's my solution:
     

    import net.minecraft.item.IItemTier;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.SwordItem;
    
    public class KnifeItem extends SwordItem {
    
        public KnifeItem(IItemTier p_i48460_1_, int p_i48460_2_, float p_i48460_3_, Properties p_i48460_4_) {
            super(p_i48460_1_, p_i48460_2_, p_i48460_3_, p_i48460_4_);
        }
    
        @Override
        public boolean hasContainerItem(ItemStack stack) {
            return true;
        }
    
        @Override
        public ItemStack getContainerItem(ItemStack itemStack) {
            ItemStack ret = new ItemStack(this);
            ret.setDamage(itemStack.getDamage() + 1);
            return ret;
        }
    }

     

  8. 3 minutes ago, diesieben07 said:

    The 2nd makes zero sense:

    • Don't create items in a static initializer.
    • You assign a value to the knife field, only to immediately overwrite it... with an almost identical value.
    • It's unknown if you register this Item anywhere, probably you didn't, which is why it did not work. All Items must be created and registered in the appropriate registry events.

    Yes, I know it's stupid. ? I was aware of this when writing that post.

×
×
  • Create New...

Important Information

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