Advertisement
Creepinson

Untitled

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