Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ElectricBallEntity extends DamagingProjectileEntity {
- private static final DataParameter<Float> BALL_SIZE = EntityDataManager.createKey(ElectricBallEntity.class, DataSerializers.FLOAT);
- private double charge;
- public ElectricBallEntity(EntityType<? extends ElectricBallEntity> p_i50173_1_, World p_i50173_2_) {
- super(p_i50173_1_, p_i50173_2_);
- }
- public ElectricBallEntity(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ, double charge) {
- super(ModEntityType.electric_ball_entity, shooter, accelX, accelY, accelZ, worldIn);
- this.charge = charge;
- float size = MathHelper.clamp((float)(charge/2), 1, 2);
- System.out.println(size);
- this.setBallSize((int)(size));
- }
- public void tick() {
- super.tick();
- System.out.println(this.getBallSize());
- }
- /** Impact effect */
- @Override
- protected void onImpact(RayTraceResult result) {
- if (!this.world.isRemote()) {
- if (result.getType() == RayTraceResult.Type.ENTITY) {
- Entity entity = ((EntityRayTraceResult)result).getEntity();
- entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity)this.shootingEntity).setDamageBypassesArmor(), 6F * (float)this.charge);
- }
- else {
- this.remove();
- }
- }
- }
- public float getBallSize() {
- return this.dataManager.get(BALL_SIZE);
- }
- public void setBallSize(float size) {
- this.dataManager.set(BALL_SIZE, size);
- this.setPosition(this.posX, this.posY, this.posZ);
- this.recalculateSize();
- }
- public EntitySize getSize(Pose poseIn) {
- return super.getSize(poseIn).scale(this.getBallSize());
- }
- @Override
- protected float getMotionFactor() {
- return 1F;
- }
- @Override
- public boolean isBurning() {
- return false;
- }
- protected boolean isFireballFiery() {
- return false;
- }
- protected IParticleData getParticle() {
- return ModParticleTypes.electric_spark;
- }
- /**
- * Returns true if other Entities should be prevented from moving through this Entity.
- */
- public boolean canBeCollidedWith() {
- return false;
- }
- /**
- * Called when the entity is attacked.
- */
- public boolean attackEntityFrom(DamageSource source, float amount) {
- return false;
- }
- protected void registerData() {
- this.dataManager.register(BALL_SIZE, 1F);
- super.registerData();
- }
- public void writeAdditional(CompoundNBT compound) {
- super.writeAdditional(compound);
- compound.putFloat("Size", this.getBallSize());
- }
- /**
- * Protected helper method to read subclass entity data from NBT.
- */
- public void readAdditional(CompoundNBT compound) {
- super.readAdditional(compound);
- float i = compound.getFloat("Size");
- this.setBallSize(i);
- }
- public void notifyDataManagerChange(DataParameter<?> key) {
- if (BALL_SIZE.equals(key)) {
- this.recalculateSize();
- }
- super.notifyDataManagerChange(key);
- }
- @Override
- public IPacket<?> createSpawnPacket()
- {
- return NetworkHooks.getEntitySpawningPacket(this);
- }
- public static ElectricBallEntity spawnOnClient(FMLPlayMessages.SpawnEntity spawnPacket, World world) {
- return new ElectricBallEntity(ModEntityType.electric_ball_entity, world);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement