Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressWarnings("unchecked")
- public class EntityExplosivePotion extends ThrowableEntity implements IRendersAsItem {
- public static final DataParameter<Integer> STRENGTH = EntityDataManager.createKey(EntityExplosivePotion.class, DataSerializers.VARINT);
- public static final DataParameter<Boolean> SPICY = EntityDataManager.createKey(EntityExplosivePotion.class, DataSerializers.BOOLEAN);
- public EntityExplosivePotion(EntityType<? extends ThrowableEntity> type, World worldIn) {
- super(type, worldIn);
- }
- public EntityExplosivePotion(double x, double y, double z, World worldIn) {
- super((EntityType<? extends ThrowableEntity>) ModEntities.THROWABLE_EXPLOSIVE_POTION, x, y, z, worldIn);
- }
- public EntityExplosivePotion(LivingEntity livingEntity, World world) {
- super((EntityType<? extends ThrowableEntity>) ModEntities.THROWABLE_EXPLOSIVE_POTION, livingEntity, world);
- }
- @Override
- public ItemStack getItem() {
- System.out.println(ModItems.THROWABLE_EXPLOSIVE_POTION); //this is here just to test to see if this method is called
- return new ItemStack(this.isSpicy() ? ModItems.SPICY_THROWABLE_EXPLOSIVE_POTION : ModItems.THROWABLE_EXPLOSIVE_POTION);
- }
- public void setStrength(int strength) {
- this.getDataManager().set(STRENGTH, strength);
- }
- public void setSpicy(boolean spicy) {
- this.getDataManager().set(SPICY, spicy);
- }
- public int getStrength() {
- return this.getDataManager().get(STRENGTH);
- }
- public boolean isSpicy() {
- return this.getDataManager().get(SPICY);
- }
- @Override
- protected float getGravityVelocity() {
- return 0.05f;
- }
- @Override
- protected void onImpact(RayTraceResult result) {
- if (!this.world.isRemote && result.getType() != RayTraceResult.Type.MISS) {
- Type type = result.getType();
- BlockPos pos = type == RayTraceResult.Type.BLOCK ?
- ((BlockRayTraceResult) result).getPos() :
- ((EntityRayTraceResult) result).getEntity().getPosition();
- this.world.createExplosion(this, pos.getX(), pos.getY(), pos.getZ(), Math.max(2.0f, this.getStrength() * 5.0f), this.isSpicy(), Explosion.Mode.DESTROY);
- this.world.playBroadcastSound(2002, new BlockPos(this), 1);
- this.remove();
- }
- }
- @Override
- public void writeAdditional(CompoundNBT compound) {
- super.writeAdditional(compound);
- compound.putInt(ItemUtil.POTION_STRENGTH_TAG_NAME, this.getStrength());
- compound.putBoolean(ItemUtil.SPICY_TAG_NAME, this.isSpicy());
- }
- @Override
- public void readAdditional(CompoundNBT compound) {
- super.readAdditional(compound);
- this.setStrength(compound.getInt(ItemUtil.POTION_STRENGTH_TAG_NAME));
- this.setSpicy(compound.getBoolean(ItemUtil.SPICY_TAG_NAME));
- }
- @Override
- protected void registerData() {
- EntityDataManager dm = this.getDataManager();
- dm.register(STRENGTH, ItemUtil.MIN_STRENGTH);
- dm.register(SPICY, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment