Decrease carbon footprint of Solid fuel generator. Improvement due to #2403
This commit is contained in:
parent
0932b86811
commit
3edf36e0ef
1 changed files with 41 additions and 22 deletions
|
@ -31,6 +31,7 @@ import net.minecraft.item.BucketItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -56,8 +57,6 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
|
||||||
public int fuelSlot = 0;
|
public int fuelSlot = 0;
|
||||||
public int burnTime;
|
public int burnTime;
|
||||||
public int totalBurnTime = 0;
|
public int totalBurnTime = 0;
|
||||||
// sould properly use the conversion
|
|
||||||
// ratio here.
|
|
||||||
public boolean isBurning;
|
public boolean isBurning;
|
||||||
public boolean lastTickBurning;
|
public boolean lastTickBurning;
|
||||||
ItemStack burnItem;
|
ItemStack burnItem;
|
||||||
|
@ -77,17 +76,28 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateState() {
|
||||||
|
assert world != null;
|
||||||
|
final BlockState BlockStateContainer = world.getBlockState(pos);
|
||||||
|
if (BlockStateContainer.getBlock() instanceof final BlockMachineBase blockMachineBase) {
|
||||||
|
boolean active = burnTime > 0 && getFreeSpace() > 0.0f;
|
||||||
|
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != active) {
|
||||||
|
blockMachineBase.setActive(active, world, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// PowerAcceptorBlockEntity
|
||||||
@Override
|
@Override
|
||||||
public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) {
|
public void tick(World world, BlockPos pos, BlockState state, MachineBaseBlockEntity blockEntity) {
|
||||||
super.tick(world, pos, state, blockEntity);
|
super.tick(world, pos, state, blockEntity);
|
||||||
if (world == null){
|
if (world == null || world.isClient){
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (world.isClient) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
discharge(1);
|
discharge(1);
|
||||||
if (getEnergy() < getMaxStoredPower()) {
|
if (getFreeSpace() >= TechRebornConfig.solidFuelGeneratorOutputAmount) {
|
||||||
if (burnTime > 0) {
|
if (burnTime > 0) {
|
||||||
burnTime--;
|
burnTime--;
|
||||||
addEnergy(TechRebornConfig.solidFuelGeneratorOutputAmount);
|
addEnergy(TechRebornConfig.solidFuelGeneratorOutputAmount);
|
||||||
|
@ -120,16 +130,6 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
|
||||||
lastTickBurning = isBurning;
|
lastTickBurning = isBurning;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateState() {
|
|
||||||
final BlockState BlockStateContainer = world.getBlockState(pos);
|
|
||||||
if (BlockStateContainer.getBlock() instanceof final BlockMachineBase blockMachineBase) {
|
|
||||||
boolean active = burnTime > 0 && getFreeSpace() > 0.0f;
|
|
||||||
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != active) {
|
|
||||||
blockMachineBase.setActive(active, world, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseMaxPower() {
|
public double getBaseMaxPower() {
|
||||||
return TechRebornConfig.solidFuelGeneratorMaxEnergy;
|
return TechRebornConfig.solidFuelGeneratorMaxEnergy;
|
||||||
|
@ -150,16 +150,40 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readNbt(NbtCompound tag) {
|
||||||
|
super.readNbt(tag);
|
||||||
|
burnTime = tag.getInt("BurnTime");
|
||||||
|
totalBurnTime = tag.getInt("TotalBurnTime");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NbtCompound writeNbt(NbtCompound tag) {
|
||||||
|
super.writeNbt(tag);
|
||||||
|
tag.putInt("BurnTime", burnTime);
|
||||||
|
tag.putInt("TotalBurnTime", totalBurnTime);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MachineBaseBlockEntity
|
||||||
|
@Override
|
||||||
|
public boolean canBeUpgraded() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IToolDrop
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
public ItemStack getToolDrop(PlayerEntity playerIn) {
|
||||||
return TRContent.Machine.SOLID_FUEL_GENERATOR.getStack();
|
return TRContent.Machine.SOLID_FUEL_GENERATOR.getStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InventoryProvider
|
||||||
@Override
|
@Override
|
||||||
public RebornInventory<SolidFuelGeneratorBlockEntity> getInventory() {
|
public RebornInventory<SolidFuelGeneratorBlockEntity> getInventory() {
|
||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuiltScreenHandlerProvider
|
||||||
public int getBurnTime() {
|
public int getBurnTime() {
|
||||||
return burnTime;
|
return burnTime;
|
||||||
}
|
}
|
||||||
|
@ -187,9 +211,4 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
|
||||||
.sync(this::getBurnTime, this::setBurnTime)
|
.sync(this::getBurnTime, this::setBurnTime)
|
||||||
.sync(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
.sync(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeUpgraded() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue