Update to 1.16.5
This commit is contained in:
parent
8a20837f11
commit
b1c37595ab
26
build.gradle
26
build.gradle
|
@ -1,7 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "fabric-loom" version "0.2.5-SNAPSHOT"
|
id "fabric-loom" version "0.5-SNAPSHOT"
|
||||||
id "maven-publish"
|
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
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
@ -40,14 +40,9 @@ dependencies {
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
filesMatching("fabric.mod.json") {
|
||||||
include "fabric.mod.json"
|
|
||||||
expand "version": project.version
|
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
|
// 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"
|
options.encoding = "UTF-8"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
java {
|
||||||
// if it is present.
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
// If you remove this task, sources will not be generated.
|
// if it is present.
|
||||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
// If you remove this line, sources will not be generated.
|
||||||
classifier = "sources"
|
withSourcesJar()
|
||||||
from sourceSets.main.allSource
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from "LICENSE"
|
from("LICENSE") {
|
||||||
|
rename { "${it}_${project.archivesBaseName}" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx1G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
minecraft_version=1.14.4
|
minecraft_version=1.16.5
|
||||||
yarn_mappings=1.14.4+build.14
|
yarn_mappings=1.16.5+build.4
|
||||||
loader_version=0.6.3+build.167
|
loader_version=0.11.1
|
||||||
|
|
||||||
mod_version=0.1.0
|
mod_version=0.1.0
|
||||||
maven_group=net.shadowfacts
|
maven_group=net.shadowfacts
|
||||||
archives_base_name=PhysicalConnectivity
|
archives_base_name=PhysicalConnectivity
|
||||||
|
|
||||||
fabric_version=0.4.1+build.245-1.14
|
fabric_version=0.30.0+1.16
|
||||||
fabric_kotlin_version=1.3.50+build.3
|
fabric_kotlin_version=1.4.30+build.2
|
||||||
|
|
||||||
libblockattributes_version=0.5.0
|
libblockattributes_version=0.8.5
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
package net.shadowfacts.phycon
|
package net.shadowfacts.phycon
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer
|
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.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.init.PhyBlocks
|
import net.shadowfacts.phycon.init.PhyBlocks
|
||||||
import net.shadowfacts.phycon.init.PhyItems
|
import net.shadowfacts.phycon.init.PhyItems
|
||||||
import net.shadowfacts.phycon.network.block.terminal.TerminalBlock
|
|
||||||
import net.shadowfacts.phycon.network.block.terminal.TerminalContainer
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -24,13 +16,6 @@ object PhysicalConnectivity: ModInitializer {
|
||||||
PhyBlocks.init()
|
PhyBlocks.init()
|
||||||
PhyBlockEntities.init()
|
PhyBlockEntities.init()
|
||||||
PhyItems.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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package net.shadowfacts.phycon
|
package net.shadowfacts.phycon
|
||||||
|
|
||||||
import net.fabricmc.api.ClientModInitializer
|
import net.fabricmc.api.ClientModInitializer
|
||||||
import net.fabricmc.fabric.api.client.screen.ContainerScreenFactory
|
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap
|
||||||
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry
|
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.render.RenderLayer
|
||||||
import net.minecraft.util.Identifier
|
import net.shadowfacts.phycon.init.PhyBlocks
|
||||||
import net.shadowfacts.phycon.network.block.terminal.TerminalContainer
|
import net.shadowfacts.phycon.init.PhyScreens
|
||||||
import net.shadowfacts.phycon.network.block.terminal.TerminalScreen
|
import net.shadowfacts.phycon.network.block.terminal.TerminalScreen
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,10 +13,8 @@ import net.shadowfacts.phycon.network.block.terminal.TerminalScreen
|
||||||
*/
|
*/
|
||||||
object PhysicalConnectivityClient: ClientModInitializer {
|
object PhysicalConnectivityClient: ClientModInitializer {
|
||||||
override fun onInitializeClient() {
|
override fun onInitializeClient() {
|
||||||
ScreenProviderRegistry.INSTANCE.registerFactory(TerminalContainer.ID, ContainerScreenFactory(::createTerminalScreen))
|
BlockRenderLayerMap.INSTANCE.putBlock(PhyBlocks.CABLE, RenderLayer.getTranslucent())
|
||||||
}
|
|
||||||
|
|
||||||
fun createTerminalScreen(container: TerminalContainer): TerminalScreen {
|
ScreenRegistry.register(PhyScreens.TERMINAL_SCREEN_HANDLER, ::TerminalScreen)
|
||||||
return TerminalScreen(container, MinecraftClient.getInstance().player.inventory)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ object PhyBlockEntities {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(id: Identifier, type: BlockEntityType<*>) {
|
private fun register(id: Identifier, type: BlockEntityType<*>) {
|
||||||
Registry.register(Registry.BLOCK_ENTITY, id, type)
|
Registry.register(Registry.BLOCK_ENTITY_TYPE, id, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package net.shadowfacts.phycon.network
|
package net.shadowfacts.phycon.network
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
import net.minecraft.block.entity.BlockEntityType
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
|
@ -73,8 +74,8 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), P
|
||||||
return super.toTag(tag)
|
return super.toTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromTag(tag: CompoundTag) {
|
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||||
super.fromTag(tag)
|
super.fromTag(state, tag)
|
||||||
macAddress = MACAddress(tag.getLong("MACAddress"))
|
macAddress = MACAddress(tag.getLong("MACAddress"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package net.shadowfacts.phycon.network.block.cable
|
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.*
|
||||||
import net.minecraft.block.piston.PistonBehavior
|
import net.minecraft.block.piston.PistonBehavior
|
||||||
import net.minecraft.entity.EntityContext
|
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
import net.minecraft.item.ItemPlacementContext
|
import net.minecraft.item.ItemPlacementContext
|
||||||
import net.minecraft.state.StateFactory
|
import net.minecraft.state.StateManager
|
||||||
import net.minecraft.state.property.EnumProperty
|
import net.minecraft.state.property.EnumProperty
|
||||||
|
import net.minecraft.util.ActionResult
|
||||||
import net.minecraft.util.Hand
|
import net.minecraft.util.Hand
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.hit.BlockHitResult
|
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.VoxelShape
|
||||||
import net.minecraft.util.shape.VoxelShapes
|
import net.minecraft.util.shape.VoxelShapes
|
||||||
import net.minecraft.world.BlockView
|
import net.minecraft.world.BlockView
|
||||||
import net.minecraft.world.IWorld
|
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
|
import net.minecraft.world.WorldAccess
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
import net.shadowfacts.phycon.api.NetworkCable
|
import net.shadowfacts.phycon.api.NetworkCable
|
||||||
import net.shadowfacts.phycon.api.NetworkComponent
|
import net.shadowfacts.phycon.api.NetworkComponent
|
||||||
|
@ -30,10 +28,13 @@ import java.util.*
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
|
class CableBlock: Block(
|
||||||
|
Settings.of(CABLE_MATERIAL)
|
||||||
|
.nonOpaque()
|
||||||
|
), NetworkCable {
|
||||||
companion object {
|
companion object {
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "cable")
|
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 CENTER_SHAPE = createCuboidShape(6.0, 6.0, 6.0, 10.0, 10.0, 10.0)
|
||||||
val SIDE_SHAPES = mapOf<Direction, VoxelShape>(
|
val SIDE_SHAPES = mapOf<Direction, VoxelShape>(
|
||||||
Direction.DOWN to createCuboidShape(6.0, 0.0, 6.0, 10.0, 6.0, 10.0),
|
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 {
|
init {
|
||||||
defaultState = CONNECTIONS.values.fold(stateFactory.defaultState) { acc, prop ->
|
defaultState = CONNECTIONS.values.fold(stateManager.defaultState) { acc, prop ->
|
||||||
acc.with(prop, CableConnection.OFF)
|
acc.with(prop, CableConnection.OFF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +76,7 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
|
||||||
return set
|
return set
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun appendProperties(builder: StateFactory.Builder<Block, BlockState>) {
|
override fun appendProperties(builder: StateManager.Builder<Block, BlockState>) {
|
||||||
super.appendProperties(builder)
|
super.appendProperties(builder)
|
||||||
CONNECTIONS.values.forEach {
|
CONNECTIONS.values.forEach {
|
||||||
builder.add(it)
|
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 prop = CONNECTIONS[side]
|
||||||
val current = state[prop]
|
val current = state[prop]
|
||||||
return when (current) {
|
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))
|
val state = world.getBlockState(pos.offset(direction))
|
||||||
return when (state.block) {
|
return when (state.block) {
|
||||||
this -> {
|
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) {
|
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 hitPos = Vec3d(hitResult.pos.x - pos.x, hitResult.pos.y - pos.y, hitResult.pos.z - pos.z)
|
||||||
val hitConnection = SIDE_SHAPES.entries.firstOrNull { (_, shape) ->
|
val hitConnection = SIDE_SHAPES.entries.firstOrNull { (_, shape) ->
|
||||||
|
@ -139,29 +147,20 @@ class CableBlock: Block(Settings.of(CABLE_MATERIAL)), NetworkCable {
|
||||||
}
|
}
|
||||||
world.setBlockState(pos, newState)
|
world.setBlockState(pos, newState)
|
||||||
}
|
}
|
||||||
return true
|
return ActionResult.SUCCESS
|
||||||
}
|
}
|
||||||
return false
|
return ActionResult.PASS
|
||||||
}
|
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
|
||||||
override fun getRenderLayer(): BlockRenderLayer {
|
|
||||||
return BlockRenderLayer.TRANSLUCENT
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isOpaque(blockState_1: BlockState?): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isTranslucent(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
|
override fun isTranslucent(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isSimpleFullBlock(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
|
// override fun isSimpleFullBlock(blockState_1: BlockState?, blockView_1: BlockView?, blockPos_1: BlockPos?): Boolean {
|
||||||
return false
|
// 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)
|
return getShape(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ import alexiil.mc.lib.attributes.AttributeProvider
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.Material
|
import net.minecraft.block.Material
|
||||||
import net.minecraft.entity.EntityContext
|
import net.minecraft.block.ShapeContext
|
||||||
import net.minecraft.entity.LivingEntity
|
import net.minecraft.entity.LivingEntity
|
||||||
import net.minecraft.item.ItemPlacementContext
|
import net.minecraft.item.ItemPlacementContext
|
||||||
import net.minecraft.item.ItemStack
|
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.EnumProperty
|
||||||
import net.minecraft.state.property.Properties
|
import net.minecraft.state.property.Properties
|
||||||
import net.minecraft.util.Identifier
|
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.VoxelShape
|
||||||
import net.minecraft.util.shape.VoxelShapes
|
import net.minecraft.util.shape.VoxelShapes
|
||||||
import net.minecraft.world.BlockView
|
import net.minecraft.world.BlockView
|
||||||
import net.minecraft.world.IWorld
|
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
|
import net.minecraft.world.WorldAccess
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
import net.shadowfacts.phycon.api.NetworkComponent
|
import net.shadowfacts.phycon.api.NetworkComponent
|
||||||
import net.shadowfacts.phycon.block.BlockWithEntity
|
import net.shadowfacts.phycon.block.BlockWithEntity
|
||||||
import net.shadowfacts.phycon.network.block.cable.CableBlock
|
import net.shadowfacts.phycon.network.block.cable.CableBlock
|
||||||
import java.net.NoRouteToHostException
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +66,7 @@ class InterfaceBlock: BlockWithEntity<InterfaceBlockEntity>(Settings.of(Material
|
||||||
return EnumSet.of(state[CABLE_CONNECTION])
|
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)
|
super.appendProperties(builder)
|
||||||
builder.add(FACING)
|
builder.add(FACING)
|
||||||
builder.add(CABLE_CONNECTION)
|
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) {
|
if (neighborState.block is NetworkComponent && world.getBlockState(pos.offset(state[CABLE_CONNECTION])).block !is NetworkComponent) {
|
||||||
return state.with(CABLE_CONNECTION, side)
|
return state.with(CABLE_CONNECTION, side)
|
||||||
}
|
}
|
||||||
|
@ -114,7 +113,7 @@ class InterfaceBlock: BlockWithEntity<InterfaceBlockEntity>(Settings.of(Material
|
||||||
to.offer(getBlockEntity(world, pos))
|
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])
|
return getShape(state[FACING], state[CABLE_CONNECTION])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import alexiil.mc.lib.attributes.AttributeProvider
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.Material
|
import net.minecraft.block.Material
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
|
import net.minecraft.util.ActionResult
|
||||||
import net.minecraft.util.Hand
|
import net.minecraft.util.Hand
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.hit.BlockHitResult
|
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 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)
|
getBlockEntity(world, pos)!!.onActivate(player)
|
||||||
return true
|
return ActionResult.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
||||||
|
|
|
@ -4,15 +4,20 @@ import alexiil.mc.lib.attributes.item.GroupedItemInv
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
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.ItemEntity
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
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.Inventory
|
||||||
import net.minecraft.inventory.InventoryListener
|
import net.minecraft.inventory.InventoryChangedListener
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.ListTag
|
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.minecraft.util.Tickable
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
import net.shadowfacts.phycon.api.packet.Packet
|
||||||
import net.shadowfacts.phycon.api.util.MACAddress
|
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.block.netinterface.InterfaceBlockEntity
|
||||||
import net.shadowfacts.phycon.network.packet.*
|
import net.shadowfacts.phycon.network.packet.*
|
||||||
import net.shadowfacts.phycon.util.fromTag
|
import net.shadowfacts.phycon.util.fromTag
|
||||||
import net.shadowfacts.phycon.util.insert
|
|
||||||
import net.shadowfacts.phycon.util.toTag
|
import net.shadowfacts.phycon.util.toTag
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
@ -29,7 +33,7 @@ import kotlin.math.min
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), InventoryListener, BlockEntityClientSerializable, Tickable {
|
class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), InventoryChangedListener, BlockEntityClientSerializable, Tickable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val LOCATE_REQUEST_TIMEOUT = 40 // ticks
|
val LOCATE_REQUEST_TIMEOUT = 40 // ticks
|
||||||
|
@ -134,9 +138,18 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
|
||||||
|
|
||||||
inventoryCache.clear()
|
inventoryCache.clear()
|
||||||
sendToSingle(RequestInventoryPacket(macAddress))
|
sendToSingle(RequestInventoryPacket(macAddress))
|
||||||
ContainerProviderRegistry.INSTANCE.openContainer(TerminalContainer.ID, player) { buf ->
|
val factory = object: ExtendedScreenHandlerFactory {
|
||||||
buf.writeBlockPos(pos)
|
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()
|
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) {
|
if (inv == internalBuffer && world != null && !world!!.isClient) {
|
||||||
markDirty()
|
markDirty()
|
||||||
sync()
|
sync()
|
||||||
|
@ -170,8 +183,8 @@ class TerminalBlockEntity: DeviceBlockEntity(PhyBlockEntities.TERMINAL), Invento
|
||||||
return super.toTag(tag)
|
return super.toTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromTag(tag: CompoundTag) {
|
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||||
super.fromTag(tag)
|
super.fromTag(state, tag)
|
||||||
internalBuffer.fromTag(tag.getList("InternalBuffer", 10))
|
internalBuffer.fromTag(tag.getList("InternalBuffer", 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package net.shadowfacts.phycon.network.block.terminal
|
package net.shadowfacts.phycon.network.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
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.item.ItemStack
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class TerminalBufferInventory(size: Int): BasicInventory(size) {
|
class TerminalBufferInventory(size: Int): SimpleInventory(size) {
|
||||||
|
|
||||||
enum class Mode {
|
enum class Mode {
|
||||||
TO_NETWORK, FROM_NETWORK, UNASSIGNED
|
TO_NETWORK, FROM_NETWORK, UNASSIGNED
|
||||||
|
@ -18,7 +18,7 @@ class TerminalBufferInventory(size: Int): BasicInventory(size) {
|
||||||
|
|
||||||
fun insertFromNetwork(stack: ItemStack): ItemStack {
|
fun insertFromNetwork(stack: ItemStack): ItemStack {
|
||||||
var remaining = stack.copy()
|
var remaining = stack.copy()
|
||||||
for (slot in 0 until invSize) {
|
for (slot in 0 until size()) {
|
||||||
if (modes[slot] == Mode.TO_NETWORK) continue
|
if (modes[slot] == Mode.TO_NETWORK) continue
|
||||||
|
|
||||||
remaining = insertFromNetwork(stack, slot)
|
remaining = insertFromNetwork(stack, slot)
|
||||||
|
@ -33,9 +33,9 @@ class TerminalBufferInventory(size: Int): BasicInventory(size) {
|
||||||
private fun insertFromNetwork(stack: ItemStack, slot: Int): ItemStack {
|
private fun insertFromNetwork(stack: ItemStack, slot: Int): ItemStack {
|
||||||
val mode = modes[slot]
|
val mode = modes[slot]
|
||||||
if (mode == Mode.TO_NETWORK) return stack
|
if (mode == Mode.TO_NETWORK) return stack
|
||||||
val current = getInvStack(slot)
|
val current = getStack(slot)
|
||||||
if (current.isEmpty) {
|
if (current.isEmpty) {
|
||||||
setInvStack(slot, stack)
|
setStack(slot, stack)
|
||||||
modes[slot] = Mode.FROM_NETWORK
|
modes[slot] = Mode.FROM_NETWORK
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
|
} 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) {
|
if (stack.isEmpty) {
|
||||||
modes[slot] = Mode.UNASSIGNED
|
modes[slot] = Mode.UNASSIGNED
|
||||||
}
|
}
|
||||||
super.setInvStack(slot, stack)
|
super.setStack(slot, stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.shadowfacts.phycon.network.block.terminal
|
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.entity.player.PlayerEntity
|
||||||
import net.minecraft.inventory.Inventory
|
import net.minecraft.inventory.Inventory
|
||||||
import net.minecraft.item.ItemStack
|
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 {
|
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
|
if (slot >= terminal.cachedSortedNetItems.size) return ItemStack.EMPTY
|
||||||
return terminal.cachedSortedNetItems[slot]
|
return terminal.cachedSortedNetItems[slot]
|
||||||
}
|
}
|
||||||
|
@ -35,26 +35,26 @@ class FakeInventory(val terminal: TerminalBlockEntity, val slot: Int): Inventory
|
||||||
override fun clear() {
|
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
|
return ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun canPlayerUseInv(p0: PlayerEntity?): Boolean {
|
override fun canPlayerUse(p0: PlayerEntity?): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getInvSize(): Int {
|
override fun size(): Int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun takeInvStack(p0: Int, p1: Int): ItemStack {
|
override fun removeStack(p0: Int, p1: Int): ItemStack {
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isInvEmpty(): Boolean {
|
override fun isEmpty(): Boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package net.shadowfacts.phycon.network.block.terminal
|
package net.shadowfacts.phycon.network.block.terminal
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager
|
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.entity.player.PlayerInventory
|
||||||
import net.minecraft.text.LiteralText
|
import net.minecraft.text.LiteralText
|
||||||
|
import net.minecraft.text.Text
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
|
|
||||||
|
@ -11,30 +13,29 @@ import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
// todo: translate title
|
// 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 {
|
companion object {
|
||||||
val BACKGROUND = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png")
|
val BACKGROUND = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png")
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
containerWidth = 252
|
backgroundWidth = 252
|
||||||
containerHeight = 222
|
backgroundHeight = 222
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawForeground(mouseX: Int, mouseY: Int) {
|
override fun drawForeground(matrixStack: MatrixStack, mouseX: Int, mouseY: Int) {
|
||||||
font.draw(title.asFormattedString(), 65f, 6f, 0x404040)
|
textRenderer.draw(matrixStack, title, 65f, 6f, 0x404040)
|
||||||
font.draw(playerInventory.displayName.asFormattedString(), 65f, containerHeight - 94f, 0x404040)
|
textRenderer.draw(matrixStack, playerInventory.displayName, 65f, backgroundHeight - 94f, 0x404040)
|
||||||
// todo: translate this
|
// 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)
|
GlStateManager.color4f(1f, 1f, 1f, 1f)
|
||||||
minecraft!!.textureManager.bindTexture(BACKGROUND)
|
client!!.textureManager.bindTexture(BACKGROUND)
|
||||||
val x = (width - containerWidth) / 2
|
val x = (width - backgroundWidth) / 2
|
||||||
val y = (height - containerHeight) / 2
|
val y = (height - backgroundHeight) / 2
|
||||||
blit(x, y, 0, 0, containerWidth, containerHeight)
|
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,31 @@
|
||||||
package net.shadowfacts.phycon.network.block.terminal
|
package net.shadowfacts.phycon.network.block.terminal
|
||||||
|
|
||||||
import net.minecraft.container.Container
|
import net.minecraft.screen.slot.Slot
|
||||||
import net.minecraft.container.Slot
|
import net.minecraft.screen.slot.SlotActionType
|
||||||
import net.minecraft.container.SlotActionType
|
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraft.network.PacketByteBuf
|
||||||
|
import net.minecraft.screen.ScreenHandler
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
|
import net.shadowfacts.phycon.init.PhyBlocks
|
||||||
|
import net.shadowfacts.phycon.init.PhyScreens
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @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 {
|
companion object {
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "terminal")
|
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 {
|
init {
|
||||||
// network
|
// network
|
||||||
for (y in 0 until 6) {
|
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) {
|
if (slotId in 0 until 54) {
|
||||||
// the slot clicked was one of the network stacks
|
// the slot clicked was one of the network stacks
|
||||||
if (actionType == SlotActionType.QUICK_MOVE) {
|
if (actionType == SlotActionType.QUICK_MOVE) {
|
||||||
val stack = slotList[slotId].stack
|
val stack = slots[slotId].stack
|
||||||
if (!stack.isEmpty && !player.world.isClient) {
|
if (!stack.isEmpty && !player.world.isClient) {
|
||||||
terminal.requestItem(stack, min(stack.count, stack.maxCount))
|
terminal.requestItem(stack, min(stack.count, stack.maxCount))
|
||||||
}
|
}
|
||||||
} else if (actionType == SlotActionType.PICKUP && clickData == 1) {
|
} else if (actionType == SlotActionType.PICKUP && clickData == 1) {
|
||||||
if (clickData == 1) {
|
if (clickData == 1) {
|
||||||
// right click, request half stack
|
// right click, request half stack
|
||||||
val stack = slotList[slotId].stack
|
val stack = slots[slotId].stack
|
||||||
if (!stack.isEmpty && !player.world.isClient) {
|
if (!stack.isEmpty && !player.world.isClient) {
|
||||||
terminal.requestItem(stack, ceil(min(stack.count, stack.maxCount) / 2f).toInt())
|
terminal.requestItem(stack, ceil(min(stack.count, stack.maxCount) / 2f).toInt())
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package net.shadowfacts.phycon.util
|
package net.shadowfacts.phycon.util
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
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.item.ItemStack
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.ListTag
|
import net.minecraft.nbt.ListTag
|
||||||
|
@ -11,10 +11,10 @@ import kotlin.math.min
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
fun BasicInventory.toTag(): ListTag {
|
fun SimpleInventory.toTag(): ListTag {
|
||||||
val list = ListTag()
|
val list = ListTag()
|
||||||
for (slot in 0 until invSize) {
|
for (slot in 0 until size()) {
|
||||||
val stack = getInvStack(slot)
|
val stack = getStack(slot)
|
||||||
if (!stack.isEmpty) {
|
if (!stack.isEmpty) {
|
||||||
val stackTag = stack.toTag(CompoundTag())
|
val stackTag = stack.toTag(CompoundTag())
|
||||||
stackTag.putInt("Slot", slot)
|
stackTag.putInt("Slot", slot)
|
||||||
|
@ -24,22 +24,22 @@ fun BasicInventory.toTag(): ListTag {
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BasicInventory.fromTag(list: ListTag) {
|
fun SimpleInventory.fromTag(list: ListTag) {
|
||||||
if (list.listType != 10) throw RuntimeException("Can't decode BasicInventory from list tag that does not contain compound tags")
|
if (list.elementType != 10.toByte()) throw RuntimeException("Can't decode BasicInventory from list tag that does not contain compound tags")
|
||||||
this.clear()
|
this.clear()
|
||||||
for (tag in list) {
|
for (tag in list) {
|
||||||
val compound = tag as CompoundTag
|
val compound = tag as CompoundTag
|
||||||
val stack = ItemStack.fromTag(compound)
|
val stack = ItemStack.fromTag(compound)
|
||||||
val slot = compound.getInt("Slot")
|
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()
|
@Suppress("NAME_SHADOWING") val stack = stack.copy()
|
||||||
val current = getInvStack(slot)
|
val current = getStack(slot)
|
||||||
if (current.isEmpty) {
|
if (current.isEmpty) {
|
||||||
setInvStack(slot, stack)
|
setStack(slot, stack)
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
|
} else if (ItemStackUtil.areEqualIgnoreAmounts(stack, current)) {
|
||||||
val toTransfer = min(current.maxCount - current.count, stack.count)
|
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
|
var remaining = stack
|
||||||
for (slot in 0 until invSize) {
|
for (slot in 0 until size()) {
|
||||||
remaining = insert(stack, slot)
|
remaining = insert(stack, slot)
|
||||||
if (remaining.isEmpty) {
|
if (remaining.isEmpty) {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue