2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityLavaFactoryController.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
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.Block;
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
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;
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyDisplay {
|
2015-06-06 01:25:53 +02:00
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
public static final int NOT_MULTI = 0;
|
|
|
|
public static final int HAS_LAVA = 1;
|
|
|
|
public static final int HAS_AIR = 2;
|
2015-12-01 19:48:09 +01:00
|
|
|
public static final int ENERGY_USE = 150000;
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(300000, 2000, 0);
|
2021-02-27 16:33:00 +01:00
|
|
|
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
private int currentWorkTime;
|
2015-12-23 14:03:41 +01:00
|
|
|
private int oldEnergy;
|
2015-07-25 05:28:31 +02:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public TileEntityLavaFactoryController(BlockPos pos, BlockState state) {
|
|
|
|
super(ActuallyBlocks.LAVA_FACTORY_CONTROLLER.getTileEntityType(), pos, state);
|
2016-05-06 23:23:29 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public void writeSyncableNBT(CompoundTag compound, NBTType type) {
|
2016-07-02 15:01:46 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2021-02-27 16:33:00 +01:00
|
|
|
compound.putInt("WorkTime", this.currentWorkTime);
|
2016-07-02 15:01:46 +02:00
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public void readSyncableNBT(CompoundTag compound, NBTType type) {
|
2016-07-02 15:01:46 +02:00
|
|
|
super.readSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (type != NBTType.SAVE_BLOCK) {
|
2021-02-27 16:33:00 +01:00
|
|
|
this.currentWorkTime = compound.getInt("WorkTime");
|
2016-07-02 15:01:46 +02:00
|
|
|
}
|
2016-02-01 17:49:55 +01: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 TileEntityLavaFactoryController tile) {
|
|
|
|
tile.clientTick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T extends BlockEntity> void serverTick(Level level, BlockPos pos, BlockState state, T t) {
|
|
|
|
if (t instanceof TileEntityLavaFactoryController tile) {
|
|
|
|
tile.serverTick();
|
|
|
|
|
|
|
|
if (tile.storage.getEnergyStored() >= ENERGY_USE && tile.isMultiblock() == HAS_AIR) {
|
|
|
|
tile.currentWorkTime++;
|
|
|
|
if (tile.currentWorkTime >= 200) {
|
|
|
|
tile.currentWorkTime = 0;
|
|
|
|
level.setBlock(tile.worldPosition.above(), Blocks.LAVA.defaultBlockState(), 2);
|
|
|
|
tile.storage.extractEnergyInternal(ENERGY_USE, false);
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2024-03-02 21:23:08 +01:00
|
|
|
tile.currentWorkTime = 0;
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2015-12-23 14:03:41 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
if (tile.oldEnergy != tile.storage.getEnergyStored() && tile.sendUpdateWithInterval()) {
|
|
|
|
tile.oldEnergy = tile.storage.getEnergyStored();
|
2015-12-23 14:03:41 +01:00
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public int isMultiblock() {
|
2021-08-22 17:09:06 +02:00
|
|
|
BlockPos thisPos = this.worldPosition;
|
|
|
|
BlockPos[] positions = new BlockPos[]{thisPos.offset(1, 1, 0), thisPos.offset(-1, 1, 0), thisPos.offset(0, 1, 1), thisPos.offset(0, 1, -1)};
|
2016-01-07 23:42:42 +01:00
|
|
|
|
2021-11-13 18:16:25 +01:00
|
|
|
if (this.level != null && WorldUtil.hasBlocksInPlacesGiven(positions, ActuallyBlocks.LAVA_FACTORY_CASING.get(), this.level)) {
|
2021-08-22 17:09:06 +02:00
|
|
|
BlockPos pos = thisPos.above();
|
|
|
|
BlockState state = this.level.getBlockState(pos);
|
2016-07-04 20:15:41 +02:00
|
|
|
Block block = state.getBlock();
|
2021-02-27 16:33:00 +01:00
|
|
|
if (block == Blocks.LAVA) {
|
2021-02-26 22:15:48 +01:00
|
|
|
return HAS_LAVA;
|
|
|
|
}
|
2021-08-22 17:09:06 +02:00
|
|
|
if (this.level.isEmptyBlock(pos)) {
|
2021-02-26 22:15:48 +01:00
|
|
|
return HAS_AIR;
|
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|
|
|
|
return NOT_MULTI;
|
|
|
|
}
|
|
|
|
|
2015-12-13 00:54:25 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public CustomEnergyStorage getEnergyStorage() {
|
2016-07-21 13:22:55 +02:00
|
|
|
return this.storage;
|
2015-12-13 00:54:25 +01:00
|
|
|
}
|
2016-07-02 18:39:47 +02:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean needsHoldShift() {
|
2016-07-02 18:39:47 +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
|
|
|
}
|
2015-06-06 01:25:53 +02:00
|
|
|
}
|