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 a39346c..f30b27e 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/BlockFluidHopper.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/BlockFluidHopper.kt @@ -13,7 +13,9 @@ import net.minecraft.world.World import net.minecraftforge.fluids.FluidUtil import net.minecraftforge.fluids.capability.CapabilityFluidHandler import net.minecraftforge.fml.common.registry.GameRegistry +import net.shadowfacts.extrahoppers.ExtraHoppers import net.shadowfacts.extrahoppers.block.base.BlockHopperBase +import net.shadowfacts.extrahoppers.gui.GUIHandler /** * @author shadowfacts @@ -27,8 +29,9 @@ class BlockFluidHopper: BlockHopperBase("fluid_hopper", m } override fun onBlockActivated(world: World, pos: BlockPos, state: IBlockState, player: EntityPlayer, hand: EnumHand, side: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean { -// TODO: GUI - if (!player.isSneaking) { + if (player.isSneaking) { + player.openGui(ExtraHoppers, GUIHandler.FLUID_HOPPER, world, pos.x, pos.y, pos.z) + } else { val te = getTileEntity(world, pos) val stack = player.getHeldItem(hand) val result = FluidUtil.interactWithFluidHandler(stack, te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.NORTH), player) diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/GUIFluidHopper.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/GUIFluidHopper.kt new file mode 100644 index 0000000..8fe6efe --- /dev/null +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/block/fluid/GUIFluidHopper.kt @@ -0,0 +1,44 @@ +package net.shadowfacts.extrahoppers.block.fluid + +import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.inventory.Container +import net.minecraft.util.ResourceLocation +import net.shadowfacts.extrahoppers.MOD_ID +import net.shadowfacts.extrahoppers.gui.element.UIFluidIndicator +import net.shadowfacts.shadowmc.ui.dsl.* + +/** + * @author shadowfacts + */ +object GUIFluidHopper { + + private val BG = ResourceLocation("shadowmc", "textures/gui/blank.png") + + fun create(hopper: TileEntityFluidHopper, container: Container): GuiContainer { + return container(container) { + fixed { + id = "root" + width = 176 + height = 166 + + image { + id = "bg" + width = 176 + height = 166 + texture = BG + } + + fixed { + id = "top" + width = 176 + height = 166 / 2 + + add(UIFluidIndicator(hopper.tank, "fluidIndicator")) + } + } + + style("$MOD_ID:fluid_hopper") + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/gui/GUIHandler.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/gui/GUIHandler.kt index 6e1c908..833cfde 100644 --- a/src/main/kotlin/net/shadowfacts/extrahoppers/gui/GUIHandler.kt +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/gui/GUIHandler.kt @@ -5,9 +5,12 @@ import net.minecraft.inventory.Container import net.minecraft.util.math.BlockPos import net.minecraft.world.World import net.minecraftforge.fml.common.network.IGuiHandler +import net.shadowfacts.extrahoppers.block.fluid.GUIFluidHopper +import net.shadowfacts.extrahoppers.block.fluid.TileEntityFluidHopper import net.shadowfacts.extrahoppers.block.wooden.ContainerWoodenHopper import net.shadowfacts.extrahoppers.block.wooden.GUIWoodenHopper import net.shadowfacts.extrahoppers.block.wooden.TileEntityWoodenHopper +import net.shadowfacts.shadowmc.inventory.ContainerPlayerInv /** * @author shadowfacts @@ -18,7 +21,9 @@ object GUIHandler: IGuiHandler { val WOODEN_HOPPER = 1 override fun getClientGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): Any? { + val pos = BlockPos(x, y, z) return when (ID) { + FLUID_HOPPER -> GUIFluidHopper.create(world.getTileEntity(pos) as TileEntityFluidHopper, getServerGuiElement(ID, player, world, x, y, z)!!) WOODEN_HOPPER -> GUIWoodenHopper(getServerGuiElement(ID, player, world, x, y, z)!!) else -> null } @@ -27,6 +32,7 @@ object GUIHandler: IGuiHandler { override fun getServerGuiElement(ID: Int, player: EntityPlayer, world: World, x: Int, y: Int, z: Int): Container? { val pos = BlockPos(x, y, z) return when (ID) { + FLUID_HOPPER -> ContainerPlayerInv(pos, player.inventory) WOODEN_HOPPER -> ContainerWoodenHopper(world.getTileEntity(pos) as TileEntityWoodenHopper, player.inventory, pos) else -> null } diff --git a/src/main/kotlin/net/shadowfacts/extrahoppers/gui/element/UIFluidIndicator.kt b/src/main/kotlin/net/shadowfacts/extrahoppers/gui/element/UIFluidIndicator.kt new file mode 100644 index 0000000..2d43324 --- /dev/null +++ b/src/main/kotlin/net/shadowfacts/extrahoppers/gui/element/UIFluidIndicator.kt @@ -0,0 +1,16 @@ +package net.shadowfacts.extrahoppers.gui.element + +import net.minecraftforge.fluids.IFluidTank +import net.shadowfacts.shadowmc.ui.UIDimensions +import net.shadowfacts.shadowmc.ui.element.UIFluidIndicator + +/** + * @author shadowfacts + */ +class UIFluidIndicator(tank: IFluidTank, id: String, vararg classes: String): UIFluidIndicator(tank, id, *classes) { + + override fun getPreferredDimensions(): UIDimensions { + return UIDimensions(20, 73) + } + +} \ No newline at end of file diff --git a/src/main/resources/assets/extrahoppers/gui/fluid_hopper.uiss b/src/main/resources/assets/extrahoppers/gui/fluid_hopper.uiss new file mode 100644 index 0000000..ce09c48 --- /dev/null +++ b/src/main/resources/assets/extrahoppers/gui/fluid_hopper.uiss @@ -0,0 +1,3 @@ +#top { + vertical-layout: top +} \ No newline at end of file