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

104 lines
3.1 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;
2021-11-13 18:16:25 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
2024-03-02 21:23:08 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
2024-03-04 20:21:48 +01:00
import net.neoforged.neoforge.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);
2016-07-03 22:53:12 +02:00
private int oldEnergy;
2024-03-02 21:23:08 +01:00
public TileEntityShockSuppressor(BlockPos pos, BlockState state) {
super(ActuallyBlocks.SHOCK_SUPPRESSOR.getTileEntityType(), pos, state);
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
if (!this.level.isClientSide) {
2016-07-03 22:53:12 +02:00
SUPPRESSORS.remove(this);
}
}
2024-03-04 21:38:02 +01:00
// @Override
// public void invalidateCaps() {
// super.invalidateCaps();
//
// if (!this.level.isClientSide) {
// SUPPRESSORS.remove(this);
// }
// }
2016-07-03 22:53:12 +02:00
2024-03-02 21:23:08 +01:00
public static <T extends BlockEntity> void clientTick(Level level, BlockPos pos, BlockState state, T t) {
if (t instanceof TileEntityShockSuppressor tile) {
tile.clientTick();
}
}
2021-02-27 16:33:00 +01:00
2024-03-02 21:23:08 +01:00
public static <T extends BlockEntity> void serverTick(Level level, BlockPos pos, BlockState state, T t) {
if (t instanceof TileEntityShockSuppressor tile) {
tile.serverTick();
2016-07-03 22:53:12 +02:00
2024-03-02 21:23:08 +01:00
if (!tile.isRemoved() && !SUPPRESSORS.contains(tile)) {
SUPPRESSORS.add(tile);
2016-07-03 22:53:12 +02:00
}
2024-03-02 21:23:08 +01:00
if (tile.oldEnergy != tile.storage.getEnergyStored() && tile.sendUpdateWithInterval()) {
tile.oldEnergy = tile.storage.getEnergyStored();
2016-07-03 22:53:12 +02:00
}
}
}
@Override
2024-03-02 21:23:08 +01:00
public void writeSyncableNBT(CompoundTag compound, NBTType type) {
2016-07-03 22:53:12 +02:00
super.writeSyncableNBT(compound, type);
this.storage.writeToNBT(compound);
}
@Override
2024-03-02 21:23:08 +01:00
public void readSyncableNBT(CompoundTag 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
2024-03-04 20:21:48 +01:00
public IEnergyStorage getEnergyStorage(Direction facing) {
2024-03-04 21:38:02 +01:00
return this.storage;
2016-11-26 08:58:42 +01:00
}
2016-07-03 22:53:12 +02:00
}