Fluid filter stuff
This commit is contained in:
parent
c2e96e62c0
commit
6185115c3c
|
@ -17,7 +17,7 @@ abstract class TileEntityHopperBase<T>(var inverted: Boolean, var advanced: Bool
|
|||
var mode = RedstoneMode.LOW
|
||||
private var prevPowered = false
|
||||
|
||||
var filterMode = FilterMode.WHITELIST
|
||||
var filterMode = FilterMode.BLACKLIST
|
||||
abstract var filter: Filter<T>
|
||||
|
||||
constructor(): this(false, false)
|
||||
|
|
|
@ -3,9 +3,13 @@ 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.ExtraHoppers
|
||||
import net.shadowfacts.extrahoppers.MOD_ID
|
||||
import net.shadowfacts.extrahoppers.gui.element.UIFilterButton
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -14,12 +18,13 @@ import net.shadowfacts.shadowmc.ui.dsl.container
|
|||
object GUIFluidHopper {
|
||||
|
||||
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) {
|
||||
fixed {
|
||||
id = "root"
|
||||
width = 176
|
||||
width = 176 + 83 * 2
|
||||
height = 166
|
||||
|
||||
image {
|
||||
|
@ -34,21 +39,52 @@ object GUIFluidHopper {
|
|||
width = 176
|
||||
height = 166 / 2
|
||||
|
||||
add(UIFluidIndicator(hopper.tank, "fluidIndicator"))
|
||||
|
||||
if (hopper.advanced) {
|
||||
buttonRedstoneMode {
|
||||
id = "mode"
|
||||
mode = hopper.mode
|
||||
callback = {
|
||||
hopper.mode = it
|
||||
hopper.sync()
|
||||
}
|
||||
}
|
||||
add(UIFluidIndicator(tile.tank, "fluidIndicator"))
|
||||
|
||||
if (tile.advanced) {
|
||||
add(UIFilterButton({
|
||||
// TODO
|
||||
}, "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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,15 +52,6 @@ class GUIInventoryHopper(container: Container, tile: TileEntityInventoryHopper):
|
|||
add(UIFixedView(83, 86, "filter-container").apply {
|
||||
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(UIButtonEnum<FilterMode>(tile.filterMode, Function(FilterMode::localize), Consumer {
|
||||
tile.filterMode = it.value
|
||||
|
|
|
@ -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.IMessageHandler
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ class PacketSetHopperFilterMode(): IMessage {
|
|||
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) {
|
||||
buf.writeInt(dim)
|
||||
|
@ -43,7 +43,7 @@ class PacketSetHopperFilterMode(): IMessage {
|
|||
override fun onMessage(message: PacketSetHopperFilterMode, ctx: MessageContext): IMessage? {
|
||||
val world = FMLCommonHandler.instance().minecraftServerInstance.getWorld(message.dim)
|
||||
val tile = world.getTileEntity(message.pos)
|
||||
if (tile is TileEntityAdvancedHopper) {
|
||||
if (tile is TileEntityHopperBase<*>) {
|
||||
tile.filterMode = message.mode
|
||||
tile.markDirty()
|
||||
}
|
||||
|
|
|
@ -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.IMessageHandler
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ class PacketSetHopperRedstoneMode(): IMessage {
|
|||
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) {
|
||||
buf.writeInt(dim)
|
||||
|
@ -43,7 +43,7 @@ class PacketSetHopperRedstoneMode(): IMessage {
|
|||
override fun onMessage(message: PacketSetHopperRedstoneMode, ctx: MessageContext): IMessage? {
|
||||
val world = FMLCommonHandler.instance().minecraftServerInstance.getWorld(message.dim)
|
||||
val tile = world.getTileEntity(message.pos)
|
||||
if (tile is TileEntityAdvancedHopper) {
|
||||
if (tile is TileEntityHopperBase<*>) {
|
||||
tile.mode = message.mode
|
||||
tile.markDirty()
|
||||
}
|
||||
|
|
|
@ -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_ITEM_CAPABILITY
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler
|
||||
import net.shadowfacts.extrahoppers.util.getFluidHandler
|
||||
import net.shadowfacts.extrahoppers.util.hasFluidHandler
|
||||
import net.shadowfacts.forgelin.extensions.forEach
|
||||
|
||||
/**
|
||||
|
@ -21,13 +23,8 @@ class FluidFilter(size: Int): Filter<FluidStack>() {
|
|||
if (stack.isEmpty) {
|
||||
filter[i] = null
|
||||
} else {
|
||||
val handler: IFluidHandler = if (stack.hasCapability(FLUID_HANDLER_CAPABILITY, null)) {
|
||||
stack.getCapability(FLUID_HANDLER_CAPABILITY, null)!!
|
||||
} else if (stack.hasCapability(FLUID_HANDLER_ITEM_CAPABILITY, null)) {
|
||||
stack.getCapability(FLUID_HANDLER_ITEM_CAPABILITY, null)!!
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if (!stack.hasFluidHandler()) return
|
||||
val handler = stack.getFluidHandler()
|
||||
filter[i] = handler.tankProperties[0].contents?.copy()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,27 @@
|
|||
vertical-layout: top
|
||||
}
|
||||
|
||||
#mode {
|
||||
#filter {
|
||||
horizontal-layout: left
|
||||
margin-left: 20
|
||||
margin-left: 12
|
||||
vertical-layout: top
|
||||
margin-top: 18
|
||||
}
|
||||
|
||||
#filter {
|
||||
#mode {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -26,34 +26,3 @@
|
|||
vertical-layout: bottom
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue