Advertisement
Creepinson

entitymoing

Jun 30th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. package me.creepinson.entity;
  2.  
  3. import javax.annotation.Nullable;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.material.Material;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.crash.CrashReportCategory;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.EntityCreature;
  11. import net.minecraft.entity.IEntityLivingData;
  12. import net.minecraft.entity.SharedMonsterAttributes;
  13. import net.minecraft.entity.ai.EntityAILookIdle;
  14. import net.minecraft.entity.ai.EntityAIPanic;
  15. import net.minecraft.entity.ai.EntityAISwimming;
  16. import net.minecraft.entity.ai.EntityAIWander;
  17. import net.minecraft.entity.passive.IAnimals;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.init.Blocks;
  20. import net.minecraft.item.Item;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.nbt.NBTTagCompound;
  23. import net.minecraft.network.datasync.DataParameter;
  24. import net.minecraft.network.datasync.DataSerializers;
  25. import net.minecraft.network.datasync.EntityDataManager;
  26. import net.minecraft.util.DamageSource;
  27. import net.minecraft.util.EnumHand;
  28. import net.minecraft.util.ResourceLocation;
  29. import net.minecraft.util.datafix.DataFixer;
  30. import net.minecraft.util.math.BlockPos;
  31. import net.minecraft.world.DifficultyInstance;
  32. import net.minecraft.world.World;
  33. import net.minecraftforge.fml.relauncher.Side;
  34. import net.minecraftforge.fml.relauncher.SideOnly;
  35.  
  36. public class EntityMovingBlock extends EntityCreature {
  37. private IBlockState fallTile;
  38. public NBTTagCompound tileEntityData;
  39.  
  40. World world = null;
  41.  
  42. public EntityMovingBlock(World worldIn) {
  43. super(worldIn);
  44. this.world = worldIn;
  45.  
  46. }
  47.  
  48. public void setState(IBlockState block) {
  49.  
  50. this.fallTile = block;
  51.  
  52. }
  53.  
  54. public EntityMovingBlock(World worldIn, BlockPos pos) {
  55. super(worldIn);
  56. this.world = worldIn;
  57. this.setSize(3.98F, 3.98F);
  58. this.setPosition(pos.getX(), pos.getY(), pos.getZ());
  59. this.motionX = 0.0D;
  60. this.motionY = 0.0D;
  61. this.motionZ = 0.0D;
  62. this.prevPosX = pos.getX();
  63. this.prevPosY = pos.getY();
  64. this.prevPosZ = pos.getZ();
  65. experienceValue = 3;
  66.  
  67. setNoAI(false);
  68. this.tasks.addTask(2, new EntityAISwimming(this));
  69. this.tasks.addTask(9, new EntityAIWander(this, 1.0D));
  70. this.tasks.addTask(6, new EntityAILookIdle(this));
  71. this.tasks.addTask(7, new EntityAIWander(this, 1.2D));
  72. this.tasks.addTask(10, new EntityAIPanic(this, 1.2D));
  73.  
  74. }
  75.  
  76. protected void applyEntityAttributes() {
  77. super.applyEntityAttributes();
  78. this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.30D);
  79. this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0D);
  80. if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
  81. this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(2.0);
  82. }
  83.  
  84. @Override
  85. protected void initEntityAI() {
  86. this.tasks.addTask(2, new EntityAISwimming(this));
  87. this.tasks.addTask(9, new EntityAIWander(this, 0.3D));
  88. this.tasks.addTask(6, new EntityAILookIdle(this));
  89. this.tasks.addTask(7, new EntityAIWander(this, 0.3D));
  90. this.tasks.addTask(10, new EntityAIPanic(this, 0.3D));
  91.  
  92. super.initEntityAI();
  93. }
  94.  
  95.  
  96. @Override
  97. public boolean processInteract(EntityPlayer entity, EnumHand hand) {
  98. super.processInteract(entity, hand);
  99. int i = (int) this.posX;
  100. int j = (int) this.posY;
  101. int k = (int) this.posZ;
  102.  
  103. return true;
  104. }
  105.  
  106. @Override
  107. protected Item getDropItem() {
  108. return new ItemStack(this.fallTile.getBlock()).getItem();
  109. }
  110.  
  111. protected void entityInit() {
  112. super.entityInit();
  113. }
  114.  
  115. /**
  116. * Returns true if other Entities should be prevented from moving through
  117. * this Entity.
  118. */
  119. public boolean canBeCollidedWith() {
  120. return true;
  121. }
  122.  
  123. @Override
  124. public void onLivingUpdate() {
  125. //if(this.fallTile != null){
  126. // BlockPos below = this.getPosition().down(1);
  127. // IBlockState belowState = this.world.getBlockState(below);
  128. // this.setState(belowState);
  129. //}
  130. super.onLivingUpdate();
  131. }
  132.  
  133. public void onUpdate() {
  134.  
  135.  
  136. /*
  137. * ticks++;
  138. *
  139. * if (ticks == 40) { fallTile = Blocks.DIRT.getDefaultState(); } if
  140. * (ticks == 80) { fallTile = Blocks.BONE_BLOCK.getDefaultState(); } if
  141. * (ticks == 120) { fallTile = Blocks.EMERALD_BLOCK.getDefaultState();
  142. *
  143. * } if (ticks == 160) {
  144. *
  145. * ticks = 0;
  146. *
  147. * }
  148. */
  149.  
  150. super.onUpdate();
  151. }
  152.  
  153. @Override
  154. public boolean isAIDisabled() {
  155.  
  156. return false;
  157. }
  158.  
  159. @Override
  160. public boolean attackEntityAsMob(Entity entityIn) {
  161.  
  162. return super.attackEntityAsMob(entityIn);
  163. }
  164.  
  165. @Override
  166. public boolean attackEntityFrom(DamageSource source, float amount) {
  167.  
  168. return super.attackEntityFrom(source, amount);
  169. }
  170.  
  171. public static void registerFixesFallingBlock(DataFixer fixer) {
  172. }
  173.  
  174. /**
  175. * (abstract) Protected helper method to write subclass entity data to NBT.
  176. */
  177. public void writeEntityToNBT(NBTTagCompound compound) {
  178. Block block = this.fallTile != null ? this.fallTile.getBlock() : Blocks.AIR;
  179. ResourceLocation resourcelocation = (ResourceLocation) Block.REGISTRY.getNameForObject(block);
  180. compound.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
  181. if (this.tileEntityData != null) {
  182. compound.setTag("TileEntityData", this.tileEntityData);
  183. }
  184. }
  185.  
  186. /**
  187. * (abstract) Protected helper method to read subclass entity data from NBT.
  188. */
  189. public void readEntityFromNBT(NBTTagCompound compound) {
  190.  
  191.  
  192. if (compound.hasKey("Block", 8)) {
  193. this.fallTile = Block.getBlockFromName(compound.getString("Block")).getDefaultState();
  194. } else if (compound.hasKey("TileID", 99)) {
  195. this.fallTile = Block.getBlockById(compound.getInteger("TileID")).getDefaultState();
  196. } else {
  197. this.fallTile = Block.getBlockById(compound.getByte("Tile")).getDefaultState();
  198. }
  199. Block block = this.fallTile.getBlock();
  200. if (block == null || block.getDefaultState().getMaterial() == Material.AIR) {
  201. this.fallTile = Blocks.STONE.getDefaultState();
  202. }
  203. }
  204.  
  205. public void addEntityCrashInfo(CrashReportCategory category) {
  206. super.addEntityCrashInfo(category);
  207.  
  208. if (this.fallTile != null) {
  209. Block block = this.fallTile.getBlock();
  210. category.addCrashSection("Immitating block ID", Integer.valueOf(Block.getIdFromBlock(block)));
  211. category.addCrashSection("Immitating block data", Integer.valueOf(block.getMetaFromState(this.fallTile)));
  212. }
  213. }
  214.  
  215. @SideOnly(Side.CLIENT)
  216. public World getWorldObj() {
  217. return this.world;
  218. }
  219.  
  220. /**
  221. * Return whether this entity should be rendered as on fire.
  222. */
  223. @SideOnly(Side.CLIENT)
  224. public boolean canRenderOnFire() {
  225. return false;
  226. }
  227.  
  228. @Nullable
  229. public IBlockState getBlock() {
  230. return this.fallTile;
  231. }
  232.  
  233. public boolean ignoreItemEntityData() {
  234. return true;
  235. }
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement