Jump to content
Search In
  • More options...
Find results that contain...
Find results in...


  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Squander's Achievements

Stone Miner

Stone Miner (3/8)



  1. i did something like this and it works too. @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { for (int i = 0; i < getSlots(); i++) { ItemStack stack1 = getStackInSlot(i); if(stack.getItem() == stack1.getItem()){ return false; } } return super.isItemValid(slot, stack); }
  2. Ok it works, but i don't know how i can prevent amulet of the same kind from being added to a container
  3. I'm not sure if I did it right if(player != null){ if(getStackInSlot(slot).isEmpty()){ ((BaseAmulet)getStackInSlot(slot).getItem()).remove(player); } if(getStackInSlot(slot).getItem() instanceof BaseAmulet amulet){ amulet.apply(player); } }
  4. I don't think it will work. I want to do it in a similar way to the inventory when I put my boots on, the attributes from it are added to the player when I take them off they are removed.
  5. public class ItemStackHandlerMod extends ItemStackHandler { private Player player; public ItemStackHandlerMod(int size) { super(size); } public ItemStackHandlerMod(int size, Player player) { super(size); this.player = player; } @Override protected void onContentsChanged(int slot) { if(player != null){ if(getStackInSlot(slot).getItem() instanceof BaseAmulet amulet){ amulet.apply(player); } } } } public class HealthAmulet extends BaseAmulet { public static final UUID HEALTH = UUID.fromString("c2d8616a-c58a-4d99-aec9-faad03858302"); public HealthAmulet(Properties pProperties) { super(pProperties); } @Override public void apply(Player player) { AttributeInstance instance = player.getAttribute(Attributes.MAX_HEALTH); instance.addPermanentModifier(new AttributeModifier(HEALTH, "Health Amulet", 5, AttributeModifier.Operation.ADDITION)); } @Override public void remove(Player player) { AttributeInstance instance = player.getAttribute(Attributes.MAX_HEALTH); instance.removeModifier(HEALTH); } }
  6. Overrides the onContentChanged method. When I put an item, it calls the apply method, but I would like to call remove when I take item out of the container, but I don't think onContentChanged will let me do that.
  7. public class MineSkillSyncPacket { private int level; public MineSkillSyncPacket(int level){ this.level = level; } public MineSkillSyncPacket(FriendlyByteBuf buf){ new MineSkillSyncPacket(buf.readVarInt()); } public void encode(FriendlyByteBuf buf){ buf.writeVarInt(this.level); } public boolean handler(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context ctx = supplier.get(); ctx.enqueueWork(() -> { MineSkillData.setLevel(this.level); }); return true; } public static void register(int id){ PacketHandler.INSTANCE.messageBuilder(MineSkillSyncPacket.class, id, NetworkDirection.PLAY_TO_CLIENT) .decoder(MineSkillSyncPacket::new) .encoder(MineSkillSyncPacket::encode) .consumer(MineSkillSyncPacket::handler).add(); } } This is my packet, I have to send it from the server to the client, but I don't know where to call the sending methods.
  8. I should send the packet from server to client or client to server and what it should contain?
  9. I do not send any packets, what, where and what should be included if should.
  10. I get such an error in the console and am using this code. @SubscribeEvent public static void onMineBlock(PlayerEvent.BreakSpeed event){ event.getPlayer().getCapability(Capabilities.PLAYER_SKILLS).ifPresent(skills -> { for(AbstractSkill skill : skills.getSkills()){ if(skill instanceof MineSkill){ event.setNewSpeed(event.getOriginalSpeed() * skill.getLevel() + 0.5f); System.out.println("ORIGINAL: " + event.getOriginalSpeed()); System.out.println("NEW: " + event.getNewSpeed()); } } }); } [Server thread/WARN] [net.minecraft.server.level.ServerPlayerGameMode/]: Mismatch in destroy block pos: BlockPos{x=0, y=0, z=0} BlockPos{x=16, y=94, z=13}
  11. Should I assign a new instance to the IItemHandler field
  12. Everything works, repository on github updated.
  13. Does my IItemHandler extension interface need to be registered with RegisterCapabilityEvent?
  • Create New...

Important Information

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