Advertisement
Guest User

ModItem Class

a guest
Oct 13th, 2020
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ModItem extends Item {
  2. public static final String LAYER_KEY = "LayerKey";
  3.  
  4. public static int getTag(ItemStack stack, String tag) {
  5. return stack.getOrCreateTag().getInt(tag);
  6. }
  7. public static void setTag(ItemStack stack, String tag, int tagInt) {
  8. stack.getOrCreateTag().putInt(tag, tagInt);
  9. }
  10. public static Float updateModel(ItemStack stack) {
  11. return (float) stack.getOrCreateTag().getInt(LAYER_KEY);
  12. }
  13.  
  14. public ModItem() {
  15. super(new Item.Properties().group(ItemGroup.TOOLS));
  16. }
  17.  
  18. @Override
  19. public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand hand) {
  20. ItemStack itemStackIn = playerIn.getHeldItem(hand);
  21.  
  22. if (!worldIn.isRemote) {
  23. ModItemEntity modItem = new ModItemEntity(playerIn, worldIn, itemStackIn.copy());
  24. modItem.shoot(playerIn.getLookVec().x, playerIn.getLookVec().y, playerIn.getLookVec().z, 1.5F, 1.0F);
  25. worldIn.addEntity(modItem);
  26. }
  27. worldIn.playSound(playerIn, playerIn.func_233580_cy_(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (Item.random.nextFloat() * 0.4F + 0.8F));
  28. return ActionResult.resultSuccess(itemStackIn);
  29. }
  30. }
  31.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement