Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ike.tenchest.chest.uncolossalchest;
- import com.ike.tenchest.Blocks;
- import net.minecraft.block.BlockState;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.ItemStackHelper;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.CompoundNBT;
- import net.minecraft.tileentity.IChestLid;
- import net.minecraft.tileentity.ITickableTileEntity;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.tileentity.TileEntityType;
- import net.minecraft.util.NonNullList;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.SoundEvents;
- import net.minecraft.util.math.MathHelper;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraftforge.api.distmarker.OnlyIn;
- /**
- * @author Ike
- * @version 1.0A
- **/
- public class UncolossalChestTileEntity extends TileEntity implements IInventory, IChestLid, ITickableTileEntity {
- public float openness;
- public float oOpenness;
- public int openCount;
- private int tickInterval;
- public UncolossalChestTileEntity() {
- super(TileEntityType.ENDER_CHEST);
- }
- public void tick() {
- if (++this.tickInterval % 20 * 4 == 0) {
- this.level.blockEvent(this.worldPosition, Blocks.uncolossalChest, 1, this.openCount);
- }
- this.oOpenness = this.openness;
- int i = this.worldPosition.getX();
- int j = this.worldPosition.getY();
- int k = this.worldPosition.getZ();
- float f = 0.1F;
- if (this.openCount > 0 && this.openness == 0.0F) {
- double d0 = (double) i + 0.5D;
- double d1 = (double) k + 0.5D;
- this.level.playSound((PlayerEntity) null, d0, (double) j + 0.5D, d1, SoundEvents.ENDER_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
- }
- if (this.openCount == 0 && this.openness > 0.0F || this.openCount > 0 && this.openness < 1.0F) {
- float f2 = this.openness;
- if (this.openCount > 0) {
- this.openness += 0.1F;
- } else {
- this.openness -= 0.1F;
- }
- if (this.openness > 1.0F) {
- this.openness = 1.0F;
- }
- float f1 = 0.5F;
- if (this.openness < 0.5F && f2 >= 0.5F) {
- double d3 = (double) i + 0.5D;
- double d2 = (double) k + 0.5D;
- this.level.playSound((PlayerEntity) null, d3, (double) j + 0.5D, d2, SoundEvents.ENDER_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
- }
- if (this.openness < 0.0F) {
- this.openness = 0.0F;
- }
- }
- }
- public boolean triggerEvent(int p_145842_1_, int p_145842_2_) {
- if (p_145842_1_ == 1) {
- this.openCount = p_145842_2_;
- return true;
- } else {
- return super.triggerEvent(p_145842_1_, p_145842_2_);
- }
- }
- public void setRemoved() {
- this.clearCache();
- super.setRemoved();
- }
- public void startOpen() {
- ++this.openCount;
- this.level.blockEvent(this.worldPosition, Blocks.uncolossalChest, 1, this.openCount);
- }
- public void stopOpen() {
- --this.openCount;
- this.level.blockEvent(this.worldPosition, Blocks.uncolossalChest, 1, this.openCount);
- }
- private NonNullList<ItemStack> inventory = NonNullList.withSize(27, ItemStack.EMPTY);
- @Override
- public CompoundNBT save(CompoundNBT nbt) {
- super.save(nbt);
- ItemStackHelper.saveAllItems(nbt, this.inventory);
- return nbt;
- }
- @Override
- public void load(BlockState state, CompoundNBT nbt) {
- super.load(state, nbt);
- this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
- ItemStackHelper.loadAllItems(nbt, this.inventory);
- }
- @Override
- public int getContainerSize() {
- return 27;
- }
- @Override
- public boolean isEmpty() {
- return inventory.isEmpty();
- }
- @Override
- public ItemStack getItem(int index) {
- return inventory.get(index);
- }
- @Override
- public ItemStack removeItem(int index, int quantity) {
- ItemStack itemStack = inventory.get(index);
- if (itemStack.getCount() <= quantity) {
- inventory.set(index, ItemStack.EMPTY);
- return itemStack;
- } else {
- int count = itemStack.getCount() - quantity;
- itemStack.setCount(count);
- inventory.set(index, itemStack);
- return new ItemStack(itemStack.getItem(), count);
- }
- }
- @Override
- public ItemStack removeItemNoUpdate(int index) {
- return inventory.remove(index);
- }
- @Override
- public void setItem(int index, ItemStack stack) {
- this.inventory.set(index, stack);
- }
- @Override
- public boolean stillValid(PlayerEntity p_70300_1_) {
- return true;
- }
- @Override
- public void clearContent() {
- this.inventory.clear();
- }
- @OnlyIn(Dist.CLIENT)
- public float getOpenNess(float p_195480_1_) {
- return MathHelper.lerp(p_195480_1_, this.oOpenness, this.openness);
- }
- }
Add Comment
Please, Sign In to add comment