2016-06-06 21:27:09 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityDisplayStand.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-06-06 21:27:09 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-06-06 21:27:09 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-06-06 21:27:09 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2016-06-06 21:27:09 +02:00
|
|
|
|
2016-11-26 20:43:50 +01:00
|
|
|
public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay{
|
2016-06-06 21:27:09 +02:00
|
|
|
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(80000, 1000, 0);
|
2016-06-06 21:27:09 +02:00
|
|
|
private int oldEnergy;
|
|
|
|
|
|
|
|
public TileEntityDisplayStand(){
|
|
|
|
super(1, "displayStand");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
|
2016-11-26 21:32:27 +01:00
|
|
|
if(!this.world.isRemote){
|
2018-06-23 01:39:30 +02:00
|
|
|
if(StackUtil.isValid(this.inv.getStackInSlot(0)) && !this.isRedstonePowered){
|
|
|
|
IDisplayStandItem item = this.convertToDisplayStandItem(this.inv.getStackInSlot(0).getItem());
|
2016-06-06 21:27:09 +02:00
|
|
|
if(item != null){
|
2018-06-23 01:39:30 +02:00
|
|
|
int energy = item.getUsePerTick(this.inv.getStackInSlot(0), this, this.ticksElapsed);
|
2016-06-06 21:27:09 +02:00
|
|
|
if(this.storage.getEnergyStored() >= energy){
|
2018-06-23 01:39:30 +02:00
|
|
|
if(item.update(this.inv.getStackInSlot(0), this, this.ticksElapsed)){
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.extractEnergyInternal(energy, false);
|
2016-06-06 21:27:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldSyncSlots(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-06-06 21:27:09 +02:00
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
2016-06-06 21:27:09 +02:00
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
private IDisplayStandItem convertToDisplayStandItem(Item item){
|
|
|
|
if(item instanceof IDisplayStandItem){
|
|
|
|
return (IDisplayStandItem)item;
|
|
|
|
}
|
|
|
|
else if(item instanceof ItemBlock){
|
|
|
|
Block block = Block.getBlockFromItem(item);
|
|
|
|
if(block instanceof IDisplayStandItem){
|
|
|
|
return (IDisplayStandItem)block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-23 18:10:55 +01:00
|
|
|
public CustomEnergyStorage getEnergyStorage(){
|
2016-07-21 13:22:55 +02:00
|
|
|
return this.storage;
|
2016-06-06 21:27:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-02 18:39:47 +02:00
|
|
|
@Override
|
|
|
|
public boolean needsHoldShift(){
|
2016-08-31 16:56:32 +02:00
|
|
|
return false;
|
2016-07-02 18:39:47 +02:00
|
|
|
}
|
|
|
|
|
2016-06-06 21:27:09 +02:00
|
|
|
@Override
|
2018-06-23 01:39:30 +02:00
|
|
|
public int getMaxStackSize(int slot){
|
2016-06-06 21:27:09 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
|
|
|
return this.storage;
|
|
|
|
}
|
2018-06-24 02:44:47 +02:00
|
|
|
|
|
|
|
public ItemStack getStack() {
|
|
|
|
return this.inv.getStackInSlot(0);
|
|
|
|
}
|
2016-06-06 21:27:09 +02:00
|
|
|
}
|