Fluid filter stuff

This commit is contained in:
Shadowfacts 2017-07-02 13:59:13 -04:00
parent c2e96e62c0
commit 6185115c3c
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
8 changed files with 79 additions and 71 deletions

View File

@ -17,7 +17,7 @@ abstract class TileEntityHopperBase<T>(var inverted: Boolean, var advanced: Bool
var mode = RedstoneMode.LOW var mode = RedstoneMode.LOW
private var prevPowered = false private var prevPowered = false
var filterMode = FilterMode.WHITELIST var filterMode = FilterMode.BLACKLIST
abstract var filter: Filter<T> abstract var filter: Filter<T>
constructor(): this(false, false) constructor(): this(false, false)

View File

@ -3,9 +3,13 @@ package net.shadowfacts.extrahoppers.block.fluid
import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Container import net.minecraft.inventory.Container
import net.minecraft.util.ResourceLocation import net.minecraft.util.ResourceLocation
import net.shadowfacts.extrahoppers.ExtraHoppers
import net.shadowfacts.extrahoppers.MOD_ID import net.shadowfacts.extrahoppers.MOD_ID
import net.shadowfacts.extrahoppers.gui.element.UIFilterButton import net.shadowfacts.extrahoppers.gui.element.UIFilterButton
import net.shadowfacts.extrahoppers.gui.element.UIFluidIndicator import net.shadowfacts.extrahoppers.gui.element.UIFluidIndicator
import net.shadowfacts.extrahoppers.network.PacketSetHopperFilterMode
import net.shadowfacts.extrahoppers.network.PacketSetHopperRedstoneMode
import net.shadowfacts.extrahoppers.util.filter.FilterMode
import net.shadowfacts.shadowmc.ui.dsl.container import net.shadowfacts.shadowmc.ui.dsl.container
/** /**
@ -14,12 +18,13 @@ import net.shadowfacts.shadowmc.ui.dsl.container
object GUIFluidHopper { object GUIFluidHopper {
private val BG = ResourceLocation(MOD_ID, "textures/gui/fluid_hopper.png") private val BG = ResourceLocation(MOD_ID, "textures/gui/fluid_hopper.png")
private val FILTER_BG = ResourceLocation(MOD_ID, "textures/gui/filter.png")
fun create(hopper: TileEntityFluidHopper, container: Container): GuiContainer { fun create(tile: TileEntityFluidHopper, container: Container): GuiContainer {
return container(container) { return container(container) {
fixed { fixed {
id = "root" id = "root"
width = 176 width = 176 + 83 * 2
height = 166 height = 166
image { image {
@ -34,21 +39,52 @@ object GUIFluidHopper {
width = 176 width = 176
height = 166 / 2 height = 166 / 2
add(UIFluidIndicator(hopper.tank, "fluidIndicator")) add(UIFluidIndicator(tile.tank, "fluidIndicator"))
if (hopper.advanced) {
buttonRedstoneMode {
id = "mode"
mode = hopper.mode
callback = {
hopper.mode = it
hopper.sync()
}
}
if (tile.advanced) {
add(UIFilterButton({ add(UIFilterButton({
// TODO // TODO
}, "filter")) }, "filter"))
buttonRedstoneMode {
id = "mode"
mode = tile.mode
callback = {
tile.mode = it
ExtraHoppers.network.sendToServer(PacketSetHopperRedstoneMode(tile))
}
}
}
}
if (tile.advanced) {
fixed {
id = "filter-container"
width = 83
height = 86
image {
id = "filter-bg"
width = 83
height = 86
texture = FILTER_BG
}
fixed {
id = "filter-bottom"
width = 83
height = 34
buttonEnum(FilterMode::class.java) {
id = "filter-mode"
value = tile.filterMode
localizer = FilterMode::localize
clickHandler = {
tile.filterMode = it.value
ExtraHoppers.network.sendToServer(PacketSetHopperFilterMode(tile))
}
}
}
} }
} }
} }

View File

@ -52,15 +52,6 @@ class GUIInventoryHopper(container: Container, tile: TileEntityInventoryHopper):
add(UIFixedView(83, 86, "filter-container").apply { add(UIFixedView(83, 86, "filter-container").apply {
add(UIImage(FILTER_BG, 83, 86, "filter-bg")) add(UIImage(FILTER_BG, 83, 86, "filter-bg"))
// add(UIFixedView(52, 37, "filter-slots").apply {
// for (i in 0..2) {
// add(UIItemFilterSlot(tile, i, "filter-slot-$i", "filter-slot-top"))
// }
// for (i in 3..5) {
// add(UIItemFilterSlot(tile, i, "filter-slot-$i", "filter-slot-bottom"))
// }
// })
add(UIFixedView(83, 34, "filter-bottom").apply { add(UIFixedView(83, 34, "filter-bottom").apply {
add(UIButtonEnum<FilterMode>(tile.filterMode, Function(FilterMode::localize), Consumer { add(UIButtonEnum<FilterMode>(tile.filterMode, Function(FilterMode::localize), Consumer {
tile.filterMode = it.value tile.filterMode = it.value

View File

@ -6,7 +6,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler
import net.minecraftforge.fml.common.network.simpleimpl.IMessage import net.minecraftforge.fml.common.network.simpleimpl.IMessage
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext import net.minecraftforge.fml.common.network.simpleimpl.MessageContext
import net.shadowfacts.extrahoppers.block.advanced.TileEntityAdvancedHopper import net.shadowfacts.extrahoppers.block.base.TileEntityHopperBase
import net.shadowfacts.extrahoppers.util.filter.FilterMode import net.shadowfacts.extrahoppers.util.filter.FilterMode
/** /**
@ -24,7 +24,7 @@ class PacketSetHopperFilterMode(): IMessage {
this.mode = mode this.mode = mode
} }
constructor(tile: TileEntityAdvancedHopper): this(tile.world.provider.dimension, tile.pos, tile.filterMode) constructor(tile: TileEntityHopperBase<*>): this(tile.world.provider.dimension, tile.pos, tile.filterMode)
override fun toBytes(buf: ByteBuf) { override fun toBytes(buf: ByteBuf) {
buf.writeInt(dim) buf.writeInt(dim)
@ -43,7 +43,7 @@ class PacketSetHopperFilterMode(): IMessage {
override fun onMessage(message: PacketSetHopperFilterMode, ctx: MessageContext): IMessage? { override fun onMessage(message: PacketSetHopperFilterMode, ctx: MessageContext): IMessage? {
val world = FMLCommonHandler.instance().minecraftServerInstance.getWorld(message.dim) val world = FMLCommonHandler.instance().minecraftServerInstance.getWorld(message.dim)
val tile = world.getTileEntity(message.pos) val tile = world.getTileEntity(message.pos)
if (tile is TileEntityAdvancedHopper) { if (tile is TileEntityHopperBase<*>) {
tile.filterMode = message.mode tile.filterMode = message.mode
tile.markDirty() tile.markDirty()
} }

View File

@ -6,7 +6,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler
import net.minecraftforge.fml.common.network.simpleimpl.IMessage import net.minecraftforge.fml.common.network.simpleimpl.IMessage
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext import net.minecraftforge.fml.common.network.simpleimpl.MessageContext
import net.shadowfacts.extrahoppers.block.advanced.TileEntityAdvancedHopper import net.shadowfacts.extrahoppers.block.base.TileEntityHopperBase
import net.shadowfacts.shadowmc.util.RedstoneMode import net.shadowfacts.shadowmc.util.RedstoneMode
/** /**
@ -24,7 +24,7 @@ class PacketSetHopperRedstoneMode(): IMessage {
this.mode = mode this.mode = mode
} }
constructor(tile: TileEntityAdvancedHopper): this(tile.world.provider.dimension, tile.pos, tile.mode) constructor(tile: TileEntityHopperBase<*>): this(tile.world.provider.dimension, tile.pos, tile.mode)
override fun toBytes(buf: ByteBuf) { override fun toBytes(buf: ByteBuf) {
buf.writeInt(dim) buf.writeInt(dim)
@ -43,7 +43,7 @@ class PacketSetHopperRedstoneMode(): IMessage {
override fun onMessage(message: PacketSetHopperRedstoneMode, ctx: MessageContext): IMessage? { override fun onMessage(message: PacketSetHopperRedstoneMode, ctx: MessageContext): IMessage? {
val world = FMLCommonHandler.instance().minecraftServerInstance.getWorld(message.dim) val world = FMLCommonHandler.instance().minecraftServerInstance.getWorld(message.dim)
val tile = world.getTileEntity(message.pos) val tile = world.getTileEntity(message.pos)
if (tile is TileEntityAdvancedHopper) { if (tile is TileEntityHopperBase<*>) {
tile.mode = message.mode tile.mode = message.mode
tile.markDirty() tile.markDirty()
} }

View File

@ -8,6 +8,8 @@ import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.fluids.capability.CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY import net.minecraftforge.fluids.capability.CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY
import net.minecraftforge.fluids.capability.CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY import net.minecraftforge.fluids.capability.CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY
import net.minecraftforge.fluids.capability.IFluidHandler import net.minecraftforge.fluids.capability.IFluidHandler
import net.shadowfacts.extrahoppers.util.getFluidHandler
import net.shadowfacts.extrahoppers.util.hasFluidHandler
import net.shadowfacts.forgelin.extensions.forEach import net.shadowfacts.forgelin.extensions.forEach
/** /**
@ -21,13 +23,8 @@ class FluidFilter(size: Int): Filter<FluidStack>() {
if (stack.isEmpty) { if (stack.isEmpty) {
filter[i] = null filter[i] = null
} else { } else {
val handler: IFluidHandler = if (stack.hasCapability(FLUID_HANDLER_CAPABILITY, null)) { if (!stack.hasFluidHandler()) return
stack.getCapability(FLUID_HANDLER_CAPABILITY, null)!! val handler = stack.getFluidHandler()
} else if (stack.hasCapability(FLUID_HANDLER_ITEM_CAPABILITY, null)) {
stack.getCapability(FLUID_HANDLER_ITEM_CAPABILITY, null)!!
} else {
return
}
filter[i] = handler.tankProperties[0].contents?.copy() filter[i] = handler.tankProperties[0].contents?.copy()
} }
} }

View File

@ -2,12 +2,27 @@
vertical-layout: top vertical-layout: top
} }
#mode { #filter {
horizontal-layout: left horizontal-layout: left
margin-left: 20 margin-left: 12
vertical-layout: top
margin-top: 18
} }
#filter { #mode {
horizontal-layout: right horizontal-layout: right
margin-right: 20 margin-right: 12
vertical-layout: top
margin-top: 18
}
#filter-container {
horizontal-layout: left
vertical-layout: top
margin-left: 4
}
#filter-bottom {
vertical-layout: bottom
margin-bottom: 3
} }

View File

@ -26,34 +26,3 @@
vertical-layout: bottom vertical-layout: bottom
margin-bottom: 3 margin-bottom: 3
} }
#filter-slots {
vertical-layout: top
margin-top: 11
horizontal-layout: left
margin-left: 17
}
.filter-slot-top {
vertical-layout: top
}
#filter-slot-0 {
horizontal-layout: left
}
#filter-slot-2 {
horizontal-layout: right
}
.filter-slot-bottom {
vertical-layout: bottom
}
#filter-slot-3 {
horizontal-layout: left
}
#filter-slot-4 {
horizontal-layout: right
}