Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.creepinson.entity;
- import javax.annotation.Nullable;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockFalling;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.crash.CrashReportCategory;
- import net.minecraft.entity.EntityCreature;
- import net.minecraft.entity.MoverType;
- import net.minecraft.entity.SharedMonsterAttributes;
- import net.minecraft.entity.ai.EntityAILookIdle;
- import net.minecraft.entity.ai.EntityAIPanic;
- import net.minecraft.entity.ai.EntityAISwimming;
- import net.minecraft.entity.ai.EntityAIWander;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.item.Item;
- 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.ResourceLocation;
- import net.minecraft.util.datafix.DataFixer;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class EntityMovingBlock extends EntityCreature
- {
- private IBlockState fallTile;
- public NBTTagCompound tileEntityData;
- protected static final DataParameter<BlockPos> ORIGIN = EntityDataManager.<BlockPos>createKey(EntityMovingBlock.class, DataSerializers.BLOCK_POS);
- World world = null;
- public EntityMovingBlock(World worldIn)
- {
- super(worldIn);
- this.world = worldIn;
- }
- public EntityMovingBlock(World worldIn, double x, double y, double z, IBlockState fallingBlockState)
- {
- super(worldIn);
- this.world = worldIn;
- this.fallTile = fallingBlockState;
- this.setSize(0.98F, 0.98F);
- this.setPosition(x, y, z);
- this.motionX = 0.0D;
- this.motionY = 0.0D;
- this.motionZ = 0.0D;
- this.prevPosX = x;
- this.prevPosY = y;
- this.prevPosZ = z;
- experienceValue = 3;
- setNoAI(!true);
- this.tasks.addTask(2, new EntityAISwimming(this));
- this.tasks.addTask(9, new EntityAIWander(this, 1.0D));
- this.tasks.addTask(6, new EntityAILookIdle(this));
- this.tasks.addTask(7, new EntityAIWander(this, 0.8D));
- this.tasks.addTask(10, new EntityAIPanic(this, 1.2D));
- }
- protected void applyEntityAttributes() {
- super.applyEntityAttributes();
- this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.15D);
- this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10D);
- if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
- this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(2.0);
- }
- @Override
- protected Item getDropItem() {
- return new ItemStack(this.fallTile.getBlock()).getItem();
- }
- /**
- * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
- * prevent them from trampling crops
- */
- protected boolean canTriggerWalking()
- {
- return false;
- }
- protected void entityInit()
- {
- }
- /**
- * Returns true if other Entities should be prevented from moving through this Entity.
- */
- public boolean canBeCollidedWith()
- {
- return !this.isDead;
- }
- /**
- * Called to update the entity's position/logic.
- */
- public void onUpdate()
- {
- Block block = this.fallTile.getBlock();
- if (this.fallTile.getMaterial() == Material.AIR)
- {
- this.setDead();
- }
- else
- {
- this.prevPosX = this.posX;
- this.prevPosY = this.posY;
- this.prevPosZ = this.posZ;
- BlockPos blockpos = new BlockPos(this);
- if (this.world.getBlockState(blockpos).getBlock() == block)
- {
- this.world.setBlockToAir(blockpos);
- }
- else if (!this.world.isRemote)
- {
- this.setDead();
- return;
- }
- }
- this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
- this.motionX *= 0.9800000190734863D;
- this.motionY *= 0.9800000190734863D;
- this.motionZ *= 0.9800000190734863D;
- if (!this.world.isRemote)
- {
- BlockPos blockpos1 = new BlockPos(this);
- if (this.onGround)
- {
- IBlockState iblockstate = this.world.getBlockState(blockpos1);
- if (this.world.isAirBlock(new BlockPos(this.posX, this.posY - 0.009999999776482582D, this.posZ))) //Forge: Don't indent below.
- if (BlockFalling.canFallThrough(this.world.getBlockState(new BlockPos(this.posX, this.posY - 0.009999999776482582D, this.posZ))))
- {
- this.onGround = false;
- return;
- }
- this.motionX *= 0.699999988079071D;
- this.motionZ *= 0.699999988079071D;
- this.motionY *= -0.5D;
- if (iblockstate.getBlock() != Blocks.PISTON_EXTENSION)
- {
- this.setDead();
- }
- }
- }
- }
- public static void registerFixesFallingBlock(DataFixer fixer)
- {
- }
- /**
- * (abstract) Protected helper method to write subclass entity data to NBT.
- */
- public void writeEntityToNBT(NBTTagCompound compound)
- {
- Block block = this.fallTile != null ? this.fallTile.getBlock() : Blocks.AIR;
- ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(block);
- compound.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
- compound.setByte("Data", (byte)block.getMetaFromState(this.fallTile));
- if (this.tileEntityData != null)
- {
- compound.setTag("TileEntityData", this.tileEntityData);
- }
- }
- /**
- * (abstract) Protected helper method to read subclass entity data from NBT.
- */
- public void readEntityFromNBT(NBTTagCompound compound)
- {
- int i = compound.getByte("Data") & 255;
- if (compound.hasKey("Block", 8))
- {
- this.fallTile = Block.getBlockFromName(compound.getString("Block")).getStateFromMeta(i);
- }
- else if (compound.hasKey("TileID", 99))
- {
- this.fallTile = Block.getBlockById(compound.getInteger("TileID")).getStateFromMeta(i);
- }
- else
- {
- this.fallTile = Block.getBlockById(compound.getByte("Tile") & 255).getStateFromMeta(i);
- }
- Block block = this.fallTile.getBlock();
- if (block == null || block.getDefaultState().getMaterial() == Material.AIR)
- {
- this.fallTile = Blocks.SAND.getDefaultState();
- }
- }
- public void addEntityCrashInfo(CrashReportCategory category)
- {
- super.addEntityCrashInfo(category);
- if (this.fallTile != null)
- {
- Block block = this.fallTile.getBlock();
- category.addCrashSection("Immitating block ID", Integer.valueOf(Block.getIdFromBlock(block)));
- category.addCrashSection("Immitating block data", Integer.valueOf(block.getMetaFromState(this.fallTile)));
- }
- }
- @SideOnly(Side.CLIENT)
- public World getWorldObj()
- {
- return this.world;
- }
- /**
- * Return whether this entity should be rendered as on fire.
- */
- @SideOnly(Side.CLIENT)
- public boolean canRenderOnFire()
- {
- return false;
- }
- @Nullable
- public IBlockState getBlock()
- {
- return this.fallTile;
- }
- public boolean ignoreItemEntityData()
- {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement