ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java

94 lines
2.4 KiB
Java
Raw Normal View History

2016-07-03 22:53:12 +02:00
/*
* This file ("TileEntityShockSuppressor.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-07-03 22:53:12 +02:00
*/
package de.ellpeck.actuallyadditions.mod.tile;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
2016-11-26 08:58:42 +01:00
import net.minecraftforge.energy.IEnergyStorage;
2016-07-03 22:53:12 +02:00
import java.util.ArrayList;
import java.util.List;
2016-11-26 20:43:50 +01:00
public class TileEntityShockSuppressor extends TileEntityBase implements IEnergyDisplay{
2016-07-03 22:53:12 +02:00
public static final List<TileEntityShockSuppressor> SUPPRESSORS = new ArrayList<TileEntityShockSuppressor>();
public static final int USE_PER = 300;
public static final int RANGE = 5;
2016-11-26 20:43:50 +01:00
public CustomEnergyStorage storage = new CustomEnergyStorage(300000, 400, 0);
2016-07-03 22:53:12 +02:00
private int oldEnergy;
public TileEntityShockSuppressor(){
super("shockSuppressor");
}
@Override
public void onChunkUnload(){
super.onChunkUnload();
2016-11-26 21:32:27 +01:00
if(!this.world.isRemote){
2016-07-03 22:53:12 +02:00
SUPPRESSORS.remove(this);
}
}
@Override
public void invalidate(){
super.invalidate();
2016-11-26 21:32:27 +01:00
if(!this.world.isRemote){
2016-07-03 22:53:12 +02:00
SUPPRESSORS.remove(this);
}
}
@Override
public void updateEntity(){
super.updateEntity();
2016-11-26 21:32:27 +01:00
if(!this.world.isRemote){
2016-07-03 22:53:12 +02:00
if(!this.isInvalid() && !SUPPRESSORS.contains(this)){
SUPPRESSORS.add(this);
}
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
this.oldEnergy = this.storage.getEnergyStored();
}
}
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
this.storage.writeToNBT(compound);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
this.storage.readFromNBT(compound);
}
@Override
public CustomEnergyStorage getEnergyStorage(){
return this.storage;
2016-07-03 22:53:12 +02:00
}
@Override
public boolean needsHoldShift(){
return false;
}
2016-11-26 08:58:42 +01:00
@Override
public IEnergyStorage getEnergyStorage(EnumFacing facing){
return this.storage;
}
2016-07-03 22:53:12 +02:00
}