2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityFurnaceSolar.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-03-30 15:08:19 +02:00
|
|
|
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2016-12-18 17:28:29 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
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-05-20 22:39:43 +02:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay {
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-07 16:07:23 +01:00
|
|
|
public static final int PRODUCE = 8;
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 0, 100);
|
2021-02-27 16:33:00 +01:00
|
|
|
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
|
2015-12-21 22:18:33 +01:00
|
|
|
private int oldEnergy;
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityFurnaceSolar() {
|
2021-02-27 16:33:00 +01:00
|
|
|
super(ActuallyTiles.SOLAR_TILE.get());
|
2016-05-06 23:23:29 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void writeSyncableNBT(CompoundNBT 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void readSyncableNBT(CompoundNBT 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);
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void updateEntity() {
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!this.level.isClientSide) {
|
2016-09-17 11:48:25 +02:00
|
|
|
int power = this.getPowerToGenerate(PRODUCE);
|
2021-08-22 17:09:06 +02:00
|
|
|
if (this.level.isDay() && power > 0) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (power <= this.storage.getMaxEnergyStored() - this.storage.getEnergyStored()) {
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.receiveEnergyInternal(power, false);
|
2021-08-22 17:09:06 +02:00
|
|
|
this.setChanged();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-30 15:08:19 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()) {
|
2015-12-21 22:18:33 +01:00
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
|
|
|
}
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getPowerToGenerate(int power) {
|
2021-08-22 17:09:06 +02:00
|
|
|
for (int y = 1; y <= this.level.getMaxBuildHeight() - this.worldPosition.getY(); y++) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (power > 0) {
|
2021-08-22 17:09:06 +02:00
|
|
|
BlockPos pos = this.worldPosition.above(y);
|
|
|
|
BlockState state = this.level.getBlockState(pos);
|
2016-09-17 11:48:25 +02:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
if (state.getMaterial().isSolidBlocking()) {
|
2016-09-17 11:48:25 +02:00
|
|
|
power = 0;
|
2021-08-22 17:09:06 +02:00
|
|
|
} else if (!state.getBlock().isAir(state, this.level, pos)) {
|
2016-09-17 11:48:25 +02:00
|
|
|
power--;
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-09-17 11:48:25 +02:00
|
|
|
break;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-17 11:48:25 +02:00
|
|
|
|
|
|
|
return power;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
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-08-31 20:16:36 +02:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getEnergyToSplitShare() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean doesShareEnergy() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public Direction[] getEnergyShareSides() {
|
|
|
|
return Direction.values();
|
2016-08-31 20:16:36 +02:00
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
2016-12-18 17:28:29 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canShareTo(TileEntity tile) {
|
2016-12-18 17:28:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-03-30 15:08:19 +02:00
|
|
|
}
|