Remove IContainer
This commit is contained in:
parent
59eab74b44
commit
c43be6eb62
@ -1,81 +0,0 @@
|
|||||||
package ru.dbotthepony.mc.otm.container
|
|
||||||
|
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Player
|
|
||||||
import net.minecraft.world.item.Item
|
|
||||||
import net.minecraft.world.item.ItemStack
|
|
||||||
import java.util.function.Predicate
|
|
||||||
import java.util.function.Supplier
|
|
||||||
|
|
||||||
/**
|
|
||||||
* because mods tend to do crazy shit
|
|
||||||
*/
|
|
||||||
class DynamicallyProxiedContainer(private val toProxy: Supplier<Container>) : IContainer {
|
|
||||||
override fun clearContent() {
|
|
||||||
return toProxy.get().clearContent()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getContainerSize(): Int {
|
|
||||||
return toProxy.get().containerSize
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isEmpty(): Boolean {
|
|
||||||
return toProxy.get().isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItem(slot: Int): ItemStack {
|
|
||||||
return toProxy.get().getItem(slot)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeItem(slot: Int, amount: Int): ItemStack {
|
|
||||||
return toProxy.get().removeItem(slot, amount)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeItemNoUpdate(slot: Int): ItemStack {
|
|
||||||
return toProxy.get().removeItemNoUpdate(slot)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setItem(slot: Int, itemStack: ItemStack) {
|
|
||||||
return toProxy.get().setItem(slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setChanged() {
|
|
||||||
return toProxy.get().setChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun stillValid(player: Player): Boolean {
|
|
||||||
return toProxy.get().stillValid(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getMaxStackSize(): Int {
|
|
||||||
return toProxy.get().getMaxStackSize()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun startOpen(player: Player) {
|
|
||||||
toProxy.get().startOpen(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun stopOpen(player: Player) {
|
|
||||||
toProxy.get().stopOpen(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canPlaceItem(slot: Int, itemStack: ItemStack): Boolean {
|
|
||||||
return toProxy.get().canPlaceItem(slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canTakeItem(container: Container, slot: Int, itemStack: ItemStack): Boolean {
|
|
||||||
return toProxy.get().canTakeItem(container, slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun countItem(item: Item): Int {
|
|
||||||
return toProxy.get().countItem(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasAnyOf(items: Set<Item>): Boolean {
|
|
||||||
return toProxy.get().hasAnyOf(items)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasAnyMatching(predicate: Predicate<ItemStack>): Boolean {
|
|
||||||
return toProxy.get().hasAnyMatching(predicate)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
package ru.dbotthepony.mc.otm.container
|
|
||||||
|
|
||||||
import net.minecraft.world.Container
|
|
||||||
import net.minecraft.world.entity.player.Player
|
|
||||||
import net.minecraft.world.item.Item
|
|
||||||
import net.minecraft.world.item.ItemStack
|
|
||||||
import java.util.function.Predicate
|
|
||||||
|
|
||||||
// passthrough all default methods to fix Kotlin bug related to implementation delegation not properly working on Java interfaces
|
|
||||||
// and also to give params proper names
|
|
||||||
// https://youtrack.jetbrains.com/issue/KT-55080/Change-the-behavior-of-inheritance-delegation-to-delegates-implementing-Java-interfaces-with-default-methods
|
|
||||||
interface IContainer : Container {
|
|
||||||
override fun getMaxStackSize(): Int {
|
|
||||||
return super.getMaxStackSize()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun startOpen(player: Player) {
|
|
||||||
super.startOpen(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun stopOpen(player: Player) {
|
|
||||||
super.stopOpen(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canPlaceItem(slot: Int, itemStack: ItemStack): Boolean {
|
|
||||||
return super.canPlaceItem(slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canTakeItem(container: Container, slot: Int, itemStack: ItemStack): Boolean {
|
|
||||||
return super.canTakeItem(container, slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun countItem(item: Item): Int {
|
|
||||||
return super.countItem(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasAnyOf(items: Set<Item>): Boolean {
|
|
||||||
return super.hasAnyOf(items)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasAnyMatching(predicate: Predicate<ItemStack>): Boolean {
|
|
||||||
return super.hasAnyMatching(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun clearContent()
|
|
||||||
override fun getContainerSize(): Int
|
|
||||||
override fun isEmpty(): Boolean
|
|
||||||
override fun getItem(slot: Int): ItemStack
|
|
||||||
override fun removeItem(slot: Int, amount: Int): ItemStack
|
|
||||||
override fun removeItemNoUpdate(slot: Int): ItemStack
|
|
||||||
override fun setItem(slot: Int, itemStack: ItemStack)
|
|
||||||
override fun setChanged()
|
|
||||||
|
|
||||||
override fun stillValid(player: Player): Boolean
|
|
||||||
companion object {
|
|
||||||
fun wrap(container: Container): IContainer {
|
|
||||||
if (container is IContainer)
|
|
||||||
return container
|
|
||||||
else
|
|
||||||
return object : IContainer, Container by container {
|
|
||||||
override fun getMaxStackSize(): Int {
|
|
||||||
return container.getMaxStackSize()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun startOpen(player: Player) {
|
|
||||||
container.startOpen(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun stopOpen(player: Player) {
|
|
||||||
container.stopOpen(player)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canPlaceItem(slot: Int, itemStack: ItemStack): Boolean {
|
|
||||||
return container.canPlaceItem(slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canTakeItem(container: Container, slot: Int, itemStack: ItemStack): Boolean {
|
|
||||||
return container.canTakeItem(container, slot, itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun countItem(item: Item): Int {
|
|
||||||
return container.countItem(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasAnyOf(items: Set<Item>): Boolean {
|
|
||||||
return container.hasAnyOf(items)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hasAnyMatching(predicate: Predicate<ItemStack>): Boolean {
|
|
||||||
return container.hasAnyMatching(predicate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,12 +19,41 @@ import java.util.stream.Stream
|
|||||||
import java.util.stream.StreamSupport
|
import java.util.stream.StreamSupport
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Backward-compatible" enhanced container interface, where all methods can be derived/emulated from existing [IContainer] ([Container]) code
|
* "Backward-compatible" enhanced container interface, where all methods can be derived/emulated from existing [Container] code
|
||||||
*
|
*
|
||||||
* This is useful because it allows to interact with actually enhanced and regular containers through unified interface,
|
* This is useful because it allows to interact with actually enhanced and regular containers through unified interface,
|
||||||
* and actual implementations of this interface are likely to provide efficient method implementations in place of derived/emulated ones.
|
* and actual implementations of this interface are likely to provide efficient method implementations in place of derived/emulated ones.
|
||||||
*/
|
*/
|
||||||
interface IEnhancedContainer<S : IContainerSlot> : IContainer, RecipeInput, Iterable<ItemStack>, StackedContentsCompatible {
|
interface IEnhancedContainer<S : IContainerSlot> : Container, RecipeInput, Iterable<ItemStack>, StackedContentsCompatible {
|
||||||
|
// https://youtrack.jetbrains.com/issue/KT-55080/Change-the-behavior-of-inheritance-delegation-to-delegates-implementing-Java-interfaces-with-default-methods
|
||||||
|
override fun getMaxStackSize(): Int {
|
||||||
|
return super.getMaxStackSize()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startOpen(player: Player) {
|
||||||
|
super.startOpen(player)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stopOpen(player: Player) {
|
||||||
|
super.stopOpen(player)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canPlaceItem(slot: Int, itemStack: ItemStack): Boolean {
|
||||||
|
return super.canPlaceItem(slot, itemStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun canTakeItem(container: Container, slot: Int, itemStack: ItemStack): Boolean {
|
||||||
|
return super.canTakeItem(container, slot, itemStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clearContent()
|
||||||
|
override fun getContainerSize(): Int
|
||||||
|
override fun getItem(slot: Int): ItemStack
|
||||||
|
override fun removeItem(slot: Int, amount: Int): ItemStack
|
||||||
|
override fun removeItemNoUpdate(slot: Int): ItemStack
|
||||||
|
override fun setItem(slot: Int, itemStack: ItemStack)
|
||||||
|
override fun setChanged()
|
||||||
|
|
||||||
// provide non-ambiguous get and set operators
|
// provide non-ambiguous get and set operators
|
||||||
operator fun get(slot: Int): ItemStack {
|
operator fun get(slot: Int): ItemStack {
|
||||||
return getItem(slot)
|
return getItem(slot)
|
||||||
|
@ -79,9 +79,7 @@ import ru.dbotthepony.mc.otm.client.minecraft
|
|||||||
import ru.dbotthepony.mc.otm.config.PlayerConfig
|
import ru.dbotthepony.mc.otm.config.PlayerConfig
|
||||||
import ru.dbotthepony.mc.otm.config.ExopackConfig
|
import ru.dbotthepony.mc.otm.config.ExopackConfig
|
||||||
import ru.dbotthepony.mc.otm.container.CombinedContainer
|
import ru.dbotthepony.mc.otm.container.CombinedContainer
|
||||||
import ru.dbotthepony.mc.otm.container.DynamicallyProxiedContainer
|
|
||||||
import ru.dbotthepony.mc.otm.container.EnhancedContainer
|
import ru.dbotthepony.mc.otm.container.EnhancedContainer
|
||||||
import ru.dbotthepony.mc.otm.container.IContainer
|
|
||||||
import ru.dbotthepony.mc.otm.container.IContainerSlot
|
import ru.dbotthepony.mc.otm.container.IContainerSlot
|
||||||
import ru.dbotthepony.mc.otm.container.IEnhancedContainer
|
import ru.dbotthepony.mc.otm.container.IEnhancedContainer
|
||||||
import ru.dbotthepony.mc.otm.container.IFilteredContainerSlot
|
import ru.dbotthepony.mc.otm.container.IFilteredContainerSlot
|
||||||
|
Loading…
Reference in New Issue
Block a user