Update to 1.16.5

This commit is contained in:
Shadowfacts 2021-02-10 18:55:49 -05:00
parent 8a20837f11
commit b1c37595ab
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
17 changed files with 154 additions and 143 deletions

View File

@ -1,7 +1,7 @@
plugins {
id "fabric-loom" version "0.2.5-SNAPSHOT"
id "fabric-loom" version "0.5-SNAPSHOT"
id "maven-publish"
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "org.jetbrains.kotlin.jvm" version "1.4.30"
}
sourceCompatibility = JavaVersion.VERSION_1_8
@ -40,14 +40,9 @@ dependencies {
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
filesMatching("fabric.mod.json") {
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
@ -57,16 +52,17 @@ tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from "LICENSE"
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
}
// configure the maven publication
@ -88,4 +84,4 @@ publishing {
// uncomment to publish to the local maven
// mavenLocal()
}
}
}

View File

@ -1,15 +1,15 @@
org.gradle.jvmargs=-Xmx1G
org.gradle.daemon=false
minecraft_version=1.14.4
yarn_mappings=1.14.4+build.14
loader_version=0.6.3+build.167
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.4
loader_version=0.11.1
mod_version=0.1.0
maven_group=net.shadowfacts
archives_base_name=PhysicalConnectivity
fabric_version=0.4.1+build.245-1.14
fabric_kotlin_version=1.3.50+build.3
fabric_version=0.30.0+1.16
fabric_kotlin_version=1.4.30+build.2
libblockattributes_version=0.5.0
libblockattributes_version=0.8.5

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,17 +1,9 @@
package net.shadowfacts.phycon
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.container.ContainerFactory
import net.fabricmc.fabric.api.container.ContainerProviderRegistry
import net.minecraft.container.Container
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.Identifier
import net.minecraft.util.PacketByteBuf
import net.shadowfacts.phycon.init.PhyBlockEntities
import net.shadowfacts.phycon.init.PhyBlocks
import net.shadowfacts.phycon.init.PhyItems
import net.shadowfacts.phycon.network.block.terminal.TerminalBlock
import net.shadowfacts.phycon.network.block.terminal.TerminalContainer
/**
* @author shadowfacts
@ -24,13 +16,6 @@ object PhysicalConnectivity: ModInitializer {
PhyBlocks.init()
PhyBlockEntities.init()
PhyItems.init()
ContainerProviderRegistry.INSTANCE.registerFactory(TerminalContainer.ID, ContainerFactory(::createTerminalContainer))
}
private fun createTerminalContainer(syncId: Int, identifier: Identifier, player: PlayerEntity, buf: PacketByteBuf): Container {
val pos = buf.readBlockPos()
val terminalEntity = PhyBlocks.TERMINAL.getBlockEntity(player.world, pos)!!
return TerminalContainer(syncId, player.inventory, terminalEntity)
}
}

View File

@ -1,11 +1,11 @@
package net.shadowfacts.phycon
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.screen.ContainerScreenFactory
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry
import net.minecraft.client.MinecraftClient
import net.minecraft.util.Identifier
import net.shadowfacts.phycon.network.block.terminal.TerminalContainer
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry
import net.minecraft.client.render.RenderLayer
import net.shadowfacts.phycon.init.PhyBlocks
import net.shadowfacts.phycon.init.PhyScreens
import net.shadowfacts.phycon.network.block.terminal.TerminalScreen
/**
@ -13,10 +13,8 @@ import net.shadowfacts.phycon.network.block.terminal.TerminalScreen
*/
object PhysicalConnectivityClient: ClientModInitializer {
override fun onInitializeClient() {
ScreenProviderRegistry.INSTANCE.registerFactory(TerminalContainer.ID, ContainerScreenFactory(::createTerminalScreen))
}
BlockRenderLayerMap.INSTANCE.putBlock(PhyBlocks.CABLE, RenderLayer.getTranslucent())
fun createTerminalScreen(container: TerminalContainer): TerminalScreen {
return TerminalScreen(container, MinecraftClient.getInstance().player.inventory)
ScreenRegistry.register(PhyScreens.TERMINAL_SCREEN_HANDLER, ::TerminalScreen)
}
}

View File

@ -32,7 +32,7 @@ object PhyBlockEntities {
}
private fun register(id: Identifier, type: BlockEntityType<*>) {
Registry.register(Registry.BLOCK_ENTITY, id, type)
Registry.register(Registry.BLOCK_ENTITY_TYPE, id, type)
}
}

View File

@ -0,0 +1,12 @@
package net.shadowfacts.phycon.init
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry
import net.minecraft.util.Identifier
import net.shadowfacts.phycon.PhysicalConnectivity
import net.shadowfacts.phycon.network.block.terminal.TerminalScreenHandler
object PhyScreens {
val TERMINAL_SCREEN_HANDLER = ScreenHandlerRegistry.registerExtended(Identifier(PhysicalConnectivity.MODID, "terminal"), ::TerminalScreenHandler)
}

View File

@ -1,5 +1,6 @@
package net.shadowfacts.phycon.network
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.nbt.CompoundTag
@ -73,8 +74,8 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), P
return super.toTag(tag)
}
override fun fromTag(tag: CompoundTag) {
super.fromTag(tag)
override fun fromTag(state: BlockState, tag: CompoundTag) {
super.fromTag(state, tag)
macAddress = MACAddress(tag.getLong("MACAddress"))
}

View File

@ -1,14 +1,12 @@
package net.shadowfacts.phycon.network.block.cable
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.block.*
import net.minecraft.block.piston.PistonBehavior
import net.minecraft.entity.EntityContext
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemPlacementContext
import net.minecraft.state.StateFactory
import net.minecraft.state.StateManager
import net.minecraft.state.property.EnumProperty
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.Identifier
import net.minecraft.util.hit.BlockHitResult
@ -18,8 +16,8 @@ import net.minecraft.util.math.Vec3d
import net.minecraft.util.shape.VoxelShape
import net.minecraft.util.shape.VoxelShapes
import net.minecraft.world.BlockView
import net.minecraft.world.IWorld
import net.minecraft.world.World
import net.minecraft.world.WorldAccess
import net.shadowfacts.phycon.PhysicalConnectivity
import net.shadowfacts.phycon.api.NetworkCable
import net.shadowfacts.phycon.api.NetworkComponent
@ -30,10 +28,13 @@ import java.util.*
/**
* @author shadowfacts
*/
class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
class CableBlock: Block(
Settings.of(CABLE_MATERIAL)
.nonOpaque()
), NetworkCable {
companion object {
val ID = Identifier(PhysicalConnectivity.MODID, "cable")
val CABLE_MATERIAL = Material(MaterialColor.IRON, false, false, true, false, true, false, false, PistonBehavior.NORMAL)
val CABLE_MATERIAL = Material(MaterialColor.IRON, false, false, true, false, true, false, PistonBehavior.NORMAL)
val CENTER_SHAPE = createCuboidShape(6.0, 6.0, 6.0, 10.0, 10.0, 10.0)
val SIDE_SHAPES = mapOf<Direction, VoxelShape>(
Direction.DOWN to createCuboidShape(6.0, 0.0, 6.0, 10.0, 6.0, 10.0),
@ -60,7 +61,7 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
}
init {
defaultState = CONNECTIONS.values.fold(stateFactory.defaultState) { acc, prop ->
defaultState = CONNECTIONS.values.fold(stateManager.defaultState) { acc, prop ->
acc.with(prop, CableConnection.OFF)
}
}
@ -75,7 +76,7 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
return set
}
override fun appendProperties(builder: StateFactory.Builder<Block, BlockState>) {
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
super.appendProperties(builder)
CONNECTIONS.values.forEach {
builder.add(it)
@ -88,7 +89,7 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
})
}
override fun getStateForNeighborUpdate(state: BlockState, side: Direction, neighborState: BlockState, world: IWorld, blockPos_1: BlockPos, blockPos_2: BlockPos): BlockState {
override fun getStateForNeighborUpdate(state: BlockState, side: Direction, neighborState: BlockState, world: WorldAccess, blockPos_1: BlockPos, blockPos_2: BlockPos): BlockState {
val prop = CONNECTIONS[side]
val current = state[prop]
return when (current) {
@ -97,7 +98,7 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
}
}
private fun getConnectionStateInDirection(world: IWorld, pos: BlockPos, direction: Direction): CableConnection {
private fun getConnectionStateInDirection(world: WorldAccess, pos: BlockPos, direction: Direction): CableConnection {
val state = world.getBlockState(pos.offset(direction))
return when (state.block) {
this -> {
@ -112,7 +113,14 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
}
}
override fun activate(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult): Boolean {
override fun onUse(
state: BlockState,
world: World,
pos: BlockPos,
player: PlayerEntity,
hand: Hand,
hitResult: BlockHitResult
): ActionResult {
if (player.getStackInHand(hand).item == PhyItems.SCREWDRIVER) {
val hitPos = Vec3d(hitResult.pos.x - pos.x, hitResult.pos.y - pos.y, hitResult.pos.z - pos.z)
val hitConnection = SIDE_SHAPES.entries.firstOrNull { (_, shape) ->
@ -139,29 +147,20 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
}
world.setBlockState(pos, newState)
}
return true
return ActionResult.SUCCESS
}
return false
}
@Environment(EnvType.CLIENT)
override fun getRenderLayer(): BlockRenderLayer {
return BlockRenderLayer.TRANSLUCENT
}
override fun isOpaque(blockState_1: BlockState?): Boolean {
return false
return ActionResult.PASS
}
override fun isTranslucent(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
return true
}
override fun isSimpleFullBlock(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
return false
}
// override fun isSimpleFullBlock(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
// return false
// }
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: EntityContext): VoxelShape {
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: ShapeContext): VoxelShape {
return getShape(state)
}

View File

@ -5,11 +5,11 @@ import alexiil.mc.lib.attributes.AttributeProvider
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.Material
import net.minecraft.entity.EntityContext
import net.minecraft.block.ShapeContext
import net.minecraft.entity.LivingEntity
import net.minecraft.item.ItemPlacementContext
import net.minecraft.item.ItemStack
import net.minecraft.state.StateFactory
import net.minecraft.state.StateManager
import net.minecraft.state.property.EnumProperty
import net.minecraft.state.property.Properties
import net.minecraft.util.Identifier
@ -18,13 +18,12 @@ import net.minecraft.util.math.Direction
import net.minecraft.util.shape.VoxelShape
import net.minecraft.util.shape.VoxelShapes
import net.minecraft.world.BlockView
import net.minecraft.world.IWorld
import net.minecraft.world.World
import net.minecraft.world.WorldAccess
import net.shadowfacts.phycon.PhysicalConnectivity
import net.shadowfacts.phycon.api.NetworkComponent
import net.shadowfacts.phycon.block.BlockWithEntity
import net.shadowfacts.phycon.network.block.cable.CableBlock
import java.net.NoRouteToHostException
import java.util.*
/**
@ -67,7 +66,7 @@ class InterfaceBlock: BlockWithEntity<InterfaceBlockEntity>(Settings.of(Material
return EnumSet.of(state[CABLE_CONNECTION])
}
override fun appendProperties(builder: StateFactory.Builder<Block, BlockState>) {
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
super.appendProperties(builder)
builder.add(FACING)
builder.add(CABLE_CONNECTION)
@ -103,7 +102,7 @@ class InterfaceBlock: BlockWithEntity<InterfaceBlockEntity>(Settings.of(Material
}
}
override fun getStateForNeighborUpdate(state: BlockState, side: Direction, neighborState: BlockState, world: IWorld, pos: BlockPos, neighborPos: BlockPos): BlockState {
override fun getStateForNeighborUpdate(state: BlockState, side: Direction, neighborState: BlockState, world: WorldAccess, pos: BlockPos, neighborPos: BlockPos): BlockState {
if (neighborState.block is NetworkComponent && world.getBlockState(pos.offset(state[CABLE_CONNECTION])).block !is NetworkComponent) {
return state.with(CABLE_CONNECTION, side)
}
@ -114,7 +113,7 @@ class InterfaceBlock: BlockWithEntity<InterfaceBlockEntity>(Settings.of(Material
to.offer(getBlockEntity(world, pos))
}
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: EntityContext): VoxelShape {
override fun getOutlineShape(state: BlockState, world: BlockView, pos: BlockPos, context: ShapeContext): VoxelShape {
return getShape(state[FACING], state[CABLE_CONNECTION])
}

View File

@ -5,6 +5,7 @@ import alexiil.mc.lib.attributes.AttributeProvider
import net.minecraft.block.BlockState
import net.minecraft.block.Material
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.Identifier
import net.minecraft.util.hit.BlockHitResult
@ -31,9 +32,9 @@ class TerminalBlock: BlockWithEntity<TerminalBlockEntity>(Settings.of(Material.M
override fun createBlockEntity(world: BlockView) = TerminalBlockEntity()
override fun activate(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult): Boolean {
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hitResult: BlockHitResult): ActionResult {
getBlockEntity(world, pos)!!.onActivate(player)
return true
return ActionResult.SUCCESS
}
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {

View File

@ -4,15 +4,20 @@ import alexiil.mc.lib.attributes.item.GroupedItemInv
import alexiil.mc.lib.attributes.item.ItemStackCollections
import alexiil.mc.lib.attributes.item.ItemStackUtil
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
import net.fabricmc.fabric.api.container.ContainerProviderRegistry
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
import net.minecraft.block.BlockState
import net.minecraft.entity.ItemEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.BasicInventory
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.inventory.Inventory
import net.minecraft.inventory.InventoryListener
import net.minecraft.inventory.InventoryChangedListener
import net.minecraft.item.ItemStack
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
import net.minecraft.network.PacketByteBuf
import net.minecraft.screen.ScreenHandler
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.text.LiteralText
import net.minecraft.util.Tickable
import net.shadowfacts.phycon.api.packet.Packet
import net.shadowfacts.phycon.api.util.MACAddress
@ -21,7 +26,6 @@ import net.shadowfacts.phycon.network.DeviceBlockEntity
import net.shadowfacts.phycon.network.block.netinterface.InterfaceBlockEntity
import net.shadowfacts.phycon.network.packet.*
import net.shadowfacts.phycon.util.fromTag
import net.shadowfacts.phycon.util.insert
import net.shadowfacts.phycon.util.toTag
import java.util.*
import kotlin.math.min
@ -29,7 +33,7 @@ import kotlin.math.min
/**
* @author shadowfacts
*/
class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), InventoryListener, BlockEntityClientSerializable, Tickable {
class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), InventoryChangedListener, BlockEntityClientSerializable, Tickable {
companion object {
val LOCATE_REQUEST_TIMEOUT = 40 // ticks
@ -134,9 +138,18 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
inventoryCache.clear()
sendToSingle(RequestInventoryPacket(macAddress))
ContainerProviderRegistry.INSTANCE.openContainer(TerminalContainer.ID, player) { buf ->
buf.writeBlockPos(pos)
val factory = object: ExtendedScreenHandlerFactory {
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler? {
return TerminalScreenHandler(syncId, playerInv, this@TerminalBlockEntity)
}
override fun getDisplayName() = LiteralText("Terminal")
override fun writeScreenOpeningData(player: ServerPlayerEntity, buf: PacketByteBuf) {
buf.writeBlockPos(this@TerminalBlockEntity.pos)
}
}
player.openHandledScreen(factory)
}
addObserver()
}
@ -158,7 +171,7 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
}
}
override fun onInvChange(inv: Inventory) {
override fun onInventoryChanged(inv: Inventory) {
if (inv == internalBuffer && world != null && !world!!.isClient) {
markDirty()
sync()
@ -170,8 +183,8 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
return super.toTag(tag)
}
override fun fromTag(tag: CompoundTag) {
super.fromTag(tag)
override fun fromTag(state: BlockState, tag: CompoundTag) {
super.fromTag(state, tag)
internalBuffer.fromTag(tag.getList("InternalBuffer", 10))
}

View File

@ -1,14 +1,14 @@
package net.shadowfacts.phycon.network.block.terminal
import alexiil.mc.lib.attributes.item.ItemStackUtil
import net.minecraft.inventory.BasicInventory
import net.minecraft.inventory.SimpleInventory
import net.minecraft.item.ItemStack
import kotlin.math.min
/**
* @author shadowfacts
*/
class TerminalBufferInventory(size: Int): BasicInventory(size) {
class TerminalBufferInventory(size: Int): SimpleInventory(size) {
enum class Mode {
TO_NETWORK, FROM_NETWORK, UNASSIGNED
@ -18,7 +18,7 @@ class TerminalBufferInventory(size: Int): BasicInventory(size) {
fun insertFromNetwork(stack: ItemStack): ItemStack {
var remaining = stack.copy()
for (slot in 0 until invSize) {
for (slot in 0 until size()) {
if (modes[slot] == Mode.TO_NETWORK) continue
remaining = insertFromNetwork(stack, slot)
@ -33,9 +33,9 @@ class TerminalBufferInventory(size: Int): BasicInventory(size) {
private fun insertFromNetwork(stack: ItemStack, slot: Int): ItemStack {
val mode = modes[slot]
if (mode == Mode.TO_NETWORK) return stack
val current = getInvStack(slot)
val current = getStack(slot)
if (current.isEmpty) {
setInvStack(slot, stack)
setStack(slot, stack)
modes[slot] = Mode.FROM_NETWORK
return ItemStack.EMPTY
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
@ -49,11 +49,11 @@ class TerminalBufferInventory(size: Int): BasicInventory(size) {
}
}
override fun setInvStack(slot: Int, stack: ItemStack) {
override fun setStack(slot: Int, stack: ItemStack) {
if (stack.isEmpty) {
modes[slot] = Mode.UNASSIGNED
}
super.setInvStack(slot, stack)
super.setStack(slot, stack)
}
}

View File

@ -1,6 +1,6 @@
package net.shadowfacts.phycon.network.block.terminal
import net.minecraft.container.Slot
import net.minecraft.screen.slot.Slot
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
@ -24,7 +24,7 @@ class TerminalFakeSlot(val terminal: TerminalBlockEntity, slot: Int, x: Int, y:
}
class FakeInventory(val terminal: TerminalBlockEntity, val slot: Int): Inventory {
override fun getInvStack(_slot: Int): ItemStack {
override fun getStack(_slot: Int): ItemStack {
if (slot >= terminal.cachedSortedNetItems.size) return ItemStack.EMPTY
return terminal.cachedSortedNetItems[slot]
}
@ -35,26 +35,26 @@ class FakeInventory(val terminal: TerminalBlockEntity, val slot: Int): Inventory
override fun clear() {
}
override fun setInvStack(p0: Int, p1: ItemStack?) {
override fun setStack(p0: Int, p1: ItemStack?) {
}
override fun removeInvStack(p0: Int): ItemStack {
override fun removeStack(p0: Int): ItemStack {
return ItemStack.EMPTY
}
override fun canPlayerUseInv(p0: PlayerEntity?): Boolean {
override fun canPlayerUse(p0: PlayerEntity?): Boolean {
return false
}
override fun getInvSize(): Int {
override fun size(): Int {
return 1
}
override fun takeInvStack(p0: Int, p1: Int): ItemStack {
override fun removeStack(p0: Int, p1: Int): ItemStack {
return ItemStack.EMPTY
}
override fun isInvEmpty(): Boolean {
override fun isEmpty(): Boolean {
return false
}

View File

@ -1,9 +1,11 @@
package net.shadowfacts.phycon.network.block.terminal
import com.mojang.blaze3d.platform.GlStateManager
import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.text.LiteralText
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import net.shadowfacts.phycon.PhysicalConnectivity
@ -11,30 +13,29 @@ import net.shadowfacts.phycon.PhysicalConnectivity
* @author shadowfacts
*/
// todo: translate title
class TerminalScreen(container: TerminalContainer, playerInv: PlayerInventory): AbstractContainerScreen<TerminalContainer>(container, playerInv, LiteralText("Terminal")) {
class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory, title: Text): HandledScreen<TerminalScreenHandler>(handler, playerInv, title) {
companion object {
val BACKGROUND = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png")
}
init {
containerWidth = 252
containerHeight = 222
backgroundWidth = 252
backgroundHeight = 222
}
override fun drawForeground(mouseX: Int, mouseY: Int) {
font.draw(title.asFormattedString(), 65f, 6f, 0x404040)
font.draw(playerInventory.displayName.asFormattedString(), 65f, containerHeight - 94f, 0x404040)
override fun drawForeground(matrixStack: MatrixStack, mouseX: Int, mouseY: Int) {
textRenderer.draw(matrixStack, title, 65f, 6f, 0x404040)
textRenderer.draw(matrixStack, playerInventory.displayName, 65f, backgroundHeight - 94f, 0x404040)
// todo: translate this
font.draw("Buffer", 7f, 6f, 0x404040)
textRenderer.draw(matrixStack, "Buffer", 7f, 6f, 0x404040)
}
override fun drawBackground(delta: Float, mouseX: Int, mouseY: Int) {
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
GlStateManager.color4f(1f, 1f, 1f, 1f)
minecraft!!.textureManager.bindTexture(BACKGROUND)
val x = (width - containerWidth) / 2
val y = (height - containerHeight) / 2
blit(x, y, 0, 0, containerWidth, containerHeight)
client!!.textureManager.bindTexture(BACKGROUND)
val x = (width - backgroundWidth) / 2
val y = (height - backgroundHeight) / 2
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
}
}

View File

@ -1,25 +1,31 @@
package net.shadowfacts.phycon.network.block.terminal
import net.minecraft.container.Container
import net.minecraft.container.Slot
import net.minecraft.container.SlotActionType
import net.minecraft.screen.slot.Slot
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.item.ItemStack
import net.minecraft.network.PacketByteBuf
import net.minecraft.screen.ScreenHandler
import net.minecraft.util.Identifier
import net.shadowfacts.phycon.PhysicalConnectivity
import net.shadowfacts.phycon.init.PhyBlocks
import net.shadowfacts.phycon.init.PhyScreens
import kotlin.math.ceil
import kotlin.math.min
/**
* @author shadowfacts
*/
class TerminalContainer(syncId: Int, playerInv: PlayerInventory, val terminal: TerminalBlockEntity): Container(null, syncId) {
class TerminalScreenHandler(syncId: Int, playerInv: PlayerInventory, val terminal: TerminalBlockEntity): ScreenHandler(PhyScreens.TERMINAL_SCREEN_HANDLER, syncId) {
companion object {
val ID = Identifier(PhysicalConnectivity.MODID, "terminal")
}
constructor(syncId: Int, playerInv: PlayerInventory, buf: PacketByteBuf):
this(syncId, playerInv, PhyBlocks.TERMINAL.getBlockEntity(playerInv.player.world, buf.readBlockPos())!!)
init {
// network
for (y in 0 until 6) {
@ -61,14 +67,14 @@ class TerminalContainer(syncId: Int, playerInv: PlayerInventory, val terminal: T
if (slotId in 0 until 54) {
// the slot clicked was one of the network stacks
if (actionType == SlotActionType.QUICK_MOVE) {
val stack = slotList[slotId].stack
val stack = slots[slotId].stack
if (!stack.isEmpty && !player.world.isClient) {
terminal.requestItem(stack, min(stack.count, stack.maxCount))
}
} else if (actionType == SlotActionType.PICKUP && clickData == 1) {
if (clickData == 1) {
// right click, request half stack
val stack = slotList[slotId].stack
val stack = slots[slotId].stack
if (!stack.isEmpty && !player.world.isClient) {
terminal.requestItem(stack, ceil(min(stack.count, stack.maxCount) / 2f).toInt())
}

View File

@ -1,7 +1,7 @@
package net.shadowfacts.phycon.util
import alexiil.mc.lib.attributes.item.ItemStackUtil
import net.minecraft.inventory.BasicInventory
import net.minecraft.inventory.SimpleInventory
import net.minecraft.item.ItemStack
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
@ -11,10 +11,10 @@ import kotlin.math.min
/**
* @author shadowfacts
*/
fun BasicInventory.toTag(): ListTag {
fun SimpleInventory.toTag(): ListTag {
val list = ListTag()
for (slot in 0 until invSize) {
val stack = getInvStack(slot)
for (slot in 0 until size()) {
val stack = getStack(slot)
if (!stack.isEmpty) {
val stackTag = stack.toTag(CompoundTag())
stackTag.putInt("Slot", slot)
@ -24,22 +24,22 @@ fun BasicInventory.toTag(): ListTag {
return list
}
fun BasicInventory.fromTag(list: ListTag) {
if (list.listType != 10) throw RuntimeException("Can't decode BasicInventory from list tag that does not contain compound tags")
fun SimpleInventory.fromTag(list: ListTag) {
if (list.elementType != 10.toByte()) throw RuntimeException("Can't decode BasicInventory from list tag that does not contain compound tags")
this.clear()
for (tag in list) {
val compound = tag as CompoundTag
val stack = ItemStack.fromTag(compound)
val slot = compound.getInt("Slot")
setInvStack(slot, stack)
setStack(slot, stack)
}
}
fun BasicInventory.insert(stack: ItemStack, slot: Int): ItemStack {
fun SimpleInventory.insert(stack: ItemStack, slot: Int): ItemStack {
@Suppress("NAME_SHADOWING") val stack = stack.copy()
val current = getInvStack(slot)
val current = getStack(slot)
if (current.isEmpty) {
setInvStack(slot, stack)
setStack(slot, stack)
return ItemStack.EMPTY
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
val toTransfer = min(current.maxCount - current.count, stack.count)
@ -51,9 +51,9 @@ fun BasicInventory.insert(stack: ItemStack, slot: Int): ItemStack {
}
}
fun BasicInventory.insert(stack: ItemStack): ItemStack {
fun SimpleInventory.insert(stack: ItemStack): ItemStack {
var remaining = stack
for (slot in 0 until invSize) {
for (slot in 0 until size()) {
remaining = insert(stack, slot)
if (remaining.isEmpty) {
break