2018-12-14 00:47:01 +01:00
|
|
|
package de.ellpeck.naturesaura.entities;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2019-01-28 15:43:21 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
2018-12-16 18:15:54 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ItemEffectPowder;
|
2018-12-14 00:47:01 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.datasync.DataParameter;
|
|
|
|
import net.minecraft.network.datasync.DataSerializers;
|
|
|
|
import net.minecraft.network.datasync.EntityDataManager;
|
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
import net.minecraft.util.EntityDamageSource;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-01-28 15:43:21 +01:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-12-14 00:47:01 +01:00
|
|
|
import net.minecraft.world.World;
|
2019-01-28 15:43:21 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2018-12-14 00:47:01 +01:00
|
|
|
|
2019-01-28 15:43:21 +01:00
|
|
|
public class EntityEffectInhibitor extends Entity implements IVisualizable {
|
2018-12-14 00:47:01 +01:00
|
|
|
|
|
|
|
private static final DataParameter<String> INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING);
|
|
|
|
private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
2019-01-28 15:43:21 +01:00
|
|
|
private static final DataParameter<Integer> AMOUNT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
|
2018-12-14 00:47:01 +01:00
|
|
|
|
|
|
|
public EntityEffectInhibitor(World worldIn) {
|
|
|
|
super(worldIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void entityInit() {
|
|
|
|
this.setSize(0.25F, 0.25F);
|
|
|
|
this.dataManager.register(INHIBITED_EFFECT, null);
|
|
|
|
this.dataManager.register(COLOR, 0);
|
2019-01-28 15:43:21 +01:00
|
|
|
this.dataManager.register(AMOUNT, 0);
|
2018-12-14 00:47:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void readEntityFromNBT(NBTTagCompound compound) {
|
|
|
|
this.setInhibitedEffect(new ResourceLocation(compound.getString("effect")));
|
|
|
|
this.setColor(compound.getInteger("color"));
|
2019-01-28 15:43:21 +01:00
|
|
|
this.setAmount(compound.hasKey("amount") ? compound.getInteger("amount") : 24);
|
2018-12-14 00:47:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void writeEntityToNBT(NBTTagCompound compound) {
|
|
|
|
compound.setString("effect", this.getInhibitedEffect().toString());
|
|
|
|
compound.setInteger("color", this.getColor());
|
2019-01-28 15:43:21 +01:00
|
|
|
compound.setInteger("amount", this.getAmount());
|
2018-12-14 00:47:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEntityUpdate() {
|
|
|
|
if (this.world.isRemote) {
|
|
|
|
if (this.world.getTotalWorldTime() % 5 == 0) {
|
|
|
|
NaturesAura.proxy.spawnMagicParticle(
|
|
|
|
this.posX + this.world.rand.nextGaussian() * 0.1F,
|
|
|
|
this.posY,
|
|
|
|
this.posZ + this.world.rand.nextGaussian() * 0.1F,
|
|
|
|
this.world.rand.nextGaussian() * 0.005F,
|
|
|
|
this.world.rand.nextFloat() * 0.03F,
|
|
|
|
this.world.rand.nextGaussian() * 0.005F,
|
|
|
|
this.getColor(), this.world.rand.nextFloat() * 3F + 1F, 120, 0F, true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBeCollidedWith() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean attackEntityFrom(DamageSource source, float amount) {
|
|
|
|
if (source instanceof EntityDamageSource && !this.world.isRemote) {
|
|
|
|
this.setDead();
|
2019-01-28 15:43:21 +01:00
|
|
|
this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.getAmount()), this.getInhibitedEffect()), 0F);
|
2018-12-14 00:47:01 +01:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return super.attackEntityFrom(source, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInhibitedEffect(ResourceLocation effect) {
|
|
|
|
this.dataManager.set(INHIBITED_EFFECT, effect.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResourceLocation getInhibitedEffect() {
|
|
|
|
return new ResourceLocation(this.dataManager.get(INHIBITED_EFFECT));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColor(int color) {
|
|
|
|
this.dataManager.set(COLOR, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getColor() {
|
|
|
|
return this.dataManager.get(COLOR);
|
|
|
|
}
|
2019-01-28 15:43:21 +01:00
|
|
|
|
|
|
|
public void setAmount(int amount) {
|
|
|
|
this.dataManager.set(AMOUNT, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getAmount() {
|
|
|
|
return this.dataManager.get(AMOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
|
|
|
|
return new AxisAlignedBB(
|
|
|
|
this.posX, this.posY, this.posZ,
|
|
|
|
this.posX, this.posY, this.posZ).grow(this.getAmount());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getVisualizationColor(World world, BlockPos pos) {
|
|
|
|
return this.getColor();
|
|
|
|
}
|
2018-12-14 00:47:01 +01:00
|
|
|
}
|