Merge branch 'master' into inventory

This commit is contained in:
AJ Ferguson 2019-11-30 15:22:50 -09:00
commit 8bb8208a46
12 changed files with 49 additions and 48627 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "connector/src/main/resources/mappings"]
path = connector/src/main/resources/mappings
url = https://github.com/GeyserMC/mappings.git

1
Jenkinsfile vendored
View file

@ -10,6 +10,7 @@ pipeline {
stages { stages {
stage ('Build') { stage ('Build') {
steps { steps {
sh 'git submodule update --init --recursive'
sh 'mvn clean package' sh 'mvn clean package'
} }
post { post {

View file

@ -34,6 +34,8 @@ import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.data.EntityFlags;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.console.GeyserLogger;
@ -69,7 +71,7 @@ public class Entity {
protected boolean valid; protected boolean valid;
protected Set<Long> passengers = new HashSet<>(); protected LongSet passengers = new LongOpenHashSet();
protected Map<AttributeType, Attribute> attributes = new HashMap<>(); protected Map<AttributeType, Attribute> attributes = new HashMap<>();
protected EntityDataDictionary metadata = new EntityDataDictionary(); protected EntityDataDictionary metadata = new EntityDataDictionary();

View file

@ -25,6 +25,10 @@
package org.geysermc.connector.network.session.cache; package org.geysermc.connector.network.session.cache;
import it.unimi.dsi.fastutil.longs.Long2LongMap;
import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
@ -41,8 +45,8 @@ public class EntityCache {
private GeyserSession session; private GeyserSession session;
@Getter @Getter
private Map<Long, Entity> entities = new HashMap<>(); private Long2ObjectMap<Entity> entities = new Long2ObjectOpenHashMap<>();
private Map<Long, Long> entityIdTranslations = new HashMap<>(); private Long2LongMap entityIdTranslations = new Long2LongOpenHashMap();
private Map<UUID, PlayerEntity> playerEntities = new HashMap<>(); private Map<UUID, PlayerEntity> playerEntities = new HashMap<>();
private Map<UUID, Long> bossbars = new HashMap<>(); private Map<UUID, Long> bossbars = new HashMap<>();
@ -62,12 +66,10 @@ public class EntityCache {
public boolean removeEntity(Entity entity, boolean force) { public boolean removeEntity(Entity entity, boolean force) {
if (entity != null && entity.isValid() && (force || entity.despawnEntity(session))) { if (entity != null && entity.isValid() && (force || entity.despawnEntity(session))) {
Long geyserId = entityIdTranslations.remove(entity.getEntityId()); long geyserId = entityIdTranslations.remove(entity.getEntityId());
if (geyserId != null) { entities.remove(geyserId);
entities.remove(geyserId); if (entity.is(PlayerEntity.class)) {
if (entity.is(PlayerEntity.class)) { playerEntities.remove(entity.as(PlayerEntity.class).getUuid());
playerEntities.remove(entity.as(PlayerEntity.class).getUuid());
}
} }
return true; return true;
} }

View file

@ -26,6 +26,8 @@
package org.geysermc.connector.network.session.cache; package org.geysermc.connector.network.session.cache;
import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter; import lombok.Getter;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.api.window.FormWindow; import org.geysermc.api.window.FormWindow;
@ -38,7 +40,7 @@ public class WindowCache {
private GeyserSession session; private GeyserSession session;
@Getter @Getter
private Map<Integer, FormWindow> windows = new HashMap<Integer, FormWindow>(); private Int2ObjectMap<FormWindow> windows = new Int2ObjectOpenHashMap<>();
public WindowCache(GeyserSession session) { public WindowCache(GeyserSession session) {
this.session = session; this.session = session;

View file

@ -79,7 +79,7 @@ public class ItemTranslator {
} }
public ItemEntry getItem(ItemData data) { public ItemEntry getItem(ItemData data) {
for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.valueCollection()) { for (ItemEntry itemEntry : Toolbox.ITEM_ENTRIES.values()) {
if (itemEntry.getBedrockId() == data.getId() && itemEntry.getBedrockData() == data.getDamage()) { if (itemEntry.getBedrockId() == data.getId() && itemEntry.getBedrockData() == data.getDamage()) {
return itemEntry; return itemEntry;
} }

View file

@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.Serve
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ItemEntity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -52,10 +53,16 @@ public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjec
return; return;
} }
Entity entity = new Entity( long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet();
packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), Entity entity;
type, position, motion, rotation switch (type) {
); case ITEM:
entity = new ItemEntity(packet.getEntityId(), geyserId, type, position, motion, rotation);
break;
default:
entity = new Entity(packet.getEntityId(), geyserId, type, position, motion, rotation);
break;
}
session.getEntityCache().spawnEntity(entity); session.getEntityCache().spawnEntity(entity);
} }

View file

@ -8,8 +8,8 @@ import com.nukkitx.nbt.tag.ListTag;
import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import gnu.trove.map.TIntObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.translators.block.BlockEntry; import org.geysermc.connector.network.translators.block.BlockEntry;
@ -26,8 +26,8 @@ public class Toolbox {
public static ListTag<CompoundTag> BLOCKS; public static ListTag<CompoundTag> BLOCKS;
public static ItemData[] CREATIVE_ITEMS; public static ItemData[] CREATIVE_ITEMS;
public static final TIntObjectMap<ItemEntry> ITEM_ENTRIES = new TIntObjectHashMap<>(); public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
public static final TIntObjectMap<BlockEntry> BLOCK_ENTRIES = new TIntObjectHashMap<>(); public static final Int2ObjectMap<BlockEntry> BLOCK_ENTRIES = new Int2ObjectOpenHashMap<>();
public static void init() { public static void init() {
InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat"); InputStream stream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/runtime_block_states.dat");
@ -74,7 +74,7 @@ public class Toolbox {
ITEMS.add(new StartGamePacket.ItemEntry((String) entry.get("name"), (short) ((int) entry.get("id")))); ITEMS.add(new StartGamePacket.ItemEntry((String) entry.get("name"), (short) ((int) entry.get("id"))));
} }
InputStream itemStream = Toolbox.class.getClassLoader().getResourceAsStream("items.json"); InputStream itemStream = Toolbox.class.getClassLoader().getResourceAsStream("mappings/items.json");
ObjectMapper itemMapper = new ObjectMapper(); ObjectMapper itemMapper = new ObjectMapper();
Map<String, Map<String, Object>> items = new HashMap<>(); Map<String, Map<String, Object>> items = new HashMap<>();
@ -90,7 +90,7 @@ public class Toolbox {
itemIndex++; itemIndex++;
} }
InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("blocks.json"); InputStream blockStream = Toolbox.class.getClassLoader().getResourceAsStream("mappings/blocks.json");
ObjectMapper blockMapper = new ObjectMapper(); ObjectMapper blockMapper = new ObjectMapper();
Map<String, Map<String, Object>> blocks = new HashMap<>(); Map<String, Map<String, Object>> blocks = new HashMap<>();

View file

@ -1,12 +1,15 @@
package org.geysermc.connector.world.chunk; package org.geysermc.connector.world.chunk;
import com.nukkitx.network.VarInts; import com.nukkitx.network.VarInts;
import gnu.trove.list.array.TIntArrayList;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.geysermc.connector.world.GlobalBlockPalette; import org.geysermc.connector.world.GlobalBlockPalette;
import org.geysermc.connector.world.chunk.bitarray.BitArray; import org.geysermc.connector.world.chunk.bitarray.BitArray;
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion; import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
import java.util.function.IntConsumer;
/** /**
* Adapted from NukkitX: https://github.com/NukkitX/Nukkit * Adapted from NukkitX: https://github.com/NukkitX/Nukkit
*/ */
@ -14,7 +17,7 @@ public class BlockStorage {
private static final int SIZE = 4096; private static final int SIZE = 4096;
private final TIntArrayList palette; private final IntList palette;
private BitArray bitArray; private BitArray bitArray;
public BlockStorage() { public BlockStorage() {
@ -23,11 +26,11 @@ public class BlockStorage {
public BlockStorage(BitArrayVersion version) { public BlockStorage(BitArrayVersion version) {
this.bitArray = version.createPalette(SIZE); this.bitArray = version.createPalette(SIZE);
this.palette = new TIntArrayList(16, -1); this.palette = new IntArrayList(16);
this.palette.add(0); // Air is at the start of every palette. this.palette.add(0); // Air is at the start of every palette.
} }
private BlockStorage(BitArray bitArray, TIntArrayList palette) { private BlockStorage(BitArray bitArray, IntArrayList palette) {
this.palette = palette; this.palette = palette;
this.bitArray = bitArray; this.bitArray = bitArray;
} }
@ -57,10 +60,7 @@ public class BlockStorage {
} }
VarInts.writeInt(buffer, palette.size()); VarInts.writeInt(buffer, palette.size());
palette.forEach(id -> { palette.forEach((IntConsumer) id -> VarInts.writeInt(buffer, id));
VarInts.writeInt(buffer, id);
return true;
});
} }
private void onResize(BitArrayVersion version) { private void onResize(BitArrayVersion version) {
@ -109,6 +109,6 @@ public class BlockStorage {
} }
public BlockStorage copy() { public BlockStorage copy() {
return new BlockStorage(this.bitArray.copy(), new TIntArrayList(this.palette)); return new BlockStorage(this.bitArray.copy(), new IntArrayList(this.palette));
} }
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

@ -0,0 +1 @@
Subproject commit 5ec6f1f339506129514de59d0e09e9b2c612e8be