I have an item with the onItemRightClick. Then I check some stuff and then decide if I need to shrink the itemstack this is most of the time not working. Also now that I only execute it one's on the server side
Here is the code if you want to see more: https://github.com/DJ1TJOO/fantasy20/
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// System.err.println("A");
if(worldIn.isRemote) {
return new ActionResult<>(ActionResultType.PASS, playerIn.getHeldItem(handIn));
}
if(playerIn.getHeldItem(handIn).getItem() instanceof Blueprint) {
//System.err.println("a");
if(!playerIn.getHeldItem(handIn).hasTag()) {
return super.onItemRightClick(worldIn, playerIn, handIn);
}
CompoundNBT tag = playerIn.getHeldItem(handIn).getTag();
if(!tag.contains("data")) {
return super.onItemRightClick(worldIn, playerIn, handIn);
}
if(!tag.getCompound("data").contains("item")) {
return super.onItemRightClick(worldIn, playerIn, handIn);
}
String itemString = tag.getCompound("data").getString("item");
//System.err.println("b");
playerIn.getCapability(CapabilityResearchProvider.RESEARCH_CAPABILITY, null).ifPresent(r -> {
// System.err.println("c");
Item item = ForgeRegistries.ITEMS.getValue(ResourceLocation.create(itemString, ':'));
// System.err.println("d");
if(!r.getResearched().contains(item)) {
r.getResearched().add(item);
playerIn.sendMessage(new StringTextComponent("Je hebt het item " + item.getDefaultInstance().getDisplayName().getFormattedText() + " geresearched!"));
playerIn.getHeldItem(handIn).shrink(1);
// System.err.println(playerIn.serializeNBT().toString());
//System.err.println(r.getResearched().toString());
}
});
}
return new ActionResult<>(ActionResultType.PASS, playerIn.getHeldItem(handIn));
}