1.13.2+ blockId System

This commit is contained in:
Bixilon 2020-07-14 19:55:41 +02:00
parent 360eeee423
commit 3b893f194d
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
29 changed files with 1381 additions and 190 deletions

View File

@ -15,7 +15,9 @@ package de.bixilon.minosoft;
import de.bixilon.minosoft.config.Configuration;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.game.datatypes.Mappings;
import de.bixilon.minosoft.game.datatypes.Player;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.entities.items.Items;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevel;
@ -30,9 +32,7 @@ import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.*;
public class Minosoft {
static Configuration config;
@ -127,29 +127,29 @@ public class Minosoft {
}
private static void loadMappings() {
HashMap<String, Mappings> mappingsHashMap = new HashMap<>();
mappingsHashMap.put("registries", Mappings.REGISTRIES);
mappingsHashMap.put("blocks", Mappings.BLOCKS);
try {
for (ProtocolVersion version : ProtocolVersion.versionMappingArray) {
if (version.getVersionNumber() < ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
// skip them, use mapping of 1.12
continue;
}
String fileName;
if (version.getVersionNumber() >= ProtocolVersion.VERSION_1_14_4.getVersionNumber()) {
fileName = Config.homeDir + String.format("assets/mapping/%s/registries.json", version.getVersionString());
} else {
fileName = Config.homeDir + String.format("assets/mapping/%s/items.json", version.getVersionString());
}
JSONObject data = Util.readJsonFromFile(fileName);
for (Iterator<String> mods = data.keys(); mods.hasNext(); ) {
// key = mod name
String mod = mods.next();
JSONObject modJSON = data.getJSONObject(mod);
if (version.getVersionNumber() >= ProtocolVersion.VERSION_1_14_4.getVersionNumber()) {
Items.load(mod, modJSON.getJSONObject("item").getJSONObject("entries"), version);
} else {
// special rule: multiple files for registers
Items.load(mod, modJSON, version);
for (Map.Entry<String, Mappings> mappingSet : mappingsHashMap.entrySet()) {
JSONObject data = Util.readJsonFromFile(Config.homeDir + String.format("assets/mapping/%s/%s.json", version.getVersionString(), mappingSet.getKey()));
for (Iterator<String> mods = data.keys(); mods.hasNext(); ) {
// key = mod name
String mod = mods.next();
JSONObject modJSON = data.getJSONObject(mod);
switch (mappingSet.getValue()) {
case REGISTRIES:
Items.load(mod, modJSON.getJSONObject("item").getJSONObject("entries"), version);
break;
case BLOCKS:
Blocks.load(mod, modJSON, version);
break;
}
}
}
}

View File

@ -0,0 +1,19 @@
/*
* Codename 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.game.datatypes;
public enum Mappings {
BLOCKS,
REGISTRIES
}

View File

@ -0,0 +1,94 @@
/*
* Codename 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.game.datatypes.blocks;
public class Block {
final String mod;
final String identifier;
final BlockRotation rotation;
final BlockProperty[] properties;
public Block(String mod, String identifier, BlockProperty[] properties, BlockRotation rotation) {
this.mod = mod;
this.identifier = identifier;
this.properties = properties;
this.rotation = rotation;
}
public Block(String mod, String identifier, BlockProperty[] properties) {
this.mod = mod;
this.identifier = identifier;
this.properties = properties;
this.rotation = BlockRotation.NONE;
}
public Block(String mod, String identifier, BlockRotation rotation) {
this.mod = mod;
this.identifier = identifier;
this.properties = new BlockProperty[0];
this.rotation = rotation;
}
public Block(String mod, String identifier) {
this.mod = mod;
this.identifier = identifier;
this.properties = new BlockProperty[0];
this.rotation = BlockRotation.NONE;
}
public String getMod() {
return mod;
}
public String getIdentifier() {
return identifier;
}
public BlockRotation getRotation() {
return rotation;
}
public BlockProperty[] getProperties() {
return properties;
}
@Override
public String toString() {
StringBuilder out = new StringBuilder();
if (rotation != BlockRotation.NONE) {
out.append(" (");
out.append("rotation=");
out.append(getRotation().name());
}
if (properties.length > 0) {
if (out.length() > 0) {
out.append(" ,");
} else {
out.append(" (");
}
out.append("properties={");
for (BlockProperty property : properties) {
out.append(property.name());
out.append(",");
}
// remove last ,
out.setLength(out.length() - 1);
out.append("}");
}
if (out.length() > 0) {
out.append(")");
}
return String.format("%s:%s%s", getMod(), getIdentifier(), out.toString());
}
}

View File

@ -0,0 +1,344 @@
/*
* Codename 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.game.datatypes.blocks;
public enum BlockProperty {
NONE,
// farmland
MOISTURE_0,
MOISTURE_1,
MOISTURE_2,
MOISTURE_3,
MOISTURE_4,
MOISTURE_5,
MOISTURE_6,
MOISTURE_7,
// furnace, ...
LIT,
// sign, fence
WATERLOGGED,
// half (flowers)
HALF_UPPER,
HALF_LOWER,
// slabs
SLAB_TOP,
SLAB_BOTTOM,
SLAB_DOUBLE,
// fluids
LEVEL_0,
LEVEL_1,
LEVEL_2,
LEVEL_3,
LEVEL_4,
LEVEL_5,
LEVEL_6,
LEVEL_7,
LEVEL_8,
LEVEL_9,
LEVEL_10,
LEVEL_11,
LEVEL_12,
LEVEL_13,
LEVEL_14,
LEVEL_15,
// bee hive
HONEY_LEVEL_0,
HONEY_LEVEL_1,
HONEY_LEVEL_2,
HONEY_LEVEL_3,
HONEY_LEVEL_4,
HONEY_LEVEL_5,
// pistons
TYPE_NORMAL,
TYPE_STICKY,
EXTENDED,
SHORT,
// rails
POWERED,
STRAIGHT,
INNER_LEFT,
INNER_RIGHT,
OUTER_LEFT,
OUTER_RIGHT,
NORTH_SOUTH,
SOUTH_EAST,
SOUTH_WEST,
NORTH_WEST,
NORTH_EAST,
EAST_WEST,
ASCENDING_EAST,
ASCENDING_WEST,
ASCENDING_NORTH,
ASCENDING_SOUTH,
SNOWY,
STAGE_0,
STAGE_1,
// dispenser
TRIGGERED,
// leaves
DISTANCE_0,
DISTANCE_1,
DISTANCE_2,
DISTANCE_3,
DISTANCE_4,
DISTANCE_5,
DISTANCE_6,
DISTANCE_7,
PERSISTENT,
// bed
HEAD,
FOOT,
OCCUPIED,
// tnt
UNSTABLE,
// door
HINGE_LEFT,
HINGE_RIGHT,
OPEN,
// fire
NORTH,
SOUTH,
EAST,
WEST,
UP,
DOWN,
AGE_0,
AGE_1,
AGE_2,
AGE_3,
AGE_4,
AGE_5,
AGE_6,
AGE_7,
AGE_8,
AGE_9,
AGE_10,
AGE_11,
AGE_12,
AGE_13,
AGE_14,
AGE_15,
AGE_16,
AGE_17,
AGE_18,
AGE_19,
AGE_20,
AGE_21,
AGE_22,
AGE_23,
AGE_24,
AGE_25,
// noteblock
HARP,
BASEDRUM,
SNARE,
HAT,
BASS,
FLUTE,
BELL,
GUITAR,
CHIME,
XYLOPHONE,
IRON_XYLOPHONE,
COW_BELL,
DIDGERIDOO,
BIT,
BANJO,
PLING,
NOTE_0,
NOTE_1,
NOTE_2,
NOTE_3,
NOTE_4,
NOTE_5,
NOTE_6,
NOTE_7,
NOTE_8,
NOTE_9,
NOTE_10,
NOTE_11,
NOTE_12,
NOTE_13,
NOTE_14,
NOTE_15,
NOTE_16,
NOTE_17,
NOTE_18,
NOTE_19,
NOTE_20,
NOTE_21,
NOTE_22,
NOTE_23,
NOTE_24,
// redstone
POWER_0,
POWER_1,
POWER_2,
POWER_3,
POWER_4,
POWER_5,
POWER_6,
POWER_7,
POWER_8,
POWER_9,
POWER_10,
POWER_11,
POWER_12,
POWER_13,
POWER_14,
POWER_15,
NORTH_UP,
SOUTH_UP,
EAST_UP,
WEST_UP,
NORTH_SIDE,
SOUTH_SIDE,
EAST_SIDE,
WEST_SIDE,
LAYERS_1,
LAYERS_2,
LAYERS_3,
LAYERS_4,
LAYERS_5,
LAYERS_6,
LAYERS_7,
LAYERS_8,
IN_WALL,
// scaffolding
BOTTOM,
// log, portal
AXIS_X,
AXIS_Y,
AXIS_Z,
// trapwire
DISARMED,
ATTACHED,
// daylight, etc
INVERTED,
// button
FLOOR,
WALL,
CEILING,
// structure block, comparator
SAVE,
LOAD,
CORNER,
DATA,
COMPARE,
SUBTRACT,
// command block
CONDITIONAL,
// double column
DRAG,
// bell
SINGLE_WALL,
DOUBLE_WALL,
// lantern
HANGING,
// sea pickle
PICKLES_1,
PICKLES_2,
PICKLES_3,
PICKLES_4,
// lectern
HAS_BOOK,
// brewing stand
HAS_BOTTLE_0,
HAS_BOTTLE_1,
HAS_BOTTLE_2,
// chest
TYPE_SINGLE,
TYPE_LEFT,
TYPE_RIGHT,
// cake
BITES_0,
BITES_1,
BITES_2,
BITES_3,
BITES_4,
BITES_5,
BITES_6,
// bamboo
SMALL,
LARGE,
// repeater
LOCKED,
DELAY_1,
DELAY_2,
DELAY_3,
DELAY_4,
// end portal frame
EYE,
// jukebox
HAS_RECORD,
// campfire
SIGNAL_FIRE,
// turtle eggs
EGGS_1,
EGGS_2,
EGGS_3,
EGGS_4,
// turtle eggs
HATCH_0,
HATCH_1,
HATCH_2,
ENABLED
}

View File

@ -0,0 +1,44 @@
/*
* Codename 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.game.datatypes.blocks;
public enum BlockRotation {
NONE,
SOUTH,
SOUTH_SOUTH_WEST,
SOUTH_WEST,
WEST_SOUTH_WEST,
WEST,
WEST_NORTH_WEST,
NORTH_WEST,
NORTH_NORTH_WEST,
NORTH,
NORTH_NORTH_EAST,
NORTH_EAST,
EAST_NORTH_EAST,
EAST,
EAST_SOUTH_EAST,
SOUTH_EAST,
SOUTH_SOUTH_EAST,
NORTH_SOUTH,
EAST_WEST,
ASCENDING_EAST,
ASCENDING_WEST,
ASCENDING_NORTH,
ASCENDING_SOUTH,
UP,
DOWN
}

View File

@ -1,3 +1,4 @@
package de.bixilon.minosoft.game.datatypes.blocks;
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
@ -11,126 +12,562 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.game.datatypes.blocks;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import org.json.JSONArray;
import org.json.JSONObject;
import de.bixilon.minosoft.game.datatypes.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public enum Blocks {
UNKNOWN(-1), // the buggy pink black block (any other block)
AIR(0),
STONE(1),
GRASS(2),
DIRT(3),
COBBLESTONE(4),
OAK_WOOD_PLANKS(5),
SPRUCE_WOOD_PLANKS(OAK_WOOD_PLANKS, 1),
BIRCH_WOOD_PLANKS(OAK_WOOD_PLANKS, 2),
JUNGLE_WOOD_PLANKS(OAK_WOOD_PLANKS, 3),
ACACIA_WOOD_PLANKS(OAK_WOOD_PLANKS, 4),
DARK_OAK_WOOD_PLANKS(OAK_WOOD_PLANKS, 5),
BEDROCK(7),
OAK_WOOD(17),
SPRUCE_WOOD(OAK_WOOD, 1),
BIRCH_WOOD(OAK_WOOD, 2),
JUNGLE_WOOD(OAK_WOOD, 3),
GLASS(20),
WHITE_WOOL(35, Color.WHITE),
ORANGE_WOOL(WHITE_WOOL, Color.ORANGE),
MAGENTA_WOOL(WHITE_WOOL, Color.MAGENTA),
LIGHT_BLUE_WOOL(WHITE_WOOL, Color.LIGHT_BLUE),
YELLOW_WOOL(WHITE_WOOL, Color.YELLOW),
LIME_WOOL(WHITE_WOOL, Color.LIME),
PINK_WOOL(WHITE_WOOL, Color.PINK),
GRAY_WOOL(WHITE_WOOL, Color.GRAY),
LIGHT_GRAY_WOOL(WHITE_WOOL, Color.SILVER),
CYAN_WOOL(WHITE_WOOL, Color.CYAN),
PURPLE_WOOL(WHITE_WOOL, Color.PURPLE),
BLUE_WOOL(WHITE_WOOL, Color.BLUE),
BROWN_WOOL(WHITE_WOOL, Color.BROWN),
GREEN_WOOL(WHITE_WOOL, Color.GREEN),
RED_WOOL(WHITE_WOOL, Color.RED),
BLACK_WOOL(WHITE_WOOL, Color.BLACK),
TNT(46),
STANDING_SIGN_SOUTH(63, 0),
STANDING_SIGN_SOUTH_SOUTH_WEST(STANDING_SIGN_SOUTH, 1),
STANDING_SIGN_SOUTH_WEST(STANDING_SIGN_SOUTH, 2),
STANDING_SIGN_WEST_SOUTH_WEST(STANDING_SIGN_SOUTH, 3),
STANDING_SIGN_WEST(STANDING_SIGN_SOUTH, 4),
STANDING_SIGN_WEST_NORTH_WEST(STANDING_SIGN_SOUTH, 5),
STANDING_SIGN_NORTH_WEST(STANDING_SIGN_SOUTH, 6),
STANDING_SIGN_NORTH_NORTH_WEST(STANDING_SIGN_SOUTH, 7),
STANDING_SIGN_NORTH(STANDING_SIGN_SOUTH, 8),
STANDING_SIGN_NORTH_NORTH_EAST(STANDING_SIGN_SOUTH, 9),
STANDING_SIGN_NORTH_EAST(STANDING_SIGN_SOUTH, 10),
STANDING_SIGN_EAST_NORTH_EAST(STANDING_SIGN_SOUTH, 11),
STANDING_SIGN_EAST(STANDING_SIGN_SOUTH, 12),
STANDING_SIGN_EAST_SOUTH_EAST(STANDING_SIGN_SOUTH, 13),
STANDING_SIGN_SOUTH_EAST(STANDING_SIGN_SOUTH, 14),
STANDING_SIGN_SOUTH_SOUTH_EAST(STANDING_SIGN_SOUTH, 15),
WALL_SIGN_EAST(68, 0),
WALL_SIGN_NORTH(WALL_SIGN_EAST, 1),
WALL_SIGN_SOUTH(WALL_SIGN_EAST, 2),
WALL_SIGN_WEST(WALL_SIGN_EAST, 3),
DROPPER_DOWN(158, 0),
DROPPER_EAST(DROPPER_DOWN, 1),
DROPPER_NORTH(DROPPER_DOWN, 2),
DROPPER_SOUTH(DROPPER_DOWN, 3),
DROPPER_UP(DROPPER_DOWN, 4),
DROPPER_WEST(DROPPER_DOWN, 5);
public class Blocks {
public static Block nullBlock;
static ArrayList<Block> blockList = new ArrayList<>();
static HashMap<ProtocolVersion, BiMap<Integer, Block>> blockMap = new HashMap<>(); // version -> (protocolId > Item)
static HashMap<String, HashMap<String, BlockProperty>> propertiesMapping = new HashMap<>();
static HashMap<String, BlockRotation> rotationMapping = new HashMap<>();
// ToDo all blocks
// ToDo post water update block states
static {
HashMap<String, BlockProperty> propertyHashMap;
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 15; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("LEVEL_%d", i)));
}
propertiesMapping.put("level", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 5; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("HONEY_LEVEL_%d", i)));
}
propertiesMapping.put("honey_level", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 15; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("POWER_%d", i)));
}
propertiesMapping.put("power", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 1; i <= 8; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("LAYERS_%d", i)));
}
propertiesMapping.put("layers", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 7; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("DISTANCE_%d", i)));
}
propertiesMapping.put("distance", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 25; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("AGE_%d", i)));
}
propertiesMapping.put("age", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 7; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("DISTANCE_%d", i)));
}
propertiesMapping.put("distance", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 7; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("MOISTURE_%d", i)));
}
propertiesMapping.put("moisture", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 1; i <= 4; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("PICKLES_%d", i)));
}
propertiesMapping.put("pickles", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 6; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("BITES_%d", i)));
}
propertiesMapping.put("bites", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 1; i <= 4; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("DELAY_%d", i)));
}
propertiesMapping.put("delay", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 2; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("HATCH_%d", i)));
}
propertiesMapping.put("hatch", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 1; i <= 4; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("EGGS_%d", i)));
}
propertiesMapping.put("eggs", propertyHashMap);
propertyHashMap = new HashMap<>();
for (int i = 0; i <= 24; i++) {
propertyHashMap.put(String.valueOf(i), BlockProperty.valueOf(String.format("NOTE_%d", i)));
}
propertiesMapping.put("note", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.SNOWY);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("snowy", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("0", BlockProperty.STAGE_0);
propertyHashMap.put("1", BlockProperty.STAGE_1);
propertiesMapping.put("stage", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.EAST);
propertyHashMap.put("up", BlockProperty.EAST_UP);
propertyHashMap.put("side", BlockProperty.EAST_SIDE);
propertyHashMap.put("false", BlockProperty.NONE);
propertyHashMap.put("none", BlockProperty.NONE);
propertiesMapping.put("east", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.WEST);
propertyHashMap.put("up", BlockProperty.WEST_UP);
propertyHashMap.put("side", BlockProperty.WEST_SIDE);
propertyHashMap.put("false", BlockProperty.NONE);
propertyHashMap.put("none", BlockProperty.NONE);
propertiesMapping.put("west", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.SOUTH);
propertyHashMap.put("up", BlockProperty.SOUTH_UP);
propertyHashMap.put("side", BlockProperty.SOUTH_SIDE);
propertyHashMap.put("false", BlockProperty.NONE);
propertyHashMap.put("none", BlockProperty.NONE);
propertiesMapping.put("south", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.NORTH);
propertyHashMap.put("up", BlockProperty.NORTH_UP);
propertyHashMap.put("side", BlockProperty.NORTH_SIDE);
propertyHashMap.put("false", BlockProperty.NONE);
propertyHashMap.put("none", BlockProperty.NONE);
propertiesMapping.put("north", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.UP);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("up", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.DOWN);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("down", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.IN_WALL);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("in_wall", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.EXTENDED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("extended", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.POWERED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("powered", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.OPEN);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("open", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.BOTTOM);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("bottom", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.OCCUPIED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("occupied", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.ATTACHED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("attached", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.DISARMED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("disarmed", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.INVERTED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("inverted", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.TRIGGERED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("triggered", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.CONDITIONAL);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("conditional", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.DRAG);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("drag", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.UNSTABLE);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("unstable", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.HANGING);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("hanging", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.HAS_BOOK);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("has_book", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.HAS_BOTTLE_0);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("has_bottle_0", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.HAS_BOTTLE_1);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("has_bottle_1", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.HAS_BOTTLE_2);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("has_bottle_2", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.PERSISTENT);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("persistent", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.LIT);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("lit", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.WATERLOGGED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("waterlogged", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.LOCKED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("locked", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.EYE);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("eye", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.ENABLED);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("enabled", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.HAS_RECORD);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("has_record", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.SHORT);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("short", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("true", BlockProperty.SIGNAL_FIRE);
propertyHashMap.put("false", BlockProperty.NONE);
propertiesMapping.put("signal_fire", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("harp", BlockProperty.HARP);
propertyHashMap.put("basedrum", BlockProperty.BASEDRUM);
propertyHashMap.put("snare", BlockProperty.SNARE);
propertyHashMap.put("hat", BlockProperty.HAT);
propertyHashMap.put("bass", BlockProperty.BASS);
propertyHashMap.put("flute", BlockProperty.FLUTE);
propertyHashMap.put("bell", BlockProperty.BELL);
propertyHashMap.put("guitar", BlockProperty.GUITAR);
propertyHashMap.put("chime", BlockProperty.CHIME);
propertyHashMap.put("xylophone", BlockProperty.XYLOPHONE);
propertyHashMap.put("iron_xylophone", BlockProperty.IRON_XYLOPHONE);
propertyHashMap.put("cow_bell", BlockProperty.COW_BELL);
propertyHashMap.put("didgeridoo", BlockProperty.DIDGERIDOO);
propertyHashMap.put("bit", BlockProperty.BIT);
propertyHashMap.put("banjo", BlockProperty.BANJO);
propertyHashMap.put("pling", BlockProperty.PLING);
propertiesMapping.put("instrument", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("head", BlockProperty.HEAD);
propertyHashMap.put("foot", BlockProperty.FOOT);
propertiesMapping.put("part", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("left", BlockProperty.HINGE_LEFT);
propertyHashMap.put("right", BlockProperty.HINGE_RIGHT);
propertiesMapping.put("hinge", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("x", BlockProperty.AXIS_X);
propertyHashMap.put("y", BlockProperty.AXIS_Y);
propertyHashMap.put("z", BlockProperty.AXIS_Z);
propertiesMapping.put("axis", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("floor", BlockProperty.FLOOR);
propertyHashMap.put("wall", BlockProperty.WALL);
propertyHashMap.put("ceiling", BlockProperty.CEILING);
propertiesMapping.put("face", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("floor", BlockProperty.FLOOR);
propertyHashMap.put("ceiling", BlockProperty.CEILING);
propertyHashMap.put("single_wall", BlockProperty.SINGLE_WALL);
propertyHashMap.put("double_wall", BlockProperty.DOUBLE_WALL);
propertiesMapping.put("attachment", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("save", BlockProperty.SAVE);
propertyHashMap.put("load", BlockProperty.LOAD);
propertyHashMap.put("corner", BlockProperty.CORNER);
propertyHashMap.put("data", BlockProperty.DATA);
propertyHashMap.put("compare", BlockProperty.COMPARE);
propertyHashMap.put("subtract", BlockProperty.SUBTRACT);
propertiesMapping.put("mode", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("top", BlockProperty.HALF_UPPER);
propertyHashMap.put("upper", BlockProperty.HALF_UPPER);
propertyHashMap.put("bottom", BlockProperty.HALF_LOWER);
propertyHashMap.put("lower", BlockProperty.HALF_LOWER);
propertiesMapping.put("half", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("none", BlockProperty.NONE);
propertyHashMap.put("small", BlockProperty.LARGE);
propertyHashMap.put("large", BlockProperty.SMALL);
propertiesMapping.put("leaves", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("top", BlockProperty.SLAB_TOP);
propertyHashMap.put("bottom", BlockProperty.SLAB_BOTTOM);
propertyHashMap.put("double", BlockProperty.SLAB_DOUBLE);
propertyHashMap.put("normal", BlockProperty.TYPE_NORMAL);
propertyHashMap.put("sticky", BlockProperty.TYPE_STICKY);
propertyHashMap.put("single", BlockProperty.TYPE_SINGLE);
propertyHashMap.put("left", BlockProperty.TYPE_LEFT);
propertyHashMap.put("right", BlockProperty.TYPE_RIGHT);
propertiesMapping.put("type", propertyHashMap);
propertyHashMap = new HashMap<>();
propertyHashMap.put("straight", BlockProperty.STRAIGHT);
propertyHashMap.put("inner_left", BlockProperty.INNER_LEFT);
propertyHashMap.put("inner_right", BlockProperty.INNER_RIGHT);
propertyHashMap.put("outer_left", BlockProperty.OUTER_LEFT);
propertyHashMap.put("outer_right", BlockProperty.OUTER_RIGHT);
propertyHashMap.put("north_south", BlockProperty.NORTH_SOUTH);
propertyHashMap.put("east_west", BlockProperty.EAST_WEST);
propertyHashMap.put("south_east", BlockProperty.SOUTH_EAST);
propertyHashMap.put("south_west", BlockProperty.SOUTH_WEST);
propertyHashMap.put("north_west", BlockProperty.NORTH_WEST);
propertyHashMap.put("north_east", BlockProperty.NORTH_EAST);
propertyHashMap.put("ascending_east", BlockProperty.ASCENDING_EAST);
propertyHashMap.put("ascending_west", BlockProperty.ASCENDING_WEST);
propertyHashMap.put("ascending_north", BlockProperty.ASCENDING_NORTH);
propertyHashMap.put("ascending_south", BlockProperty.ASCENDING_SOUTH);
propertiesMapping.put("shape", propertyHashMap);
rotationMapping.put("0", BlockRotation.SOUTH);
rotationMapping.put("1", BlockRotation.SOUTH_SOUTH_WEST);
rotationMapping.put("2", BlockRotation.SOUTH_WEST);
rotationMapping.put("3", BlockRotation.WEST_SOUTH_WEST);
rotationMapping.put("4", BlockRotation.WEST);
rotationMapping.put("5", BlockRotation.WEST_NORTH_WEST);
rotationMapping.put("6", BlockRotation.NORTH_WEST);
rotationMapping.put("7", BlockRotation.NORTH_NORTH_WEST);
rotationMapping.put("8", BlockRotation.NORTH);
rotationMapping.put("9", BlockRotation.NORTH_NORTH_EAST);
rotationMapping.put("10", BlockRotation.NORTH_EAST);
rotationMapping.put("11", BlockRotation.EAST_NORTH_EAST);
rotationMapping.put("12", BlockRotation.EAST);
rotationMapping.put("13", BlockRotation.EAST_SOUTH_EAST);
rotationMapping.put("14", BlockRotation.SOUTH_EAST);
rotationMapping.put("15", BlockRotation.SOUTH_SOUTH_EAST);
rotationMapping.put("south", BlockRotation.SOUTH);
rotationMapping.put("east", BlockRotation.EAST);
rotationMapping.put("north", BlockRotation.NONE);
rotationMapping.put("west", BlockRotation.WEST);
rotationMapping.put("up", BlockRotation.UP);
rotationMapping.put("down", BlockRotation.DOWN);
rotationMapping.put("ascending_east", BlockRotation.ASCENDING_EAST);
rotationMapping.put("ascending_west", BlockRotation.ASCENDING_WEST);
rotationMapping.put("ascending_north", BlockRotation.ASCENDING_NORTH);
rotationMapping.put("ascending_south", BlockRotation.ASCENDING_SOUTH);
rotationMapping.put("north_south", BlockRotation.NORTH_SOUTH);
rotationMapping.put("east_west", BlockRotation.EAST_WEST);
final int id;
final int data;
Blocks(int id, int data) {
this.id = id;
this.data = data;
}
Blocks(int id, Color color) {
// used for wool, etc
this.id = id;
this.data = color.getId();
public static Block getBlockByLegacy(int protocolId, int protocolMetaData) {
int itemId = protocolId << 4 | protocolMetaData;
return getBlock(itemId, ProtocolVersion.VERSION_1_12_2);
}
Blocks(Blocks block, Color color) {
// used for wool, etc
this.id = block.getId();
this.data = color.getId();
public static Block getBlockByLegacy(int itemIdAndMetaData) {
return getBlock(itemIdAndMetaData, ProtocolVersion.VERSION_1_12_2);
}
Blocks(Blocks block, int data) {
// used for existing blocks with different data values
this.id = block.getId();
this.data = data;
public static Block getBlock(int protocolId, ProtocolVersion version) {
if (version.getVersionNumber() < ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
version = ProtocolVersion.VERSION_1_12_2;
}
return blockMap.get(version).get(protocolId);
}
Blocks(int id) {
this.id = id;
this.data = 0;
}
public static void load(String mod, JSONObject json, ProtocolVersion version) {
BiMap<Integer, Block> versionMapping = HashBiMap.create();
for (Iterator<String> identifiers = json.keys(); identifiers.hasNext(); ) {
String identifierName = identifiers.next();
JSONObject identifierJSON = json.getJSONObject(identifierName);
JSONArray statesArray = identifierJSON.getJSONArray("states");
for (int i = 0; i < statesArray.length(); i++) {
JSONObject statesJSON = statesArray.getJSONObject(i);
if (statesJSON.has("properties")) {
// properties are optional
JSONObject propertiesJSON = statesJSON.getJSONObject("properties");
BlockRotation rotation = BlockRotation.NONE;
if (propertiesJSON.has("facing")) {
rotation = rotationMapping.get(propertiesJSON.getString("facing"));
propertiesJSON.remove("facing");
public static Blocks byId(int id, int data) {
for (Blocks b : values()) {
if (b.getId() == id && b.getData() == data) {
return b;
} else if (propertiesJSON.has("rotation")) {
rotation = rotationMapping.get(propertiesJSON.getString("rotation"));
propertiesJSON.remove("rotation");
}
BlockProperty[] properties = new BlockProperty[propertiesJSON.length()];
int ii = 0;
for (Iterator<String> it = propertiesJSON.keys(); it.hasNext(); ) {
String propertyName = it.next();
if (propertiesMapping.get(propertyName) == null) {
throw new RuntimeException(String.format("Unknown block property: %s (identifier=%s)", propertyName, identifierName));
}
if (propertiesMapping.get(propertyName).get(propertiesJSON.getString(propertyName)) == null) {
throw new RuntimeException(String.format("Unknown block property: %s -> %s (identifier=%s)", propertyName, propertiesJSON.getString(propertyName), identifierName));
}
properties[ii] = propertiesMapping.get(propertyName).get(propertiesJSON.getString(propertyName));
ii++;
}
Block block = getBlock(mod, identifierName, properties, rotation);
if (block == null) {
// does not exist. create
block = new Block(mod, identifierName, properties, rotation);
blockList.add(block);
}
versionMapping.put(getBlockId(statesJSON, version), block);
} else {
// no properties, directly add block
Block block = getBlock(mod, identifierName);
if (block == null) {
// does not exist. create
block = new Block(mod, identifierName);
blockList.add(block);
}
versionMapping.put(getBlockId(statesJSON, version), block);
}
}
}
return UNKNOWN;
blockMap.put(version, versionMapping);
}
public static Blocks byId(int id) {
return byId(id, 0);
private static int getBlockId(JSONObject json, ProtocolVersion version) {
int blockId = json.getInt("id");
if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
// old format (with metadata)
blockId <<= 4;
if (json.has("meta")) {
blockId |= json.getInt("meta");
}
}
return blockId;
}
public static Block getBlock(String mod, String identifier) {
for (Block item : blockList) {
if (item.getMod().equals(mod) && item.getIdentifier().equals(identifier)) {
return item;
}
}
return null;
}
public static Block getBlock(String mod, String identifier, BlockProperty[] properties, BlockRotation rotation) {
for (Block block : blockList) {
if (block.getMod().equals(mod) && block.getIdentifier().equals(identifier) && block.getRotation() == rotation && propertiesEquals(block.getProperties(), properties)) {
return block;
}
}
return null;
}
public static boolean propertiesEquals(BlockProperty[] one, BlockProperty[] two) {
if (one.length != two.length) {
return false;
}
for (BlockProperty property : one) {
if (!containsElement(two, property)) {
return false;
}
}
return true;
}
public static boolean containsElement(BlockProperty[] arr, BlockProperty value) {
for (BlockProperty property : arr) {
if (property == value)
return true;
}
return false;
}
public int getId() {
return id;
}
public int getData() {
return data;
public static int getBlockId(Block item, ProtocolVersion version) {
int itemId = blockMap.get(version).inverse().get(item);
if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
return itemId >> 4;
}
return itemId;
}
}

View File

@ -27,15 +27,15 @@ public class Items {
static ArrayList<Item> itemList = new ArrayList<>();
static HashMap<ProtocolVersion, BiMap<Integer, Item>> itemMap = new HashMap<>(); // version -> (protocolId > Item)
public static Item getItemByLegacy(int protocolId, int protocolMetaData, ProtocolVersion version) {
public static Item getItemByLegacy(int protocolId, int protocolMetaData) {
int itemId = protocolId << 4;
if (protocolMetaData > 0 && protocolMetaData <= 15) {
itemId |= protocolMetaData;
}
Item item = getItem(itemId, version);
Item item = getItem(itemId, ProtocolVersion.VERSION_1_12_2);
if (item == null) {
// ignore meta data?
return getItem(protocolId << 4, version);
return getItem(protocolId << 4, ProtocolVersion.VERSION_1_12_2);
}
return item;
}
@ -55,15 +55,13 @@ public class Items {
itemList.add(item);
}
JSONObject identifierJSON = json.getJSONObject(identifierName);
int itemId;
int itemId = identifierJSON.getInt("id");
if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
// old format (with metadata)
itemId = identifierJSON.getInt("protocol_id") << 4;
if (identifierJSON.has("protocol_meta")) {
itemId |= identifierJSON.getInt("protocol_meta");
itemId <<= 4;
if (identifierJSON.has("meta")) {
itemId |= identifierJSON.getInt("meta");
}
} else {
itemId = identifierJSON.getInt("protocol_id");
}
versionMapping.put(itemId, item);
}
@ -80,7 +78,11 @@ public class Items {
}
public static int getItemId(Item item, ProtocolVersion version) {
return itemMap.get(version).inverse().get(item);
int itemId = itemMap.get(version).inverse().get(item);
if (version.getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
return itemId >> 4;
}
return itemId;
}
}

View File

@ -12,6 +12,7 @@
*/
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
@ -24,20 +25,20 @@ public class EndermanMetaData extends MobMetaData {
}
public Blocks getCarriedBlock() {
public Block getCarriedBlock() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return Blocks.byId((short) sets.get(16).getData(), (byte) sets.get(17).getData());
return Blocks.getBlockByLegacy((short) sets.get(16).getData(), (byte) sets.get(17).getData());
case VERSION_1_9_4:
return (Blocks) sets.get(11).getData();
return (Block) sets.get(11).getData();
case VERSION_1_10:
case VERSION_1_11_2:
case VERSION_1_12_2:
case VERSION_1_13_2:
return (Blocks) sets.get(12).getData();
return (Block) sets.get(12).getData();
}
return Blocks.AIR;
return Blocks.nullBlock;
}
public boolean isScreaming() {

View File

@ -107,7 +107,11 @@ public class EntityMetaData {
break;
case BLOCK_ID:
int blockId = buffer.readVarInt();
data = Blocks.byId(blockId >> 4, blockId & 0xF);
if (buffer.getVersion().getVersionNumber() <= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
data = Blocks.getBlockByLegacy(blockId);
} else {
data = Blocks.getBlock(blockId, buffer.getVersion());
}
break;
default:
throw new IllegalStateException("Unexpected value: " + type);

View File

@ -12,6 +12,7 @@
*/
package de.bixilon.minosoft.game.datatypes.entities.meta;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
@ -71,20 +72,20 @@ public class MinecartMetaData extends EntityMetaData {
return 0;
}
public Blocks getBlock() {
public Block getBlock() {
switch (version) {
case VERSION_1_7_10:
case VERSION_1_8:
return Blocks.byId((int) sets.get(20).getData() & 0xFF, (int) sets.get(20).getData() >>> 4);
return Blocks.getBlockByLegacy((int) sets.get(20).getData());
case VERSION_1_9_4:
return Blocks.byId((int) sets.get(8).getData() & 0xFF, (int) sets.get(8).getData() >>> 4);
return Blocks.getBlockByLegacy((int) sets.get(8).getData());
case VERSION_1_10:
case VERSION_1_11_2:
case VERSION_1_12_2:
case VERSION_1_13_2:
return Blocks.byId((int) sets.get(9).getData() & 0xFF, (int) sets.get(9).getData() >>> 4);
return Blocks.getBlock((int) sets.get(9).getData(), version);
}
return Blocks.AIR;
return Blocks.nullBlock;
}
public int getBlockYPosition() {

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
@ -22,24 +23,24 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import java.util.HashMap;
public class FallingBlock extends EntityObject implements ObjectInterface {
final Blocks block;
final Block block;
FallingBlockMetaData metaData;
public FallingBlock(int entityId, Location location, short yaw, short pitch, int additionalInt) {
super(entityId, location, yaw, pitch, null);
// objects do not spawn with metadata... reading additional info from the following int
block = Blocks.byId(additionalInt & 0xFFF, additionalInt >>> 12);
block = Blocks.getBlockByLegacy(additionalInt & 0xFFF, additionalInt >>> 12);
}
public FallingBlock(int entityId, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
super(entityId, location, yaw, pitch, velocity);
block = Blocks.byId(additionalInt & 0xFFF, additionalInt >>> 12);
block = Blocks.getBlockByLegacy(additionalInt & 0xFFF, additionalInt >>> 12);
}
public FallingBlock(int entityId, Location location, short yaw, short pitch, Velocity velocity, HashMap<Integer, EntityMetaData.MetaDataSet> sets, ProtocolVersion version) {
super(entityId, location, yaw, pitch, velocity);
this.metaData = new FallingBlockMetaData(sets, version);
block = Blocks.UNKNOWN; // ToDo
block = Blocks.nullBlock; // ToDo
}
@ -68,7 +69,7 @@ public class FallingBlock extends EntityObject implements ObjectInterface {
return 0.98F;
}
public Blocks getBlock() {
public Block getBlock() {
// ToDo depends on protocol version
return block;
}

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.game.datatypes.world;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import java.util.HashMap;
import java.util.Map;
@ -28,7 +28,7 @@ public class Chunk {
this.nibbles = chunks;
}
public Blocks getBlock(int x, int y, int z) {
public Block getBlock(int x, int y, int z) {
if (x > 15 || y > 255 || z > 15 || x < 0 || y < 0 || z < 0) {
throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z));
}
@ -36,17 +36,17 @@ public class Chunk {
return nibbles.get(section).getBlock(x, y % 16, z);
}
public Blocks getBlock(InChunkLocation location) {
public Block getBlock(InChunkLocation location) {
return getBlock(location.getX(), location.getY(), location.getZ());
}
public void setBlock(int x, int y, int z, Blocks block) {
public void setBlock(int x, int y, int z, Block block) {
byte section = (byte) (y / 16);
createSection(section);
nibbles.get(section).setBlock(x, y % 16, z, block);
}
public void setBlock(InChunkLocation location, Blocks block) {
public void setBlock(InChunkLocation location, Block block) {
byte section = (byte) (location.getY() / 16);
createSection(section);
nibbles.get(section).setBlock(location.getChunkNibbleLocation(), block);
@ -59,8 +59,8 @@ public class Chunk {
}
}
public void setBlocks(HashMap<InChunkLocation, Blocks> blocks) {
for (Map.Entry<InChunkLocation, Blocks> set : blocks.entrySet()) {
public void setBlocks(HashMap<InChunkLocation, Block> blocks) {
for (Map.Entry<InChunkLocation, Block> set : blocks.entrySet()) {
setBlock(set.getKey(), set.getValue());
}
}

View File

@ -13,7 +13,7 @@
package de.bixilon.minosoft.game.datatypes.world;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import java.util.HashMap;
@ -21,9 +21,9 @@ import java.util.HashMap;
* Collection of 16x16x16 blocks
*/
public class ChunkNibble {
final HashMap<ChunkNibbleLocation, Blocks> blocks;
final HashMap<ChunkNibbleLocation, Block> blocks;
public ChunkNibble(HashMap<ChunkNibbleLocation, Blocks> blocks) {
public ChunkNibble(HashMap<ChunkNibbleLocation, Block> blocks) {
this.blocks = blocks;
}
@ -32,19 +32,19 @@ public class ChunkNibble {
this.blocks = new HashMap<>();
}
public Blocks getBlock(ChunkNibbleLocation loc) {
public Block getBlock(ChunkNibbleLocation loc) {
return blocks.get(loc);
}
public Blocks getBlock(int x, int y, int z) {
public Block getBlock(int x, int y, int z) {
return getBlock(new ChunkNibbleLocation(x, y, z));
}
public void setBlock(int x, int y, int z, Blocks block) {
public void setBlock(int x, int y, int z, Block block) {
blocks.put(new ChunkNibbleLocation(x, y, z), block);
}
public void setBlock(ChunkNibbleLocation location, Blocks block) {
public void setBlock(ChunkNibbleLocation location, Block block) {
blocks.put(location, block);
}
}

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.game.datatypes.world;
import de.bixilon.minosoft.game.datatypes.Dimension;
import de.bixilon.minosoft.game.datatypes.TextComponent;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.entities.Entity;
import de.bixilon.minosoft.nbt.tag.CompoundTag;
@ -55,15 +56,15 @@ public class World {
return chunks;
}
public Blocks getBlock(BlockPosition pos) {
public Block getBlock(BlockPosition pos) {
ChunkLocation loc = pos.getChunkLocation();
if (getChunk(loc) != null) {
return getChunk(loc).getBlock(pos.getInChunkLocation());
}
return Blocks.AIR;
return Blocks.nullBlock;
}
public void setBlock(BlockPosition pos, Blocks block) {
public void setBlock(BlockPosition pos, Block block) {
if (getChunk(pos.getChunkLocation()) != null) {
getChunk(pos.getChunkLocation()).setBlock(pos.getInChunkLocation(), block);
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.logging.Log;
@ -22,7 +23,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class PacketBlockChange implements ClientboundPacket {
BlockPosition position;
Blocks block;
Block block;
@Override
@ -30,16 +31,16 @@ public class PacketBlockChange implements ClientboundPacket {
switch (buffer.getVersion()) {
case VERSION_1_7_10:
position = buffer.readBlockPosition();
block = Blocks.byId(buffer.readVarInt(), buffer.readByte());
block = Blocks.getBlockByLegacy(buffer.readVarInt(), buffer.readByte());
return true;
case VERSION_1_8:
case VERSION_1_9_4:
case VERSION_1_10:
case VERSION_1_11_2:
case VERSION_1_12_2:
case VERSION_1_13_2:
position = buffer.readPosition();
int blockId = buffer.readVarInt();
block = Blocks.byId(blockId >>> 4, blockId & 0xF);
block = Blocks.getBlock(buffer.readVarInt(), buffer.getVersion());
return true;
}
@ -48,7 +49,7 @@ public class PacketBlockChange implements ClientboundPacket {
@Override
public void log() {
Log.protocol(String.format("Block change received at %s (block=%s)", position.toString(), block.name()));
Log.protocol(String.format("Block change received at %s (block=%s)", position.toString(), block));
}
@Override
@ -60,7 +61,7 @@ public class PacketBlockChange implements ClientboundPacket {
return position;
}
public Blocks getBlock() {
public Block getBlock() {
return block;
}
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.world.ChunkLocation;
import de.bixilon.minosoft.game.datatypes.world.InChunkLocation;
@ -24,7 +25,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import java.util.HashMap;
public class PacketMultiBlockChange implements ClientboundPacket {
final HashMap<InChunkLocation, Blocks> blocks = new HashMap<>();
final HashMap<InChunkLocation, Block> blocks = new HashMap<>();
ChunkLocation location;
@Override
@ -44,7 +45,7 @@ public class PacketMultiBlockChange implements ClientboundPacket {
byte y = (byte) ((raw & 0xFF_00_00) >>> 16);
byte z = (byte) ((raw & 0x0F_00_00_00) >>> 24);
byte x = (byte) ((raw & 0xF0_00_00_00) >>> 28);
blocks.put(new InChunkLocation(x, y, z), Blocks.byId(blockId, meta));
blocks.put(new InChunkLocation(x, y, z), Blocks.getBlockByLegacy(blockId, meta));
}
return true;
}
@ -60,7 +61,7 @@ public class PacketMultiBlockChange implements ClientboundPacket {
byte pos = buffer.readByte();
byte y = buffer.readByte();
int blockId = buffer.readVarInt();
blocks.put(new InChunkLocation(((pos & 0xF0) >>> 4), y, (pos & 0xF)), Blocks.byId((blockId >>> 4), (blockId & 0xF)));
blocks.put(new InChunkLocation(((pos & 0xF0) >>> 4), y, (pos & 0xF)), Blocks.getBlock(blockId, buffer.getVersion()));
}
return true;
}
@ -83,7 +84,7 @@ public class PacketMultiBlockChange implements ClientboundPacket {
return location;
}
public HashMap<InChunkLocation, Blocks> getBlocks() {
public HashMap<InChunkLocation, Block> getBlocks() {
return blocks;
}
}

View File

@ -277,7 +277,7 @@ public class InByteBuffer {
byte count = readByte();
short metaData = readShort();
CompoundTag nbt = readNBT(version == ProtocolVersion.VERSION_1_7_10);
return new Slot(Items.getItemByLegacy(id, metaData, version), count, metaData, nbt);
return new Slot(Items.getItemByLegacy(id, metaData), count, metaData, nbt);
case VERSION_1_13_2:
if (readBoolean()) {
return new Slot(Items.getItem(readVarInt(), version), readByte(), readNBT());

View File

@ -391,7 +391,7 @@ public class PacketHandler {
int y = ((int) pkg.getLocation().getY()) + record[1];
int z = ((int) pkg.getLocation().getY()) + record[2];
BlockPosition blockPosition = new BlockPosition(x, (short) y, z);
connection.getPlayer().getWorld().setBlock(blockPosition, Blocks.AIR);
connection.getPlayer().getWorld().setBlock(blockPosition, Blocks.nullBlock);
}
// ToDo: motion support
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.util;
import de.bixilon.minosoft.game.datatypes.blocks.Block;
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.world.Chunk;
import de.bixilon.minosoft.game.datatypes.world.ChunkNibble;
@ -53,7 +54,7 @@ public class ChunkUtil {
for (byte c = 0; c < 16; c++) { // max sections per chunks in chunk column
if (BitByte.isBitSet(sectionBitMask, c)) {
HashMap<ChunkNibbleLocation, Blocks> blockMap = new HashMap<>();
HashMap<ChunkNibbleLocation, Block> blockMap = new HashMap<>();
for (int nibbleY = 0; nibbleY < 16; nibbleY++) {
for (int nibbleZ = 0; nibbleZ < 16; nibbleZ++) {
@ -79,8 +80,8 @@ public class ChunkUtil {
// ToDo light, biome
Blocks block = Blocks.byId(singeBlockId, singleMeta);
if (block == Blocks.AIR) {
Block block = Blocks.getBlockByLegacy(singeBlockId, singleMeta);
if (block == Blocks.nullBlock) {
arrayPos++;
continue;
}
@ -124,13 +125,13 @@ public class ChunkUtil {
if (!BitByte.isBitSet(sectionBitMask, c)) {
continue;
}
HashMap<ChunkNibbleLocation, Blocks> blockMap = new HashMap<>();
HashMap<ChunkNibbleLocation, Block> blockMap = new HashMap<>();
for (int nibbleY = 0; nibbleY < 16; nibbleY++) {
for (int nibbleZ = 0; nibbleZ < 16; nibbleZ++) {
for (int nibbleX = 0; nibbleX < 16; nibbleX++) {
Blocks block = Blocks.byId(blockData[arrayPos] >>> 4, blockData[arrayPos] & 0xF);
if (block == Blocks.AIR) {
Block block = Blocks.getBlockByLegacy(blockData[arrayPos]);
if (block == Blocks.nullBlock) {
arrayPos++;
continue;
}
@ -176,7 +177,7 @@ public class ChunkUtil {
long[] data = buffer.readLongs(buffer.readVarInt());
HashMap<ChunkNibbleLocation, Blocks> blockMap = new HashMap<>();
HashMap<ChunkNibbleLocation, Block> blockMap = new HashMap<>();
for (int nibbleY = 0; nibbleY < 16; nibbleY++) {
for (int nibbleZ = 0; nibbleZ < 16; nibbleZ++) {
for (int nibbleX = 0; nibbleX < 16; nibbleX++) {
@ -203,14 +204,14 @@ public class ChunkUtil {
// you're probably reading light data instead
blockId = palette[blockId];
}
Blocks block;
Block block;
if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_13_2.getVersionNumber()) {
// no meta data anymore
block = Blocks.byId(blockId);
block = Blocks.getBlock(blockId, buffer.getVersion());
} else {
block = Blocks.byId(blockId >>> 4, blockId & 0xF);
block = Blocks.getBlockByLegacy(blockId >>> 4, blockId & 0xF);
}
if (block == Blocks.AIR) {
if (block == Blocks.nullBlock) {
continue;
}
blockMap.put(new ChunkNibbleLocation(nibbleX, nibbleY, nibbleZ), block);

View File

@ -0,0 +1,237 @@
{
"minecraft": {
"air": {
"states": [
{
"id": 0
}
]
},
"stone": {
"states": [
{
"id": 1,
"meta": 0
}
]
},
"granite": {
"states": [
{
"id": 1,
"meta": 1
}
]
},
"polished_granite": {
"states": [
{
"id": 1,
"meta": 2
}
]
},
"diorite": {
"states": [
{
"id": 1,
"meta": 3
}
]
},
"polished_diorite": {
"states": [
{
"id": 1,
"meta": 4
}
]
},
"andesite": {
"states": [
{
"id": 1,
"meta": 5
}
]
},
"polished_andesite": {
"states": [
{
"id": 1,
"meta": 6
}
]
},
"grass_block": {
"states": [
{
"id": 2
}
]
},
"dirt": {
"states": [
{
"id": 3
}
]
},
"cobblestone": {
"states": [
{
"id": 4
}
]
},
"bedrock": {
"states": [
{
"id": 7
}
]
},
"glass": {
"states": [
{
"id": 20
}
]
},
"white_wool": {
"states": [
{
"id": 35,
"meta": 0
}
]
},
"orange_wool": {
"states": [
{
"id": 35,
"meta": 1
}
]
},
"magenta_wool": {
"states": [
{
"id": 35,
"meta": 2
}
]
},
"light_blue_wool": {
"states": [
{
"id": 35,
"meta": 3
}
]
},
"yellow_wool": {
"states": [
{
"id": 35,
"meta": 4
}
]
},
"lime_wool": {
"states": [
{
"id": 35,
"meta": 5
}
]
},
"pink_wool": {
"states": [
{
"id": 35,
"meta": 6
}
]
},
"gray_wool": {
"states": [
{
"id": 35,
"meta": 7
}
]
},
"light_gray_wool": {
"states": [
{
"id": 35,
"meta": 8
}
]
},
"cyan_wool": {
"states": [
{
"id": 35,
"meta": 9
}
]
},
"purple_wool": {
"states": [
{
"id": 35,
"meta": 10
}
]
},
"blue_wool": {
"states": [
{
"id": 35,
"meta": 11
}
]
},
"brown_wool": {
"states": [
{
"id": 35,
"meta": 12
}
]
},
"green_wool": {
"states": [
{
"id": 35,
"meta": 13
}
]
},
"red_wool": {
"states": [
{
"id": 35,
"meta": 14
}
]
},
"black_wool": {
"states": [
{
"id": 35,
"meta": 15
}
]
},
"tnt": {
"states": [
{
"id": 46
}
]
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long