G2A Many GEOs
SHARE
TWEET

Untitled

a guest Feb 18th, 2020 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @SuppressWarnings("unchecked")
  2. public class EntityExplosivePotion extends ThrowableEntity implements IRendersAsItem {
  3.     public static final DataParameter<Integer> STRENGTH = EntityDataManager.createKey(EntityExplosivePotion.class, DataSerializers.VARINT);
  4.     public static final DataParameter<Boolean> SPICY = EntityDataManager.createKey(EntityExplosivePotion.class, DataSerializers.BOOLEAN);
  5.    
  6.     public EntityExplosivePotion(EntityType<? extends ThrowableEntity> type, World worldIn) {
  7.         super(type, worldIn);
  8.     }
  9.  
  10.     public EntityExplosivePotion(double x, double y, double z, World worldIn) {
  11.         super((EntityType<? extends ThrowableEntity>) ModEntities.THROWABLE_EXPLOSIVE_POTION, x, y, z, worldIn);
  12.     }
  13.      
  14.     public EntityExplosivePotion(LivingEntity livingEntity, World world) {
  15.         super((EntityType<? extends ThrowableEntity>) ModEntities.THROWABLE_EXPLOSIVE_POTION, livingEntity, world);
  16.     }
  17.  
  18.     @Override
  19.     public ItemStack getItem() {
  20.         System.out.println(ModItems.THROWABLE_EXPLOSIVE_POTION); //this is here just to test to see if this method is called
  21.         return new ItemStack(this.isSpicy() ? ModItems.SPICY_THROWABLE_EXPLOSIVE_POTION : ModItems.THROWABLE_EXPLOSIVE_POTION);
  22.     }
  23.  
  24.     public void setStrength(int strength) {
  25.         this.getDataManager().set(STRENGTH, strength);
  26.     }
  27.    
  28.     public void setSpicy(boolean spicy) {
  29.         this.getDataManager().set(SPICY, spicy);
  30.     }
  31.    
  32.     public int getStrength() {
  33.         return this.getDataManager().get(STRENGTH);
  34.     }
  35.    
  36.     public boolean isSpicy() {
  37.         return this.getDataManager().get(SPICY);
  38.     }
  39.  
  40.     @Override
  41.     protected float getGravityVelocity() {
  42.         return 0.05f;
  43.     }
  44.  
  45.     @Override
  46.     protected void onImpact(RayTraceResult result) {
  47.         if (!this.world.isRemote && result.getType() != RayTraceResult.Type.MISS) {
  48.             Type type = result.getType();
  49.             BlockPos pos = type == RayTraceResult.Type.BLOCK ?
  50.                     ((BlockRayTraceResult) result).getPos() :
  51.                     ((EntityRayTraceResult) result).getEntity().getPosition();
  52.             this.world.createExplosion(this, pos.getX(), pos.getY(), pos.getZ(), Math.max(2.0f, this.getStrength() * 5.0f), this.isSpicy(), Explosion.Mode.DESTROY);
  53.             this.world.playBroadcastSound(2002, new BlockPos(this), 1);
  54.             this.remove();
  55.         }
  56.     }
  57.    
  58.     @Override
  59.     public void writeAdditional(CompoundNBT compound) {
  60.         super.writeAdditional(compound);
  61.         compound.putInt(ItemUtil.POTION_STRENGTH_TAG_NAME, this.getStrength());
  62.         compound.putBoolean(ItemUtil.SPICY_TAG_NAME, this.isSpicy());
  63.     }
  64.    
  65.     @Override
  66.     public void readAdditional(CompoundNBT compound) {
  67.         super.readAdditional(compound);
  68.         this.setStrength(compound.getInt(ItemUtil.POTION_STRENGTH_TAG_NAME));
  69.         this.setSpicy(compound.getBoolean(ItemUtil.SPICY_TAG_NAME));
  70.     }
  71.  
  72.     @Override
  73.     protected void registerData() {
  74.         EntityDataManager dm = this.getDataManager();
  75.         dm.register(STRENGTH, ItemUtil.MIN_STRENGTH);
  76.         dm.register(SPICY, false);
  77.     }
  78. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top