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

84 lines
2.1 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.common.tile;
2016-07-03 22:53:12 +02:00
2019-05-02 09:10:29 +02:00
import java.util.ArrayList;
import java.util.List;
2016-07-03 22:53:12 +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-07-03 22:53:12 +02:00
2019-05-02 09:10:29 +02:00
public class TileEntityShockSuppressor extends TileEntityBase implements IEnergyDisplay {
2016-07-03 22:53:12 +02:00
2019-02-27 19:53:05 +01:00
public static final List<TileEntityShockSuppressor> SUPPRESSORS = new ArrayList<>();
2016-07-03 22:53:12 +02:00
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;
2019-05-02 09:10:29 +02:00
public TileEntityShockSuppressor() {
2016-07-03 22:53:12 +02:00
super("shockSuppressor");
}
@Override
2019-05-02 09:10:29 +02:00
public void onChunkUnload() {
2016-07-03 22:53:12 +02:00
super.onChunkUnload();
2019-05-02 09:10:29 +02:00
if (!this.world.isRemote) {
2016-07-03 22:53:12 +02:00
SUPPRESSORS.remove(this);
}
}
@Override
2019-05-02 09:10:29 +02:00
public void invalidate() {
2016-07-03 22:53:12 +02:00
super.invalidate();
2019-05-02 09:10:29 +02:00
if (!this.world.isRemote) {
2016-07-03 22:53:12 +02:00
SUPPRESSORS.remove(this);
}
}
@Override
2019-05-02 09:10:29 +02:00
public void updateEntity() {
2016-07-03 22:53:12 +02:00
super.updateEntity();
2019-05-02 09:10:29 +02:00
if (!this.world.isRemote) {
if (!this.isInvalid() && !SUPPRESSORS.contains(this)) {
2016-07-03 22:53:12 +02:00
SUPPRESSORS.add(this);
}
2019-05-02 09:10:29 +02:00
if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
2016-07-03 22:53:12 +02:00
this.oldEnergy = this.storage.getEnergyStored();
}
}
}
@Override
2019-05-02 09:10:29 +02:00
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
2016-07-03 22:53:12 +02:00
super.writeSyncableNBT(compound, type);
this.storage.writeToNBT(compound);
}
@Override
2019-05-02 09:10:29 +02:00
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
2016-07-03 22:53:12 +02:00
super.readSyncableNBT(compound, type);
this.storage.readFromNBT(compound);
}
@Override
2019-05-02 09:10:29 +02:00
public CustomEnergyStorage getEnergyStorage() {
return this.storage;
2016-07-03 22:53:12 +02:00
}
@Override
2019-05-02 09:10:29 +02:00
public boolean needsHoldShift() {
2016-07-03 22:53:12 +02:00
return false;
}
2016-11-26 08:58:42 +01:00
@Override
2019-05-02 09:10:29 +02:00
public IEnergyStorage getEnergyStorage(EnumFacing facing) {
2016-11-26 08:58:42 +01:00
return this.storage;
}
2016-07-03 22:53:12 +02:00
}