Guest User

Untitled

a guest
Apr 21st, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.73 KB | None | 0 0
  1. package com.TheRPGAdventurer.ROTD.server.blocks.tileentities;
  2.  
  3. import com.TheRPGAdventurer.ROTD.DragonMounts;
  4. import com.TheRPGAdventurer.ROTD.client.inventory.ContainerDragonShulker;
  5. import com.TheRPGAdventurer.ROTD.server.blocks.BlockDragonShulker;
  6. import net.minecraft.block.Block;
  7. import net.minecraft.block.material.EnumPushReaction;
  8. import net.minecraft.block.state.IBlockState;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.MoverType;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.entity.player.InventoryPlayer;
  13. import net.minecraft.init.SoundEvents;
  14. import net.minecraft.inventory.Container;
  15. import net.minecraft.inventory.ItemStackHelper;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.nbt.NBTTagCompound;
  18. import net.minecraft.tileentity.TileEntityLockableLoot;
  19. import net.minecraft.util.EnumFacing;
  20. import net.minecraft.util.ITickable;
  21. import net.minecraft.util.NonNullList;
  22. import net.minecraft.util.SoundCategory;
  23. import net.minecraft.util.math.AxisAlignedBB;
  24.  
  25. import java.util.List;
  26.  
  27. /**
  28. * Dragon Core TileEntity
  29. *
  30. * @author WolfShotz
  31. */
  32.  
  33. public class TileEntityDragonShulker extends TileEntityLockableLoot implements ITickable {
  34. private NonNullList<ItemStack> chestContents = NonNullList.<ItemStack>withSize(72, ItemStack.EMPTY);
  35. public int numPlayersUsing, ticksSinceSync;
  36. private float progress, progressOld;
  37. private TileEntityDragonShulker.AnimationStatus animationStatus;
  38.  
  39. public TileEntityDragonShulker() {
  40. this.animationStatus = TileEntityDragonShulker.AnimationStatus.CLOSED;
  41. }
  42.  
  43. @Override
  44. public int getSizeInventory() {
  45. return 1;
  46. }
  47.  
  48. @Override
  49. public int getInventoryStackLimit() {
  50. return 64;
  51. }
  52.  
  53. @Override
  54. public boolean receiveClientEvent(int id, int type) {
  55. if (id == 1) {
  56. this.numPlayersUsing = type;
  57.  
  58. if (type == 0) {
  59. this.animationStatus = TileEntityDragonShulker.AnimationStatus.CLOSING;
  60. }
  61.  
  62. if (type == 1) {
  63. this.animationStatus = TileEntityDragonShulker.AnimationStatus.OPENING;
  64. }
  65.  
  66. return true;
  67. } else {
  68. return super.receiveClientEvent(id, type);
  69. }
  70. }
  71.  
  72. //Why does this return the opposite lol
  73. @Override
  74. public boolean isEmpty() {
  75. for (ItemStack stack : this.chestContents) {
  76. if (stack.isEmpty()) return true;
  77. }
  78.  
  79. return false;
  80. }
  81.  
  82. @Override
  83. public String getName() {
  84. return this.hasCustomName() ? this.customName : "container.dragon_shulker";
  85. }
  86.  
  87. @Override
  88. public void readFromNBT(NBTTagCompound compound) {
  89. super.readFromNBT(compound);
  90. this.chestContents = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
  91.  
  92. if (!this.checkLootAndRead(compound)) ItemStackHelper.loadAllItems(compound, chestContents);
  93. if (compound.hasKey("CustomName", 8)) this.customName = compound.getString("CustomName");
  94. }
  95.  
  96. @Override
  97. public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  98. super.writeToNBT(compound);
  99.  
  100. if (!this.checkLootAndWrite(compound)) ItemStackHelper.saveAllItems(compound, chestContents);
  101. if (compound.hasKey("CustomName", 8)) compound.setString("CustomName", this.customName);
  102.  
  103. return compound;
  104. }
  105.  
  106. public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
  107. return new ContainerDragonShulker(playerInventory, this, playerIn);
  108. }
  109.  
  110. @Override
  111. public String getGuiID() {
  112. return DragonMounts.MODID + ":dragon_shulker";
  113. }
  114.  
  115. @Override
  116. protected NonNullList<ItemStack> getItems() {
  117. return this.chestContents;
  118. }
  119.  
  120. /**
  121. * Like the old updateEntity(), except more generic.
  122. */
  123. public void update() {
  124. this.updateAnimation();
  125.  
  126. if (this.animationStatus == TileEntityDragonShulker.AnimationStatus.OPENING || this.animationStatus == TileEntityDragonShulker.AnimationStatus.CLOSING) {
  127. this.moveCollidedEntities();
  128. }
  129. }
  130.  
  131. private AxisAlignedBB getTopBoundingBox(EnumFacing p_190588_1_) {
  132. EnumFacing enumfacing = p_190588_1_.getOpposite();
  133. return this.getBoundingBox(p_190588_1_).contract((double) enumfacing.getFrontOffsetX(), (double) enumfacing.getFrontOffsetY(), (double) enumfacing.getFrontOffsetZ());
  134. }
  135.  
  136. public AxisAlignedBB getBoundingBox(IBlockState p_190584_1_) {
  137. return this.getBoundingBox((EnumFacing) p_190584_1_.getValue(BlockDragonShulker.FACING));
  138. }
  139.  
  140. public AxisAlignedBB getBoundingBox(EnumFacing p_190587_1_) {
  141. return Block.FULL_BLOCK_AABB.expand((double) (0.5F * this.getProgress(1.0F) * (float) p_190587_1_.getFrontOffsetX()), (double) (0.5F * this.getProgress(1.0F) * (float) p_190587_1_.getFrontOffsetY()), (double) (0.5F * this.getProgress(1.0F) * (float) p_190587_1_.getFrontOffsetZ()));
  142. }
  143.  
  144. private void moveCollidedEntities() {
  145. IBlockState iblockstate = this.world.getBlockState(this.getPos());
  146.  
  147. if (iblockstate.getBlock() instanceof BlockDragonShulker) {
  148. EnumFacing enumfacing = (EnumFacing) iblockstate.getValue(BlockDragonShulker.FACING);
  149. AxisAlignedBB axisalignedbb = this.getTopBoundingBox(enumfacing).offset(this.pos);
  150. List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity((Entity) null, axisalignedbb);
  151.  
  152. if (!list.isEmpty()) {
  153. for (int i = 0; i < list.size(); ++i) {
  154. Entity entity = list.get(i);
  155.  
  156. if (entity.getPushReaction() != EnumPushReaction.IGNORE) {
  157. double d0 = 0.0D;
  158. double d1 = 0.0D;
  159. double d2 = 0.0D;
  160. AxisAlignedBB axisalignedbb1 = entity.getEntityBoundingBox();
  161.  
  162. switch (enumfacing.getAxis()) {
  163. case X:
  164.  
  165. if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE) {
  166. d0 = axisalignedbb.maxX - axisalignedbb1.minX;
  167. } else {
  168. d0 = axisalignedbb1.maxX - axisalignedbb.minX;
  169. }
  170.  
  171. d0 = d0 + 0.01D;
  172. break;
  173. case Y:
  174.  
  175. if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE) {
  176. d1 = axisalignedbb.maxY - axisalignedbb1.minY;
  177. } else {
  178. d1 = axisalignedbb1.maxY - axisalignedbb.minY;
  179. }
  180.  
  181. d1 = d1 + 0.01D;
  182. break;
  183. case Z:
  184.  
  185. if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE) {
  186. d2 = axisalignedbb.maxZ - axisalignedbb1.minZ;
  187. } else {
  188. d2 = axisalignedbb1.maxZ - axisalignedbb.minZ;
  189. }
  190.  
  191. d2 = d2 + 0.01D;
  192. }
  193.  
  194. entity.move(MoverType.SHULKER_BOX, d0 * (double) enumfacing.getFrontOffsetX(), d1 * (double) enumfacing.getFrontOffsetY(), d2 * (double) enumfacing.getFrontOffsetZ());
  195. }
  196. }
  197. }
  198. }
  199. }
  200.  
  201. protected void updateAnimation() {
  202. this.progressOld = this.progress;
  203.  
  204. switch (this.animationStatus) {
  205. case CLOSED:
  206. this.progress = 0.0F;
  207. break;
  208. case OPENING:
  209. this.progress += 0.1F;
  210. if (this.progress >= 1.0F) {
  211. this.animationStatus = TileEntityDragonShulker.AnimationStatus.OPENED;
  212. this.progress = 1.0F;
  213. }
  214.  
  215. break;
  216. case CLOSING:
  217. this.progress -= 0.1F;
  218.  
  219. if (this.progress <= 0.0F) {
  220. this.animationStatus = TileEntityDragonShulker.AnimationStatus.CLOSED;
  221. this.progress = 0.0F;
  222. }
  223.  
  224. break;
  225. case OPENED:
  226. this.progress = 1.0F;
  227. }
  228. }
  229.  
  230. public TileEntityDragonShulker.AnimationStatus getAnimationStatus() {
  231. return this.animationStatus;
  232. }
  233.  
  234.  
  235. @Override
  236. public void openInventory(EntityPlayer player) {
  237. ++this.numPlayersUsing;
  238. this.world.addBlockEvent(pos, this.getBlockType(), 1, this.numPlayersUsing);
  239. this.world.notifyNeighborsOfStateChange(pos, this.getBlockType(), false);
  240. if (numPlayersUsing == 1) {
  241.  
  242. double d1 = (double) pos.getX() + 0.5D;
  243. double d2 = (double) pos.getZ() + 0.5D;
  244. this.world.playSound((EntityPlayer) null, d1, (double) pos.getY() + 0.5D, d2, SoundEvents.BLOCK_ENDERCHEST_OPEN, SoundCategory.BLOCKS, 0.9F, this.world.rand.nextFloat() * 0.1F + 0.9F);
  245. this.world.playSound((EntityPlayer) null, d1, (double) pos.getY() + 0.5D, d2, SoundEvents.ENTITY_ENDERDRAGON_AMBIENT, SoundCategory.HOSTILE, 0.05F, this.world.rand.nextFloat() * 0.3F + 0.9F);
  246. this.world.playSound((EntityPlayer) null, d1, (double) pos.getY() + 0.5D, d2, SoundEvents.BLOCK_END_PORTAL_SPAWN, SoundCategory.BLOCKS, 0.08F, this.world.rand.nextFloat() * 0.1F + 0.9F);
  247.  
  248. }
  249. }
  250.  
  251. @Override
  252. public void closeInventory(EntityPlayer player) {
  253. --this.numPlayersUsing;
  254. this.world.addBlockEvent(pos, this.getBlockType(), 1, this.numPlayersUsing);
  255. this.world.notifyNeighborsOfStateChange(pos, this.getBlockType(), false);
  256. if (numPlayersUsing <= 0) {
  257. double d3 = (double) pos.getX() + 0.5D;
  258. double d0 = (double) pos.getZ() + 0.5D;
  259. this.world.playSound((EntityPlayer) null, d3, (double) pos.getY() + 0.5D, d0, SoundEvents.BLOCK_SHULKER_BOX_CLOSE, SoundCategory.BLOCKS, 0.4F, this.world.rand.nextFloat() * 0.1F + 0.9F);
  260. this.world.playSound((EntityPlayer) null, d3, (double) pos.getY() + 0.5D, d0, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 0.3F, this.world.rand.nextFloat() * 0.1F + 0.3F);
  261. }
  262. }
  263.  
  264. public float getProgress(float p_190585_1_) {
  265. return this.progressOld + (this.progress - this.progressOld) * p_190585_1_;
  266. }
  267.  
  268. public static enum AnimationStatus {
  269. CLOSED,
  270. OPENING,
  271. OPENED,
  272. CLOSING;
  273. }
  274.  
  275. }
Add Comment
Please, Sign In to add comment