mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-27 04:25:12 +01:00
Merge master
This commit is contained in:
commit
d9c25b1acc
5
LICENSE
5
LICENSE
@ -1,9 +1,6 @@
|
|||||||
License:
|
|
||||||
--------
|
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2017
|
Copyright (c) 2019
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerItemBreakEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.CraftingInventory;
|
import org.bukkit.inventory.CraftingInventory;
|
||||||
@ -91,6 +92,11 @@ public class ArmorListener extends ViaBukkitListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onItemBreak(PlayerItemBreakEvent e) {
|
||||||
|
sendDelayedArmorUpdate(e.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
public void onJoin(PlayerJoinEvent e) {
|
||||||
sendDelayedArmorUpdate(e.getPlayer());
|
sendDelayedArmorUpdate(e.getPlayer());
|
||||||
|
@ -30,6 +30,9 @@ public class BungeeChannelInitializer extends ChannelInitializer<SocketChannel>
|
|||||||
new ProtocolPipeline(info);
|
new ProtocolPipeline(info);
|
||||||
// Add originals
|
// Add originals
|
||||||
this.method.invoke(this.original, socketChannel);
|
this.method.invoke(this.original, socketChannel);
|
||||||
|
|
||||||
|
if (socketChannel.pipeline().get("packet-encoder") == null) return; // Don't inject if no packet-encoder
|
||||||
|
if (socketChannel.pipeline().get("packet-decoder") == null) return; // Don't inject if no packet-decoder
|
||||||
// Add our transformers
|
// Add our transformers
|
||||||
BungeeEncodeHandler encoder = new BungeeEncodeHandler(info);
|
BungeeEncodeHandler encoder = new BungeeEncodeHandler(info);
|
||||||
BungeeDecodeHandler decoder = new BungeeDecodeHandler(info);
|
BungeeDecodeHandler decoder = new BungeeDecodeHandler(info);
|
||||||
|
@ -67,11 +67,12 @@ public class NibbleArray {
|
|||||||
* @param value The desired value
|
* @param value The desired value
|
||||||
*/
|
*/
|
||||||
public void set(int index, int value) {
|
public void set(int index, int value) {
|
||||||
index /= 2;
|
|
||||||
if (index % 2 == 0) {
|
if (index % 2 == 0) {
|
||||||
handle[index] = (byte) (handle[index] & 0xF0 | value & 0xF);
|
index /= 2;
|
||||||
|
handle[index] = (byte) ((handle[index] & 0xF0) | (value & 0xF));
|
||||||
} else {
|
} else {
|
||||||
handle[index] = (byte) (handle[index] & 0xF | (value & 0xF) << 4);
|
index /= 2;
|
||||||
|
handle[index] = (byte) ((handle[index] & 0xF) | ((value & 0xF) << 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,9 @@ public class MetadataRewriter {
|
|||||||
// Handle AreaEffectCloud outside the loop
|
// Handle AreaEffectCloud outside the loop
|
||||||
if (type != null && type.is(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) && particleId != -1) {
|
if (type != null && type.is(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD) && particleId != -1) {
|
||||||
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2});
|
||||||
|
if (particle != null && particle.getId() != -1) {
|
||||||
metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle));
|
metadatas.add(new Metadata(9, MetaType1_13.PARTICLE, particle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -162,7 +162,6 @@ public class ConnectionData {
|
|||||||
|
|
||||||
List<ConnectorInitAction> initActions = new ArrayList<>();
|
List<ConnectorInitAction> initActions = new ArrayList<>();
|
||||||
initActions.add(PumpkinConnectionHandler.init());
|
initActions.add(PumpkinConnectionHandler.init());
|
||||||
initActions.add(MelonConnectionHandler.init());
|
|
||||||
initActions.addAll(BasicFenceConnectionHandler.init());
|
initActions.addAll(BasicFenceConnectionHandler.init());
|
||||||
initActions.add(NetherFenceConnectionHandler.init());
|
initActions.add(NetherFenceConnectionHandler.init());
|
||||||
initActions.addAll(WallConnectionHandler.init());
|
initActions.addAll(WallConnectionHandler.init());
|
||||||
@ -175,6 +174,7 @@ public class ConnectionData {
|
|||||||
initActions.add(FlowerConnectionHandler.init());
|
initActions.add(FlowerConnectionHandler.init());
|
||||||
initActions.addAll(ChorusPlantConnectionHandler.init());
|
initActions.addAll(ChorusPlantConnectionHandler.init());
|
||||||
initActions.add(TripwireConnectionHandler.init());
|
initActions.add(TripwireConnectionHandler.init());
|
||||||
|
initActions.add(SnowyGrassConnectionHandler.init());
|
||||||
for (String key : keyToId.keySet()) {
|
for (String key : keyToId.keySet()) {
|
||||||
WrappedBlockData wrappedBlockData = WrappedBlockData.fromString(key);
|
WrappedBlockData wrappedBlockData = WrappedBlockData.fromString(key);
|
||||||
for (ConnectorInitAction action : initActions) {
|
for (ConnectorInitAction action : initActions) {
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.Pair;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.BlockFace;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class SnowyGrassConnectionHandler extends ConnectionHandler {
|
||||||
|
private static Map<Pair<Integer, Boolean>, Integer> grassBlocks = new HashMap<>();
|
||||||
|
private static Set<Integer> snows = new HashSet<>();
|
||||||
|
|
||||||
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
|
final Set<String> snowyGrassBlocks = new HashSet<>();
|
||||||
|
snowyGrassBlocks.add("minecraft:grass_block");
|
||||||
|
snowyGrassBlocks.add("minecraft:podzol");
|
||||||
|
snowyGrassBlocks.add("minecraft:mycelium");
|
||||||
|
|
||||||
|
final SnowyGrassConnectionHandler handler = new SnowyGrassConnectionHandler();
|
||||||
|
return new ConnectionData.ConnectorInitAction() {
|
||||||
|
@Override
|
||||||
|
public void check(WrappedBlockData blockData) {
|
||||||
|
if (snowyGrassBlocks.contains(blockData.getMinecraftKey())) {
|
||||||
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
||||||
|
blockData.set("snowy", "true");
|
||||||
|
grassBlocks.put(new Pair<>(blockData.getSavedBlockStateId(), true), blockData.getBlockStateId());
|
||||||
|
blockData.set("snowy", "false");
|
||||||
|
grassBlocks.put(new Pair<>(blockData.getSavedBlockStateId(), false), blockData.getBlockStateId());
|
||||||
|
}
|
||||||
|
if (blockData.getMinecraftKey().equals("minecraft:snow") || blockData.getMinecraftKey().equals("minecraft:snow_block")) {
|
||||||
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
|
||||||
|
snows.add(blockData.getSavedBlockStateId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int connect(UserConnection user, Position position, int blockState) {
|
||||||
|
int blockUpId = getBlockData(user, position.getRelative(BlockFace.TOP));
|
||||||
|
Integer newId = grassBlocks.get(new Pair<>(blockState, snows.contains(blockUpId)));
|
||||||
|
if (newId != null) {
|
||||||
|
return newId;
|
||||||
|
}
|
||||||
|
return blockState;
|
||||||
|
}
|
||||||
|
}
|
@ -67,7 +67,7 @@ public class MappingData {
|
|||||||
String[] keyAndTranslation = line.split("=", 2);
|
String[] keyAndTranslation = line.split("=", 2);
|
||||||
if (keyAndTranslation.length != 2) continue;
|
if (keyAndTranslation.length != 2) continue;
|
||||||
String key = keyAndTranslation[0];
|
String key = keyAndTranslation[0];
|
||||||
String translation = keyAndTranslation[1];
|
String translation = keyAndTranslation[1].replaceAll("%(\\d\\$)?d", "%$1s");
|
||||||
if (!translateData.containsKey(key)) {
|
if (!translateData.containsKey(key)) {
|
||||||
translateMapping.put(key, translation);
|
translateMapping.put(key, translation);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,11 +11,10 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class ParticleRewriter {
|
public class ParticleRewriter {
|
||||||
private static List<NewParticle> particles = new LinkedList<>();
|
private static List<NewParticle> particles = new LinkedList<>();
|
||||||
private static Random rand = new Random();
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
add(34); // (0->34) explode -> minecraft:poof
|
add(34); // (0->34) explode -> minecraft:poof
|
||||||
@ -108,17 +107,17 @@ public class ParticleRewriter {
|
|||||||
return new ParticleDataHandler() {
|
return new ParticleDataHandler() {
|
||||||
@Override
|
@Override
|
||||||
public Particle handler(Particle particle, Integer[] data) {
|
public Particle handler(Particle particle, Integer[] data) {
|
||||||
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomFloat())); // Red 0 - 1
|
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomBool() ? 1f : 0f)); // Red 0 - 1
|
||||||
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomFloat())); // Green 0 - 1
|
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 0f)); // Green 0 - 1
|
||||||
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomFloat())); // Blue 0 - 1
|
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomBool() ? 1f : 0f)); // Blue 0 - 1
|
||||||
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 1));// Scale 0.01 - 4
|
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 1f));// Scale 0.01 - 4
|
||||||
return particle;
|
return particle;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float randomFloat() {
|
private static boolean randomBool() {
|
||||||
return rand.nextFloat();
|
return ThreadLocalRandom.current().nextBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite IconCrack items to new format :)
|
// Rewrite IconCrack items to new format :)
|
||||||
|
@ -615,7 +615,7 @@ public class InventoryPackets {
|
|||||||
ench.add(enchEntry);
|
ench.add(enchEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tag.remove("Enchantment");
|
tag.remove("Enchantments");
|
||||||
tag.put(ench);
|
tag.put(ench);
|
||||||
}
|
}
|
||||||
if (tag.get("StoredEnchantments") instanceof ListTag) {
|
if (tag.get("StoredEnchantments") instanceof ListTag) {
|
||||||
|
@ -175,12 +175,13 @@ public class WorldPackets {
|
|||||||
|
|
||||||
if (Via.getConfig().isServersideBlockConnections()) {
|
if (Via.getConfig().isServersideBlockConnections()) {
|
||||||
UserConnection userConnection = wrapper.user();
|
UserConnection userConnection = wrapper.user();
|
||||||
|
|
||||||
|
ConnectionData.updateBlockStorage(userConnection, position, newId);
|
||||||
|
|
||||||
if (ConnectionData.connects(newId)) {
|
if (ConnectionData.connects(newId)) {
|
||||||
newId = ConnectionData.connect(userConnection, position, newId);
|
newId = ConnectionData.connect(userConnection, position, newId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionData.updateBlockStorage(userConnection, position, newId);
|
|
||||||
|
|
||||||
ConnectionData.update(userConnection, position);
|
ConnectionData.update(userConnection, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,15 +416,20 @@ public class WorldPackets {
|
|||||||
if (particle.getId() == 11) {
|
if (particle.getId() == 11) {
|
||||||
int count = wrapper.get(Type.INT, 1);
|
int count = wrapper.get(Type.INT, 1);
|
||||||
float speed = wrapper.get(Type.FLOAT, 6);
|
float speed = wrapper.get(Type.FLOAT, 6);
|
||||||
// Only handle for count = 0 & speed = 1
|
// Only handle for count = 0
|
||||||
if (count == 0 && speed == 1) {
|
if (count == 0) {
|
||||||
wrapper.set(Type.INT, 1, 1);
|
wrapper.set(Type.INT, 1, 1);
|
||||||
wrapper.set(Type.FLOAT, 6, 0f);
|
wrapper.set(Type.FLOAT, 6, 0f);
|
||||||
|
|
||||||
List<Particle.ParticleData> arguments = particle.getArguments();
|
List<Particle.ParticleData> arguments = particle.getArguments();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
//RGB values are represented by the X/Y/Z offset
|
//RGB values are represented by the X/Y/Z offset
|
||||||
arguments.get(i).setValue(wrapper.get(Type.FLOAT, i + 3));
|
float colorValue = wrapper.get(Type.FLOAT, i + 3) * speed;
|
||||||
|
if (colorValue == 0 && i == 0) {
|
||||||
|
// https://minecraft.gamepedia.com/User:Alphappy/reddust
|
||||||
|
colorValue = 1;
|
||||||
|
}
|
||||||
|
arguments.get(i).setValue(colorValue);
|
||||||
wrapper.set(Type.FLOAT, i + 3, 0f);
|
wrapper.set(Type.FLOAT, i + 3, 0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,76 +1,136 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.StoredObject;
|
import us.myles.ViaVersion.api.data.StoredObject;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class BlockConnectionStorage extends StoredObject {
|
public class BlockConnectionStorage extends StoredObject {
|
||||||
private Map<Pair<Integer, Integer>, Map<BlockPositon, Integer>> blockStorage = new HashMap<>();
|
private Map<Long, Pair<byte[], NibbleArray>> blockStorage = createLongObjectMap();
|
||||||
|
|
||||||
|
private static Constructor<?> fastUtilLongObjectHashMap;
|
||||||
|
private static HashMap<Short, Short> reverseBlockMappings;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
fastUtilLongObjectHashMap = Class.forName("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap").getConstructor();
|
||||||
|
Via.getPlatform().getLogger().info("Using FastUtil Long2ObjectOpenHashMap for block connections");
|
||||||
|
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
|
||||||
|
}
|
||||||
|
reverseBlockMappings = new HashMap<>();
|
||||||
|
for (int i = 0; i < 4096; i++) {
|
||||||
|
int newBlock = MappingData.blockMappings.getNewBlock(i);
|
||||||
|
if (newBlock != -1) reverseBlockMappings.put((short) newBlock, (short) i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BlockConnectionStorage(UserConnection user) {
|
public BlockConnectionStorage(UserConnection user) {
|
||||||
super(user);
|
super(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void store(Position position, int blockState) {
|
public void store(Position position, int blockState) {
|
||||||
Pair pair = getPair(position);
|
Short mapping = reverseBlockMappings.get((short) blockState);
|
||||||
Map<BlockPositon, Integer> map = getChunkMap(pair);
|
if (mapping == null) return;
|
||||||
map.put(new BlockPositon(position), blockState);
|
blockState = mapping;
|
||||||
|
long pair = getChunkSectionIndex(position);
|
||||||
|
Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
|
||||||
|
int blockIndex = encodeBlockPos(position);
|
||||||
|
map.getKey()[blockIndex] = (byte) (blockState >> 4);
|
||||||
|
NibbleArray nibbleArray = map.getValue();
|
||||||
|
if (nibbleArray != null) nibbleArray.set(blockIndex, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int get(Position position) {
|
public int get(Position position) {
|
||||||
Pair pair = getPair(position);
|
long pair = getChunkSectionIndex(position);
|
||||||
Map<BlockPositon, Integer> map = getChunkMap(pair);
|
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
|
||||||
BlockPositon blockPositon = new BlockPositon(position);
|
if (map == null) return 0;
|
||||||
return map.containsKey(blockPositon) ? map.get(blockPositon) : 0;
|
short blockPosition = encodeBlockPos(position);
|
||||||
|
NibbleArray nibbleArray = map.getValue();
|
||||||
|
return WorldPackets.toNewId(
|
||||||
|
((map.getKey()[blockPosition] & 0xFF) << 4)
|
||||||
|
| (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Position position) {
|
public void remove(Position position) {
|
||||||
Pair pair = getPair(position);
|
long pair = getChunkSectionIndex(position);
|
||||||
Map<BlockPositon, Integer> map = getChunkMap(pair);
|
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
|
||||||
map.remove(new BlockPositon(position));
|
if (map == null) return;
|
||||||
if (map.isEmpty()) {
|
int blockIndex = encodeBlockPos(position);
|
||||||
blockStorage.remove(pair);
|
NibbleArray nibbleArray = map.getValue();
|
||||||
|
if (nibbleArray != null) {
|
||||||
|
nibbleArray.set(blockIndex, 0);
|
||||||
|
boolean allZero = true;
|
||||||
|
for (int i = 0; i < 4096; i++) {
|
||||||
|
if (nibbleArray.get(i) != 0) {
|
||||||
|
allZero = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (allZero) map.setValue(null);
|
||||||
|
}
|
||||||
|
map.getKey()[blockIndex] = 0;
|
||||||
|
for (short entry : map.getKey()) {
|
||||||
|
if (entry != 0) return;
|
||||||
|
}
|
||||||
|
blockStorage.remove(pair);
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
blockStorage.clear();
|
blockStorage.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadChunk(int x, int z) {
|
public void unloadChunk(int x, int z) {
|
||||||
blockStorage.remove(new Pair<>(x, z));
|
for (int y = 0; y < 256; y += 16) {
|
||||||
|
blockStorage.remove(getChunkSectionIndex(x, y, z));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<BlockPositon, Integer> getChunkMap(Pair pair) {
|
private Pair<byte[], NibbleArray> getChunkSection(long index, boolean requireNibbleArray) {
|
||||||
Map<BlockPositon, Integer> map = blockStorage.get(pair);
|
Pair<byte[], NibbleArray> map = blockStorage.get(index);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
map = new HashMap<>();
|
map = new Pair<>(new byte[4096], null);
|
||||||
blockStorage.put(pair, map);
|
blockStorage.put(index, map);
|
||||||
|
}
|
||||||
|
if (map.getValue() == null && requireNibbleArray) {
|
||||||
|
map.setValue(new NibbleArray(4096));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Integer, Integer> getPair(Position position) {
|
private long getChunkSectionIndex(int x, int y, int z) {
|
||||||
int chunkX = (int) (position.getX() >> 4);
|
return (((x >> 4) & 0x3FFFFFFL) << 38) | (((y >> 4) & 0xFFFL) << 26) | ((z >> 4) & 0x3FFFFFFL);
|
||||||
int chunkZ = (int) (position.getZ() >> 4);
|
|
||||||
return new Pair<>(chunkX, chunkZ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EqualsAndHashCode
|
private long getChunkSectionIndex(Position position) {
|
||||||
@Data
|
return getChunkSectionIndex(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue());
|
||||||
private class BlockPositon {
|
}
|
||||||
int x, y, z;
|
|
||||||
|
|
||||||
public BlockPositon(Position position) {
|
private short encodeBlockPos(int x, int y, int z) {
|
||||||
x = position.getX().intValue();
|
return (short) (((y & 0xF) << 8) | ((x & 0xF) << 4) | (z & 0xF));
|
||||||
y = position.getY().intValue();
|
}
|
||||||
z = position.getZ().intValue();
|
|
||||||
|
private short encodeBlockPos(Position pos) {
|
||||||
|
return encodeBlockPos(pos.getX().intValue(), pos.getY().intValue(), pos.getZ().intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Map<Long, T> createLongObjectMap() {
|
||||||
|
if (fastUtilLongObjectHashMap != null) {
|
||||||
|
try {
|
||||||
|
return (Map<Long, T>) fastUtilLongObjectHashMap.newInstance();
|
||||||
|
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user