Add comparator support for energy storage and generator blocks (#1901)
* Add comparator support for energy storage blocks Does not update automatically yet, so there needs to be a call to World.updateHorizontalAdjacent. * Switch to ceil() in energy storage comparator calculation Should prevent low amounts of energy of rounding to 0. * Add comparator support to generators Requires TechReborn/RebornCore#132.
This commit is contained in:
parent
4764271967
commit
87a36d1c23
4 changed files with 66 additions and 10 deletions
|
@ -24,10 +24,14 @@
|
|||
|
||||
package techreborn.blocks.generator;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import techreborn.init.TRContent.SolarPanels;
|
||||
import techreborn.blockentity.generator.SolarPanelBlockEntity;
|
||||
|
||||
|
@ -52,4 +56,14 @@ public class BlockSolarPanel extends BlockMachineBase {
|
|||
public IMachineGuiHandler getGui() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorOutput(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
|
||||
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package techreborn.blocks.generator;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import techreborn.blocks.GenericMachineBlock;
|
||||
import techreborn.client.EGui;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* An extension of {@link GenericMachineBlock} that provides utilities
|
||||
* for generators, like comparator output based on energy.
|
||||
*/
|
||||
public class GenericGeneratorBlock extends GenericMachineBlock {
|
||||
public GenericGeneratorBlock(EGui gui, Supplier<BlockEntity> blockEntityClass) {
|
||||
super(gui, blockEntityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorOutput(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
|
||||
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));
|
||||
}
|
||||
}
|
|
@ -45,6 +45,7 @@ import reborncore.api.ToolManager;
|
|||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import reborncore.common.BaseBlockEntityProvider;
|
||||
import reborncore.common.blocks.BlockWrenchEventHandler;
|
||||
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
|
||||
import reborncore.common.util.WrenchUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -137,4 +138,14 @@ public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
|
|||
}
|
||||
setFacing(facing, worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorOutput(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
|
||||
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue