Paintings (Motives) flatting update

This commit is contained in:
Bixilon 2020-07-27 13:52:13 +02:00
parent cbf7eaffbd
commit f9fa852231
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 212 additions and 152 deletions

View File

@ -13,32 +13,20 @@
package de.bixilon.minosoft;
import com.google.gson.JsonObject;
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.objectLoader.blockIds.BlockIds;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.objectLoader.enchantments.Enchantments;
import de.bixilon.minosoft.game.datatypes.objectLoader.entities.Entities;
import de.bixilon.minosoft.game.datatypes.objectLoader.items.Items;
import de.bixilon.minosoft.game.datatypes.objectLoader.statistics.Statistics;
import de.bixilon.minosoft.game.datatypes.objectLoader.ObjectLoader;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.logging.LogLevel;
import de.bixilon.minosoft.mojang.api.MojangAccount;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import de.bixilon.minosoft.util.FolderUtil;
import de.bixilon.minosoft.util.OSUtil;
import de.bixilon.minosoft.util.Util;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class Minosoft {
@ -68,7 +56,7 @@ public class Minosoft {
Log.info("Assets checking done");
Log.info("Loading all mappings...");
long mappingsStart = System.currentTimeMillis();
loadMappings();
ObjectLoader.loadMappings();
Log.info(String.format("Mappings loaded within %sms", (System.currentTimeMillis() - mappingsStart)));
checkClientToken();
@ -134,44 +122,6 @@ 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;
}
long startTime = System.currentTimeMillis();
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 (String mod : data.keySet()) {
JsonObject modJSON = data.getAsJsonObject(mod);
switch (mappingSet.getValue()) {
case REGISTRIES:
Items.load(mod, modJSON.getAsJsonObject("item").getAsJsonObject("entries"), version);
Entities.load(mod, modJSON.getAsJsonObject("entity_type").getAsJsonObject("entries"), version);
Enchantments.load(mod, modJSON.getAsJsonObject("enchantment").getAsJsonObject("entries"), version);
Statistics.load(mod, modJSON.getAsJsonObject("custom_stat").getAsJsonObject("entries"), version);
BlockIds.load(mod, modJSON.getAsJsonObject("block").getAsJsonObject("entries"), version);
break;
case BLOCKS:
Blocks.load(mod, modJSON, version);
break;
}
}
}
Log.verbose(String.format("Loaded mappings for version %s in %dms (%s)", version, (System.currentTimeMillis() - startTime), version.getReleaseName()));
}
// end, we must set the nullBlock
Blocks.nullBlock = new Block("minecraft", "air");
} catch (IOException e) {
Log.fatal("Error occurred while loading version mapping: " + e.getLocalizedMessage());
System.exit(1);
}
}
private static void checkAssets() {
try {

View File

@ -1,82 +0,0 @@
/*
* 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.entities;
import de.bixilon.minosoft.game.datatypes.ChangeableIdentifier;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public enum Paintings {
KEBAB(new ChangeableIdentifier("kebab"), 0),
AZTEC(new ChangeableIdentifier("aztec"), 1),
ALBAN(new ChangeableIdentifier("alban"), 2),
AZTEC2(new ChangeableIdentifier("aztec2"), 3),
BOMB(new ChangeableIdentifier("bomb"), 4),
PLANT(new ChangeableIdentifier("plant"), 5),
WASTELAND(new ChangeableIdentifier("wasteland"), 6),
POOL(new ChangeableIdentifier("pool"), 7),
COURBET(new ChangeableIdentifier("courbet"), 8),
SEA(new ChangeableIdentifier("sea"), 9),
SUNSET(new ChangeableIdentifier("sunset"), 10),
CREEBET(new ChangeableIdentifier("creebet"), 11),
WANDERER(new ChangeableIdentifier("wanderer"), 12),
GRAHAM(new ChangeableIdentifier("graham"), 13),
MATCH(new ChangeableIdentifier("match"), 14),
BUST(new ChangeableIdentifier("bust"), 15),
STAGE(new ChangeableIdentifier("stage"), 16),
VOID(new ChangeableIdentifier("void"), 17),
SKULL_AND_ROSES(new ChangeableIdentifier("skull_and_roses"), 18),
WITHER(new ChangeableIdentifier("wither"), 19),
FIGHTERS(new ChangeableIdentifier("fighters"), 20),
POINTER(new ChangeableIdentifier("pointer"), 21),
PIG_SCENE(new ChangeableIdentifier("pigscene"), 22),
BURNING_SKULL(new ChangeableIdentifier("burning_skull"), 23),
SKELETON(new ChangeableIdentifier("skeleton"), 24),
DONKEY_KONG(new ChangeableIdentifier("donkey_kong"), 25);
final ChangeableIdentifier changeableIdentifier;
final int id;
Paintings(ChangeableIdentifier changeableIdentifier, int id) {
this.changeableIdentifier = changeableIdentifier;
this.id = id;
}
public static Paintings byId(int type) {
for (Paintings painting : values()) {
if (painting.getId() == type) {
return painting;
}
}
return null;
}
public static Paintings byName(String name, ProtocolVersion version) {
for (Paintings painting : values()) {
if (painting.getChangeableIdentifier().isValidName(name, version)) {
return painting;
}
}
return null;
}
public int getId() {
return id;
}
public ChangeableIdentifier getChangeableIdentifier() {
return changeableIdentifier;
}
}

View File

@ -13,15 +13,19 @@
package de.bixilon.minosoft.game.datatypes.entities.objects;
import de.bixilon.minosoft.game.datatypes.entities.*;
import de.bixilon.minosoft.game.datatypes.entities.EntityObject;
import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.game.datatypes.entities.ObjectInterface;
import de.bixilon.minosoft.game.datatypes.entities.Velocity;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
import de.bixilon.minosoft.game.datatypes.objectLoader.motives.Motive;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class Painting extends EntityObject implements ObjectInterface {
EntityMetaData metaData;
int direction;
Paintings painting;
Motive motive;
public Painting(int entityId, Location location, short yaw, short pitch, int additionalInt) {
super(entityId, location, yaw, pitch, null);
@ -37,10 +41,10 @@ public class Painting extends EntityObject implements ObjectInterface {
this.metaData = new EntityMetaData(sets, version);
}
public Painting(int entityId, BlockPosition position, int direction, Paintings painting) {
public Painting(int entityId, BlockPosition position, int direction, Motive motive) {
super(entityId, new Location(position.getX(), position.getY(), position.getZ()), (short) 0, (short) 0, null);
this.direction = direction;
this.painting = painting;
this.motive = motive;
}
@Override
@ -65,8 +69,8 @@ public class Painting extends EntityObject implements ObjectInterface {
return 1.0F;
}
public Paintings getPainting() {
return painting;
public Motive getMotive() {
return motive;
}
public int getDirection() {

View File

@ -0,0 +1,75 @@
/*
* 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.objectLoader;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.Config;
import de.bixilon.minosoft.game.datatypes.Mappings;
import de.bixilon.minosoft.game.datatypes.objectLoader.blockIds.BlockIds;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
import de.bixilon.minosoft.game.datatypes.objectLoader.enchantments.Enchantments;
import de.bixilon.minosoft.game.datatypes.objectLoader.entities.Entities;
import de.bixilon.minosoft.game.datatypes.objectLoader.items.Items;
import de.bixilon.minosoft.game.datatypes.objectLoader.motives.Motives;
import de.bixilon.minosoft.game.datatypes.objectLoader.statistics.Statistics;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import de.bixilon.minosoft.util.Util;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ObjectLoader {
public 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;
}
long startTime = System.currentTimeMillis();
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 (String mod : data.keySet()) {
JsonObject modJSON = data.getAsJsonObject(mod);
switch (mappingSet.getValue()) {
case REGISTRIES:
Items.load(mod, modJSON.getAsJsonObject("item").getAsJsonObject("entries"), version);
Entities.load(mod, modJSON.getAsJsonObject("entity_type").getAsJsonObject("entries"), version);
Enchantments.load(mod, modJSON.getAsJsonObject("enchantment").getAsJsonObject("entries"), version);
Statistics.load(mod, modJSON.getAsJsonObject("custom_stat").getAsJsonObject("entries"), version);
BlockIds.load(mod, modJSON.getAsJsonObject("block").getAsJsonObject("entries"), version);
Motives.load(mod, modJSON.getAsJsonObject("motive").getAsJsonObject("entries"), version);
break;
case BLOCKS:
Blocks.load(mod, modJSON, version);
break;
}
}
}
Log.verbose(String.format("Loaded mappings for version %s in %dms (%s)", version, (System.currentTimeMillis() - startTime), version.getReleaseName()));
}
// end, we must set the nullBlock
Blocks.nullBlock = new Block("minecraft", "air");
} catch (IOException e) {
Log.fatal("Error occurred while loading version mapping: " + e.getLocalizedMessage());
System.exit(1);
}
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.objectLoader.motives;
public class Motive {
final String mod;
final String identifier;
public Motive(String mod, String identifier) {
this.mod = mod;
this.identifier = identifier;
}
public String getMod() {
return mod;
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", getMod(), getIdentifier());
}
@Override
public int hashCode() {
return mod.hashCode() * identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (hashCode() != obj.hashCode()) {
return false;
}
Motive their = (Motive) obj;
return getIdentifier().equals(their.getIdentifier()) && getMod().equals(their.getMod());
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.objectLoader.motives;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonObject;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
import java.util.HashMap;
import java.util.HashSet;
public class Motives {
static HashSet<Motive> motiveList = new HashSet<>();
static HashBiMap<String, Motive> motiveIdentifierMap = HashBiMap.create();
static HashMap<ProtocolVersion, HashBiMap<Integer, Motive>> motiveMao = new HashMap<>();
public static Motive byId(int id, ProtocolVersion version) {
return motiveMao.get(version).get(id);
}
// <= 1.12.2
public static Motive byIdentifier(String name) {
return motiveIdentifierMap.get(name);
}
public static void load(String mod, JsonObject json, ProtocolVersion version) {
boolean isIdMap = false;
HashBiMap<Integer, Motive> versionMapping = HashBiMap.create();
for (String identifierName : json.keySet()) {
Motive motive = new Motive(mod, identifierName);
motiveList.add(motive);
JsonObject identifierJSON = json.getAsJsonObject(identifierName);
if (json.getAsJsonObject(identifierName).has("id")) {
versionMapping.put(json.getAsJsonObject(identifierName).get("id").getAsInt(), motive);
isIdMap = true;
} else {
motiveIdentifierMap.put(identifierName, motive);
}
}
if (isIdMap) {
motiveMao.put(version, versionMapping);
}
}
}

View File

@ -13,7 +13,8 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.game.datatypes.entities.Paintings;
import de.bixilon.minosoft.game.datatypes.objectLoader.motives.Motive;
import de.bixilon.minosoft.game.datatypes.objectLoader.motives.Motives;
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
@ -25,7 +26,7 @@ import java.util.UUID;
public class PacketSpawnPainting implements ClientboundPacket {
int entityId;
UUID uuid;
Paintings painting;
Motive motive;
BlockPosition position;
int direction;
@ -34,13 +35,13 @@ public class PacketSpawnPainting implements ClientboundPacket {
switch (buffer.getVersion()) {
case VERSION_1_7_10:
entityId = buffer.readVarInt();
painting = Paintings.byName(buffer.readString(), buffer.getVersion());
motive = Motives.byIdentifier(buffer.readString());
position = buffer.readBlockPositionInteger();
direction = buffer.readInt();
return true;
case VERSION_1_8:
entityId = buffer.readVarInt();
painting = Paintings.byName(buffer.readString(), buffer.getVersion());
motive = Motives.byIdentifier(buffer.readString());
position = buffer.readPosition();
direction = buffer.readByte();
return true;
@ -50,14 +51,14 @@ public class PacketSpawnPainting implements ClientboundPacket {
case VERSION_1_12_2:
entityId = buffer.readVarInt();
uuid = buffer.readUUID();
painting = Paintings.byName(buffer.readString(), buffer.getVersion());
motive = Motives.byIdentifier(buffer.readString());
position = buffer.readPosition();
direction = buffer.readByte();
return true;
default:
entityId = buffer.readVarInt();
uuid = buffer.readUUID();
painting = Paintings.byId(buffer.readVarInt());
motive = Motives.byId(buffer.readVarInt(), buffer.getVersion());
position = buffer.readPosition();
direction = buffer.readByte();
return true;
@ -66,7 +67,7 @@ public class PacketSpawnPainting implements ClientboundPacket {
@Override
public void log() {
Log.protocol(String.format("Spawning painting at %s (entityId=%d, painting=%s, direction=%d)", position, entityId, painting, direction));
Log.protocol(String.format("Spawning painting at %s (entityId=%d, motive=%s, direction=%d)", position, entityId, motive, direction));
}
@Override
@ -78,8 +79,8 @@ public class PacketSpawnPainting implements ClientboundPacket {
return entityId;
}
public Paintings getPainting() {
return painting;
public Motive getMotive() {
return motive;
}
public BlockPosition getPosition() {

View File

@ -454,7 +454,7 @@ public class PacketHandler {
}
public void handle(PacketSpawnPainting pkg) {
connection.getPlayer().getWorld().addEntity(new Painting(pkg.getEntityId(), pkg.getPosition(), pkg.getDirection(), pkg.getPainting()));
connection.getPlayer().getWorld().addEntity(new Painting(pkg.getEntityId(), pkg.getPosition(), pkg.getDirection(), pkg.getMotive()));
}
public void handle(PacketParticle pkg) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long