From 92cb972d67bd15059add7628dc47b884ab322d49 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 15 Jan 2017 12:19:44 -0500 Subject: [PATCH] Redstone Closes #13 --- .../block/base/TileEntityHopperBase.kt | 4 ++++ .../extrahoppers/block/fluid/BlockFluidHopper.kt | 16 ++++++++++++++++ .../block/fluid/TileEntityFluidHopper.kt | 3 ++- .../block/inverted/BlockInvertedHopper.kt | 11 +++++++++++ .../block/inverted/TileEntityInvertedHopper.kt | 2 ++ .../block/wooden/TileEntityWoodenHopper.kt | 3 ++- .../wooden_fluid/TileEntityWoodenFluidHopper.kt | 1 + 7 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/base/TileEntityHopperBase.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/base/TileEntityHopperBase.kt index 218311a..92a5825 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/base/TileEntityHopperBase.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/base/TileEntityHopperBase.kt @@ -11,6 +11,10 @@ abstract class TileEntityHopperBase(var inverted: Boolean): BaseTileEntity() { constructor(): this(false) + fun isPowered(): Boolean { + return world.isBlockPowered(pos) + } + fun getHopperFacing(): EnumFacing { return world.getBlockState(pos).getValue(BlockHopperBase.FACING) } diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/BlockFluidHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/BlockFluidHopper.kt index d7cc78a..f2bc6b2 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/BlockFluidHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/BlockFluidHopper.kt @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.MathHelper import net.minecraft.world.World import net.minecraftforge.fluids.FluidUtil import net.minecraftforge.fluids.capability.CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY @@ -27,6 +28,21 @@ open class BlockFluidHopper(inverted: Boolean, name: String = "fluid_hopper", ma soundType = SoundType.METAL } + @Deprecated("") + override fun hasComparatorInputOverride(state: IBlockState): Boolean { + return true + } + + @Deprecated("") + override fun getComparatorInputOverride(blockState: IBlockState, world: World, pos: BlockPos): Int { + val tank = getTileEntity(world, pos).tank + if (tank.fluidAmount == 0) { + return 0 + } else { + return MathHelper.floor((tank.fluidAmount / tank.capacity) * 14.0) + 1 + } + } + override fun onBlockActivated(world: World, pos: BlockPos, state: IBlockState, player: EntityPlayer, hand: EnumHand, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean { if (player.isSneaking) { player.openGui(ExtraHoppers, GUIHandler.FLUID_HOPPER, world, pos.x, pos.y, pos.z) diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/TileEntityFluidHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/TileEntityFluidHopper.kt index 65ca09f..7b8f231 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/TileEntityFluidHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/TileEntityFluidHopper.kt @@ -57,7 +57,8 @@ open class TileEntityFluidHopper(inverted: Boolean): TileEntityHopperBase(invert override fun update() { if (!world.isRemote) { -// TODO: redstone me + if (isPowered()) return + handlerCooldown-- if (handlerCooldown <= 0) { handleFluidHandlers() diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/BlockInvertedHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/BlockInvertedHopper.kt index 14ad5cf..ca8f60a 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/BlockInvertedHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/BlockInvertedHopper.kt @@ -8,6 +8,7 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.world.World +import net.minecraftforge.items.ItemHandlerHelper import net.shadowfacts.extrahoppers.ExtraHoppers import net.shadowfacts.extrahoppers.block.base.BlockHopperBase import net.shadowfacts.extrahoppers.gui.GUIHandler @@ -23,6 +24,16 @@ class BlockInvertedHopper: BlockHopperBase(true, "hopp soundType = SoundType.METAL } + @Deprecated("") + override fun hasComparatorInputOverride(state: IBlockState): Boolean { + return true + } + + @Deprecated("") + override fun getComparatorInputOverride(blockState: IBlockState, world: World, pos: BlockPos): Int { + return ItemHandlerHelper.calcRedstoneFromInventory(getTileEntity(world, pos).inventory) + } + override fun onBlockActivated(world: World, pos: BlockPos, state: IBlockState, player: EntityPlayer, hand: EnumHand, facing: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean { player.openGui(ExtraHoppers, GUIHandler.INVERTED_HOPPER, world, pos.x, pos.y, pos.z) return true diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/TileEntityInvertedHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/TileEntityInvertedHopper.kt index aa92a78..906ae15 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/TileEntityInvertedHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/inverted/TileEntityInvertedHopper.kt @@ -30,6 +30,8 @@ class TileEntityInvertedHopper: TileEntityHopperBase(), ITickable { override fun update() { if (!world.isRemote) { + if (isPowered()) return + cooldown-- if (cooldown <= 0) { val pulled = pull() diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden/TileEntityWoodenHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden/TileEntityWoodenHopper.kt index eb5f3f6..660618d 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden/TileEntityWoodenHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden/TileEntityWoodenHopper.kt @@ -29,7 +29,8 @@ class TileEntityWoodenHopper: TileEntityHopperBase(), ITickable { override fun update() { if (!world.isRemote) { -// TODO: redstone + if (isPowered()) return + cooldown-- if (cooldown <= 0) { val pulled = pull() diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden_fluid/TileEntityWoodenFluidHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden_fluid/TileEntityWoodenFluidHopper.kt index 721ca5b..8687cab 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden_fluid/TileEntityWoodenFluidHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/wooden_fluid/TileEntityWoodenFluidHopper.kt @@ -10,4 +10,5 @@ import net.shadowfacts.extrahoppers.block.fluid.TileEntityFluidHopper class TileEntityWoodenFluidHopper: TileEntityFluidHopper() { override val fluidValiator: (FluidStack) -> Boolean = { it.fluid.temperature <= EHConfig.wfhMaxTemperature } + } \ No newline at end of file