From cb98ef5be13aaf1ca30b4a76b35fef9ddeccbe03 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 30 Mar 2022 14:52:27 +0200 Subject: [PATCH] backport 27aa6809ae4debb0d0dd155b8eea576fe6e078ca --- .../pressurizer/PressurizerBlock.java | 18 ++++++++++++++---- .../pressurizer/PressurizerTileEntity.java | 6 ++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlock.java b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlock.java index 0b2488f..8528999 100644 --- a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerBlock.java @@ -1,9 +1,6 @@ package de.ellpeck.prettypipes.pressurizer; import de.ellpeck.prettypipes.Utility; -import de.ellpeck.prettypipes.pipe.ConnectionType; -import de.ellpeck.prettypipes.pipe.IPipeConnectable; -import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.block.ContainerBlock; @@ -15,7 +12,6 @@ import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; @@ -28,6 +24,7 @@ import javax.annotation.Nullable; import java.util.List; public class PressurizerBlock extends ContainerBlock { + public PressurizerBlock() { super(Properties.create(Material.ROCK).hardnessAndResistance(3).sound(SoundType.STONE)); } @@ -56,4 +53,17 @@ public class PressurizerBlock extends ContainerBlock { public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List tooltip, ITooltipFlag flagIn) { Utility.addTooltip(this.getRegistryName().getPath(), tooltip); } + + @Override + public boolean hasComparatorInputOverride(BlockState state) { + return true; + } + + @Override + public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) { + PressurizerTileEntity pipe = Utility.getTileEntity(PressurizerTileEntity.class, world, pos); + if (pipe == null) + return 0; + return (int) (pipe.getEnergy() / (float) pipe.getMaxEnergy() * 15); + } } diff --git a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java index 11654a6..210b72d 100644 --- a/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pressurizer/PressurizerTileEntity.java @@ -7,7 +7,6 @@ import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.pipe.ConnectionType; import de.ellpeck.prettypipes.pipe.IPipeConnectable; import de.ellpeck.prettypipes.pipe.PipeTileEntity; -import de.ellpeck.prettypipes.terminal.containers.ItemTerminalContainer; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -19,12 +18,10 @@ import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.energy.CapabilityEnergy; @@ -136,9 +133,10 @@ public class PressurizerTileEntity extends TileEntity implements INamedContainer } } - // send energy update + // send energy update and comparator output if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) { this.lastEnergy = this.storage.getEnergyStored(); + this.world.updateComparatorOutputLevel(this.pos, this.getBlockState().getBlock()); Utility.sendTileEntityToClients(this); } }