replace block actions with block entity meta data

This commit is contained in:
Bixilon 2021-05-06 19:19:34 +02:00
parent 22ed5c7740
commit 3f9b91c8aa
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
28 changed files with 255 additions and 361 deletions

View File

@ -14,6 +14,8 @@ package de.bixilon.minosoft.data
import de.bixilon.minosoft.gui.rendering.chunk.models.FaceSize
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModelElement
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
import glm_.vec2.Vec2i
import glm_.vec3.Vec3
import glm_.vec3.Vec3i
@ -83,22 +85,23 @@ enum class Directions(val directionVector: Vec3i) {
}
companion object {
val DIRECTIONS = values()
companion object : ValuesEnum<Directions> {
override val VALUES = values()
override val NAME_MAP: Map<String, Directions> = KUtil.getEnumValues(VALUES)
val SIDES = arrayOf(NORTH, SOUTH, WEST, EAST)
const val SIDES_OFFSET = 2
@JvmStatic
fun byId(id: Int): Directions {
return DIRECTIONS[id]
return VALUES[id]
}
private const val MIN_ERROR = 0.0001f
fun byDirection(direction: Vec3): Directions {
var minDirection = DIRECTIONS[0]
var minDirection = VALUES[0]
var minError = 2.0f
for (testDirection in DIRECTIONS) {
for (testDirection in VALUES) {
val error = (testDirection.floatDirectionVector - direction).length()
if (error < MIN_ERROR) {
return testDirection
@ -112,7 +115,7 @@ enum class Directions(val directionVector: Vec3i) {
init {
for (direction in DIRECTIONS) {
for (direction in VALUES) {
direction.inverted = direction.inverse()
}
}

View File

@ -16,7 +16,11 @@ package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
class BeaconBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
class BeaconBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
override fun setBlockActionData(data1: Byte, data2: Byte) {
// no data used, just recalculates the beam
}
override fun updateNBT(nbt: Map<String, Any>) {
// ToDO: {Secondary: -1, Paper.Range: -1.0D, Primary: -1, x: -90, y: 4, Levels: 0, z: 212, id: "minecraft:beacon"}

View File

@ -13,10 +13,17 @@
package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.Directions
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
class BellBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
class BellBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
var shakingDirection: Directions = Directions.NORTH
private set
override fun setBlockActionData(data1: Byte, data2: Byte) {
shakingDirection = Directions[data2.toInt()]
}
companion object : BlockEntityFactory<BellBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:bell")

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,7 +11,8 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
package de.bixilon.minosoft.data.entities.block
public interface BlockAction {
interface BlockActionEntity {
fun setBlockActionData(data1: Byte, data2: Byte)
}

View File

@ -15,6 +15,8 @@ package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.entities.block.container.*
import de.bixilon.minosoft.data.entities.block.container.storage.*
import de.bixilon.minosoft.data.entities.block.piston.PistonBlockEntity
import de.bixilon.minosoft.data.entities.block.piston.StickyPistonBlockEntity
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
@ -55,6 +57,9 @@ object DefaultBlockEntityMetaDataFactory {
TrappedChestBlockEntity,
BeehiveBlockEntity,
NoteblockBlockEntity,
EndGatewayBlockEntity,
PistonBlockEntity,
StickyPistonBlockEntity,
)
val ret: MutableMap<ResourceLocation, BlockEntityFactory<out BlockEntity>> = mutableMapOf()

View File

@ -0,0 +1,35 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
class EndGatewayBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
override fun setBlockActionData(data1: Byte, data2: Byte) {
// just emits the beacon like beam
}
override fun updateNBT(nbt: Map<String, Any>) {
}
companion object : BlockEntityFactory<EndGatewayBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:end_gateway")
override fun build(connection: PlayConnection): EndGatewayBlockEntity {
return EndGatewayBlockEntity(connection)
}
}
}

View File

@ -16,9 +16,13 @@ package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
class MobSpawnerBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
class MobSpawnerBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
override fun setBlockActionData(data1: Byte, data2: Byte) {
// ToDo
}
override fun updateNBT(nbt: Map<String, Any>) {
// ToDo: {MaxNearbyEntities: 6s, RequiredPlayerRange: 16s, SpawnCount: 4s, x: -80, y: 4, SpawnData: {id: "minecraft:zombie"}, z: 212, id: "minecraft:mob_spawner", MaxSpawnDelay: 800s, SpawnRange: 4s, Delay: 0s, MinSpawnDelay: 200s}
}

View File

@ -14,9 +14,27 @@
package de.bixilon.minosoft.data.entities.block
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.blocks.properties.Instruments
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
class NoteblockBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
class NoteblockBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
var instrument: Instruments? = null
private set
var pitch: Int? = null
private set
override fun setBlockActionData(data1: Byte, data2: Byte) {
instrument = when (data1.toInt()) {
0 -> Instruments.HARP
1 -> Instruments.BASS
2 -> Instruments.SNARE
3 -> Instruments.BANJO // ToDo: Was CLICKS_STICKS before
4 -> Instruments.BASE_DRUM
else -> null
}
pitch = data2.toInt()
}
companion object : BlockEntityFactory<NoteblockBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:noteblock")
@ -25,4 +43,5 @@ class NoteblockBlockEntity(connection: PlayConnection) : BlockEntity(connection)
return NoteblockBlockEntity(connection)
}
}
}

View File

@ -19,6 +19,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
class ShulkerBoxBlockEntity(connection: PlayConnection) : StorageBlockEntity(connection) {
companion object : BlockEntityFactory<ShulkerBoxBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:shulker_box")

View File

@ -13,7 +13,15 @@
package de.bixilon.minosoft.data.entities.block.container.storage
import de.bixilon.minosoft.data.entities.block.BlockActionEntity
import de.bixilon.minosoft.data.entities.block.container.ContainerBlockEntity
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
abstract class StorageBlockEntity(connection: PlayConnection) : ContainerBlockEntity(connection)
abstract class StorageBlockEntity(connection: PlayConnection) : ContainerBlockEntity(connection), BlockActionEntity {
var playersLookingIntoStorage: Int = 0
private set
override fun setBlockActionData(data1: Byte, data2: Byte) {
playersLookingIntoStorage = data2.toInt()
}
}

View File

@ -0,0 +1,55 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.entities.block.piston
import de.bixilon.minosoft.data.Directions
import de.bixilon.minosoft.data.entities.block.BlockActionEntity
import de.bixilon.minosoft.data.entities.block.BlockEntity
import de.bixilon.minosoft.data.entities.block.BlockEntityFactory
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.util.KUtil
import de.bixilon.minosoft.util.enum.ValuesEnum
open class PistonBlockEntity(connection: PlayConnection) : BlockEntity(connection), BlockActionEntity {
var state: PistonStates = PistonStates.PULL
private set
var direction: Directions = Directions.NORTH
private set
override fun setBlockActionData(data1: Byte, data2: Byte) {
state = PistonStates[data1.toInt()]
direction = Directions[data2.toInt()]
}
companion object : BlockEntityFactory<PistonBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:piston")
override fun build(connection: PlayConnection): PistonBlockEntity {
return PistonBlockEntity(connection)
}
}
enum class PistonStates {
PUSH,
PULL,
;
companion object : ValuesEnum<PistonStates> {
override val VALUES: Array<PistonStates> = values()
override val NAME_MAP: Map<String, PistonStates> = KUtil.getEnumValues(VALUES)
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
* Copyright (C) 2021 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,16 +11,19 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
package de.bixilon.minosoft.data.entities.block.piston
public class MobSpawnerAction implements BlockAction {
import de.bixilon.minosoft.data.entities.block.BlockEntityFactory
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
public MobSpawnerAction(int status, int ignored) {
// only 1 action (id 1)
}
class StickyPistonBlockEntity(connection: PlayConnection) : PistonBlockEntity(connection) {
@Override
public String toString() {
return "MOB_SPAWNER_RESET_DELAY";
companion object : BlockEntityFactory<StickyPistonBlockEntity> {
override val RESOURCE_LOCATION: ResourceLocation = ResourceLocation("minecraft:sticky_piston")
override fun build(connection: PlayConnection): StickyPistonBlockEntity {
return StickyPistonBlockEntity(connection)
}
}
}

View File

@ -1,26 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
public class BeaconAction implements BlockAction {
public BeaconAction(int status, int ignored) {
// only 1 action (id 1)
}
@Override
public String toString() {
return "BEACON_RECALCULATE_BEAM";
}
}

View File

@ -1,33 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
import de.bixilon.minosoft.data.Directions;
public class BellAction implements BlockAction {
private final Directions direction;
public BellAction(short unused, short direction) {
this.direction = Directions.byId(direction);
}
public Directions getDirection() {
return this.direction;
}
@Override
public String toString() {
return String.format("BELL_HIT_%s", this.direction);
}
}

View File

@ -1,27 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
public class ChestAction implements BlockAction {
private final int playersLookingInChest;
public ChestAction(int unused, int playersLookingInChest) {
this.playersLookingInChest = playersLookingInChest;
}
@Override
public String toString() {
return this.playersLookingInChest > 0 ? String.format("CHEST_OPEN (%d)", this.playersLookingInChest) : "CHEST_CLOSE";
}
}

View File

@ -1,26 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
public class EndGatewayAction implements BlockAction {
public EndGatewayAction(int status, int ignored) {
// only 1 action (id 1)
}
@Override
public String toString() {
return "END_GATEWAY_EMIT_BEAM";
}
}

View File

@ -1,43 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
public class NoteBlockAction implements BlockAction {
private final Instruments instrument;
private final int pitch;
public NoteBlockAction(int instrument, int pitch) {
this.instrument = Instruments.byId(instrument);
this.pitch = pitch;
}
@Override
public String toString() {
return String.format("NOTEBLOCK_%s:%d", this.instrument, this.pitch);
}
public enum Instruments {
HARP,
DOUBLE_BASS,
SNARE_DRUM,
CLICKS_STICKS,
BASS_DRUM;
private static final Instruments[] INSTRUMENTS = values();
public static Instruments byId(int id) {
return INSTRUMENTS[id];
}
}
}

View File

@ -1,42 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings.blocks.actions;
import de.bixilon.minosoft.data.Directions;
public class PistonAction implements BlockAction {
private final PistonStates status;
private final Directions direction;
public PistonAction(int status, int direction) {
this.status = PistonStates.byId(status);
this.direction = Directions.byId(direction);
}
@Override
public String toString() {
return String.format("PISTON_%s:%s", this.status, this.direction);
}
public enum PistonStates {
PUSH,
PULL;
private static final PistonStates[] PISTON_STATES = values();
public static PistonStates byId(int id) {
return PISTON_STATES[id];
}
}
}

View File

@ -80,8 +80,8 @@ class WorldRenderer(
}
val blockPosition = Vec3i.of(chunkPosition, sectionHeight, index.indexPosition)
val neighborBlocks: Array<BlockState?> = arrayOfNulls(Directions.DIRECTIONS.size)
for (direction in Directions.DIRECTIONS) {
val neighborBlocks: Array<BlockState?> = arrayOfNulls(Directions.VALUES.size)
for (direction in Directions.VALUES) {
neighborBlocks[direction.ordinal] = world.getBlockState(blockPosition + direction)
}

View File

@ -35,12 +35,12 @@ import glm_.vec3.Vec3
import glm_.vec3.Vec3i
class BlockRenderer(data: JsonObject, parent: BlockModel) : BlockLikeRenderer {
private val cullFaces: Array<Directions?> = arrayOfNulls(Directions.DIRECTIONS.size)
private val cullFaces: Array<Directions?> = arrayOfNulls(Directions.VALUES.size)
val textures: MutableMap<String, String> = mutableMapOf()
private val elements: MutableSet<ElementRenderer> = mutableSetOf()
private val textureMapping: MutableMap<String, Texture> = mutableMapOf()
override val faceBorderSizes: Array<Array<FaceSize>?> = arrayOfNulls(Directions.DIRECTIONS.size)
override val transparentFaces: BooleanArray = BooleanArray(Directions.DIRECTIONS.size)
override val faceBorderSizes: Array<Array<FaceSize>?> = arrayOfNulls(Directions.VALUES.size)
override val transparentFaces: BooleanArray = BooleanArray(Directions.VALUES.size)
val directionMapping: HashBiMap<Directions, Directions> = HashBiMap.create()
init {
@ -52,7 +52,7 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) : BlockLikeRenderer {
}
private fun createDirectionMapping(rotation: Vec3) {
for (direction in Directions.DIRECTIONS) {
for (direction in Directions.VALUES) {
try {
directionMapping[direction] = ElementRenderer.getRotatedDirection(rotation, direction)
} catch (_: IllegalArgumentException) {
@ -69,7 +69,7 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) : BlockLikeRenderer {
}
override fun postInit() {
for (direction in Directions.DIRECTIONS) {
for (direction in Directions.VALUES) {
var directionIsCullFace: Boolean? = null
var directionIsNotTransparent: Boolean? = null
val faceBorderSites: MutableList<FaceSize> = mutableListOf()
@ -109,7 +109,7 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) : BlockLikeRenderer {
var tintColor: RGBColor? = null
var biome: Biome? = null
for (direction in Directions.DIRECTIONS) {
for (direction in Directions.VALUES) {
val rotatedDirection = directionMapping[direction] ?: direction
val invertedDirection = direction.inverted
var isNeighbourTransparent = false

View File

@ -40,7 +40,7 @@ class ElementRenderer(
rescale: Boolean,
private val directionMapping: HashBiMap<Directions, Directions>,
) {
val faceBorderSize: Array<FaceSize?> = arrayOfNulls(Directions.DIRECTIONS.size)
val faceBorderSize: Array<FaceSize?> = arrayOfNulls(Directions.VALUES.size)
private val faces: MutableMap<Directions, BlockModelFace> = mutableMapOf()
private var transformedPositions: Array<Vec3> = parent.transformedPositions.clone()
private val from = parent.from
@ -48,7 +48,7 @@ class ElementRenderer(
init {
rotatePositionsAxes(transformedPositions, rotation, rescale)
for (direction in Directions.DIRECTIONS) {
for (direction in Directions.VALUES) {
direction.getFaceBorderSizes(from, to)?.let {
faceBorderSize[direction.ordinal] = it
}
@ -57,7 +57,7 @@ class ElementRenderer(
}
}
if (uvLock) {
for (direction in Directions.DIRECTIONS) {
for (direction in Directions.VALUES) {
val axis = Axes.byDirection(direction)
val angle = Axes.choose(axis, rotation) * Axes.choose(axis, direction.directionVector)
faces[direction]?.rotate(-angle)

View File

@ -27,8 +27,8 @@ class FluidRenderer(
private val stillFluid: Fluid,
private val flowingFluid: Fluid,
) : BlockLikeRenderer {
override val faceBorderSizes: Array<Array<FaceSize>?> = arrayOfNulls(Directions.DIRECTIONS.size)
override val transparentFaces: BooleanArray = BooleanArray(Directions.DIRECTIONS.size)
override val faceBorderSizes: Array<Array<FaceSize>?> = arrayOfNulls(Directions.VALUES.size)
override val transparentFaces: BooleanArray = BooleanArray(Directions.VALUES.size)
private lateinit var stillTexture: Texture
private lateinit var flowingTexture: Texture
@ -46,7 +46,7 @@ class FluidRenderer(
var biome: Biome? = null
val positions = calculatePositions(heights)
for (direction in Directions.DIRECTIONS) {
for (direction in Directions.VALUES) {
val face = BlockModelFace(positions, direction)
if (isFlowing || Directions.SIDES.contains(direction)) {
face.scale(0.5)

View File

@ -27,7 +27,7 @@ class MultipartRenderer(
val models: List<BlockLikeRenderer>,
) : BlockLikeRenderer {
override val faceBorderSizes: Array<Array<FaceSize>?>
override val transparentFaces: BooleanArray = BooleanArray(Directions.DIRECTIONS.size)
override val transparentFaces: BooleanArray = BooleanArray(Directions.VALUES.size)
init {
val faceBorderSizes: MutableList<Array<FaceSize>?> = mutableListOf()

View File

@ -1,47 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.modding.event.events;
import de.bixilon.minosoft.data.mappings.blocks.actions.BlockAction;
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
import de.bixilon.minosoft.protocol.packets.s2c.play.PacketBlockAction;
import glm_.vec3.Vec3i;
/**
* Fired when a block actions happens (like opening a chest, changing instrument/note/etc on a note block, etc)
*/
public class BlockActionEvent extends CancelableEvent {
private final Vec3i position;
private final BlockAction data;
public BlockActionEvent(PlayConnection connection, Vec3i position, BlockAction data) {
super(connection);
this.position = position;
this.data = data;
}
public BlockActionEvent(PlayConnection connection, PacketBlockAction pkg) {
super(connection);
this.position = pkg.getPosition();
this.data = pkg.getData();
}
public Vec3i getPosition() {
return this.position;
}
public BlockAction getData() {
return this.data;
}
}

View File

@ -0,0 +1,70 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play
import de.bixilon.minosoft.data.entities.block.BlockActionEntity
import de.bixilon.minosoft.data.entities.block.DefaultBlockEntityMetaDataFactory
import de.bixilon.minosoft.data.mappings.blocks.Block
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.KUtil.asResourceLocation
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
import glm_.vec3.Vec3i
class BlockActionS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
val position: Vec3i = if (buffer.versionId < ProtocolVersions.V_14W03B) {
buffer.readShortBlockPosition()
} else {
buffer.readBlockPosition()
}
val data1: Byte = buffer.readByte()
val data2: Byte = buffer.readByte()
val block: Block = buffer.connection.mapping.blockRegistry.get(buffer.readVarInt())
override fun handle(connection: PlayConnection) {
val blockEntityTypeResourceLocation = when (block.resourceLocation.full) {
"minecraft:white_shulker_box", "minecraft:orange_shulker_box", "minecraft:magenta_shulker_box", "minecraft:light_blue_shulker_box",
"minecraft:yellow_shulker_box", "minecraft:lime_shulker_box", "minecraft:pink_shulker_box", "minecraft:gray_shulker_box",
"minecraft:silver_shulker_box", "minecraft:cyan_shulker_box", "minecraft:purple_shulker_box", "minecraft:blue_shulker_box",
"minecraft:brown_shulker_box", "minecraft:green_shulker_box", "minecraft:red_shulker_box", "minecraft:black_shulker_box",
-> "minecraft:shulker_box"
else -> block.resourceLocation.full
}.asResourceLocation()
val blockEntity = connection.world.getBlockEntity(position) ?: let {
val factory = connection.mapping.blockEntityRegistry.get(blockEntityTypeResourceLocation)?.factory
?: DefaultBlockEntityMetaDataFactory.getEntityFactory(blockEntityTypeResourceLocation)
?: let {
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN) { "Unknown block entity $blockEntityTypeResourceLocation" }
return
}
val blockEntity = factory.build(connection)
connection.world.setBlockEntity(position, blockEntity)
blockEntity
}
if (blockEntity !is BlockActionEntity) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.WARN) { "Block entity $blockEntity can not accept block entity actions!" }
return
}
blockEntity.setBlockActionData(data1, data2)
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block action (position=$position, data1=$data1, data2=$data2, block=$block)" }
}
}

View File

@ -1,77 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play;
import de.bixilon.minosoft.data.mappings.blocks.Block;
import de.bixilon.minosoft.data.mappings.blocks.actions.*;
import de.bixilon.minosoft.modding.event.events.BlockActionEvent;
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
import de.bixilon.minosoft.util.logging.Log;
import glm_.vec3.Vec3i;
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W03B;
public class PacketBlockAction extends PlayS2CPacket {
private final Vec3i position;
private final BlockAction data;
public PacketBlockAction(PlayInByteBuffer buffer) {
// that's the only difference here
if (buffer.getVersionId() < V_14W03B) {
this.position = buffer.readShortBlockPosition();
} else {
this.position = buffer.readBlockPosition();
}
int byte1 = buffer.readUnsignedByte();
int byte2 = buffer.readUnsignedByte();
Block blockId = buffer.getConnection().getMapping().getBlockRegistry().get(buffer.readVarInt());
if (blockId == null) {
this.data = null;
return;
}
this.data = switch (blockId.getResourceLocation().getFull()) {
case "minecraft:noteblock" -> new NoteBlockAction(byte1, byte2); // ToDo: was replaced in 17w47a (346) with the block id
case "minecraft:sticky_piston", "minecraft:piston" -> new PistonAction(byte1, byte2);
case "minecraft:chest", "minecraft:ender_chest", "minecraft:trapped_chest", "minecraft:white_shulker_box", "minecraft:shulker_box", "minecraft:orange_shulker_box", "minecraft:magenta_shulker_box", "minecraft:light_blue_shulker_box", "minecraft:yellow_shulker_box", "minecraft:lime_shulker_box", "minecraft:pink_shulker_box", "minecraft:gray_shulker_box", "minecraft:silver_shulker_box", "minecraft:cyan_shulker_box", "minecraft:purple_shulker_box", "minecraft:blue_shulker_box", "minecraft:brown_shulker_box", "minecraft:green_shulker_box", "minecraft:red_shulker_box", "minecraft:black_shulker_box" -> new ChestAction(byte1, byte2);
case "minecraft:beacon" -> new BeaconAction(byte1, byte2);
case "minecraft:mob_spawner" -> new MobSpawnerAction(byte1, byte2);
case "minecraft:end_gateway" -> new EndGatewayAction(byte1, byte2);
default -> null;
};
}
@Override
public void handle(PlayConnection connection) {
BlockActionEvent event = new BlockActionEvent(connection, this);
if (connection.fireEvent(event)) {
return;
}
}
public Vec3i getPosition() {
return this.position;
}
public BlockAction getData() {
return this.data;
}
@Override
public void log() {
Log.protocol(String.format("[IN] Block action received %s at %s", this.data, this.position));
}
}

View File

@ -260,7 +260,7 @@ open class InByteBuffer {
}
fun readDirection(): Directions {
return Directions.DIRECTIONS[readVarInt()]
return Directions.VALUES[readVarInt()]
}
fun readPose(): Poses {

View File

@ -162,7 +162,7 @@ class PacketTypes {
PLAY_BLOCK_BREAK_ACK({ BlockBreakAckS2CP(it) }),
PLAY_BLOCK_BREAK_ANIMATION({ BlockBreakAnimationS2CP(it) }),
PLAY_BLOCK_ENTITY_META_DATA({ BlockEntityMetaDataS2CP(it) }),
PLAY_BLOCK_ACTION({ PacketBlockAction(it) }),
PLAY_BLOCK_ACTION({ BlockActionS2CP(it) }),
PLAY_BLOCK_SET({ BlockSetS2CP(it) }),
PLAY_BOSS_BAR({ PacketBossBar(it) }),
PLAY_SERVER_DIFFICULTY({ ServerDifficultyS2CP(it) }),