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;
|
|
|
|
|
2021-11-13 18:16:25 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
2021-02-27 16:33:00 +01:00
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
2016-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2016-07-03 22:53:12 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
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);
|
2021-02-27 16:33:00 +01:00
|
|
|
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
2016-07-03 22:53:12 +02:00
|
|
|
private int oldEnergy;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityShockSuppressor() {
|
2021-11-13 18:16:25 +01:00
|
|
|
super(ActuallyBlocks.SHOCK_SUPPRESSOR.getTileEntityType());
|
2016-07-03 22:53:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 16:33:00 +01:00
|
|
|
public void onChunkUnloaded() {
|
|
|
|
super.onChunkUnloaded();
|
2016-07-03 22:53:12 +02:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!this.level.isClientSide) {
|
2016-07-03 22:53:12 +02:00
|
|
|
SUPPRESSORS.remove(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 16:33:00 +01:00
|
|
|
public void invalidateCaps() {
|
|
|
|
super.invalidateCaps();
|
2016-07-03 22:53:12 +02:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!this.level.isClientSide) {
|
2016-07-03 22:53:12 +02:00
|
|
|
SUPPRESSORS.remove(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-27 16:33:00 +01:00
|
|
|
|
2016-07-03 22:53:12 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void updateEntity() {
|
2016-07-03 22:53:12 +02:00
|
|
|
super.updateEntity();
|
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!this.level.isClientSide) {
|
2021-02-27 16:33:00 +01:00
|
|
|
if (!this.isRemoved() && !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
|
2021-02-26 22:15:48 +01:00
|
|
|
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
2016-07-03 22:53:12 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void readSyncableNBT(CompoundNBT 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() {
|
2016-07-21 13:22:55 +02:00
|
|
|
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
|
2021-02-27 16:33:00 +01:00
|
|
|
public LazyOptional<IEnergyStorage> getEnergyStorage(Direction facing) {
|
|
|
|
return this.lazyEnergy;
|
2016-11-26 08:58:42 +01:00
|
|
|
}
|
2016-07-03 22:53:12 +02:00
|
|
|
}
|