Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Create soft wrapper for FU IntSet and Int2IntMap
Dieser Commit ist enthalten in:
Ursprung
d58959fcca
Commit
30e10bb645
@ -19,5 +19,13 @@
|
|||||||
<version>1.18</version>
|
<version>1.18</version>
|
||||||
<scope>compile</scope> <!-- Velocity doesn't have snakeyaml -->
|
<scope>compile</scope> <!-- Velocity doesn't have snakeyaml -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- FastUtil for optional performance increases -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>it.unimi.dsi</groupId>
|
||||||
|
<artifactId>fastutil</artifactId>
|
||||||
|
<version>8.3.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -12,6 +12,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
|||||||
import us.myles.ViaVersion.api.storage.EntityTracker;
|
import us.myles.ViaVersion.api.storage.EntityTracker;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -23,7 +25,7 @@ import java.util.logging.Logger;
|
|||||||
public abstract class MetadataRewriter {
|
public abstract class MetadataRewriter {
|
||||||
private final Class<? extends EntityTracker> entityTrackerClass;
|
private final Class<? extends EntityTracker> entityTrackerClass;
|
||||||
private final Protocol protocol;
|
private final Protocol protocol;
|
||||||
private Map<Integer, Integer> typeMapping;
|
private IntMap typeMapping;
|
||||||
|
|
||||||
protected MetadataRewriter(Protocol protocol, Class<? extends EntityTracker> entityTrackerClass) {
|
protected MetadataRewriter(Protocol protocol, Class<? extends EntityTracker> entityTrackerClass) {
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
@ -182,7 +184,7 @@ public abstract class MetadataRewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) {
|
public <T extends Enum<T> & EntityType> void mapTypes(EntityType[] oldTypes, Class<T> newTypeClass) {
|
||||||
if (typeMapping == null) typeMapping = new HashMap<>(oldTypes.length);
|
if (typeMapping == null) typeMapping = CollectionUtil.createIntMap(oldTypes.length);
|
||||||
for (EntityType oldType : oldTypes) {
|
for (EntityType oldType : oldTypes) {
|
||||||
try {
|
try {
|
||||||
T newType = Enum.valueOf(newTypeClass, oldType.name());
|
T newType = Enum.valueOf(newTypeClass, oldType.name());
|
||||||
@ -197,7 +199,7 @@ public abstract class MetadataRewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void mapType(EntityType oldType, EntityType newType) {
|
public void mapType(EntityType oldType, EntityType newType) {
|
||||||
if (typeMapping == null) typeMapping = new HashMap<>();
|
if (typeMapping == null) typeMapping = CollectionUtil.createIntMap();
|
||||||
typeMapping.put(oldType.getId(), newType.getId());
|
typeMapping.put(oldType.getId(), newType.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ import us.myles.ViaVersion.api.type.Type;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.PacketBlockConnectionProvider;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntSet;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -27,7 +29,7 @@ public class ConnectionData {
|
|||||||
static Map<String, Integer> keyToId = new HashMap<>();
|
static Map<String, Integer> keyToId = new HashMap<>();
|
||||||
static Map<Integer, ConnectionHandler> connectionHandlerMap = new HashMap<>();
|
static Map<Integer, ConnectionHandler> connectionHandlerMap = new HashMap<>();
|
||||||
static Map<Integer, BlockData> blockConnectionData = new HashMap<>();
|
static Map<Integer, BlockData> blockConnectionData = new HashMap<>();
|
||||||
static Set<Integer> occludingStates = new HashSet<>();
|
static IntSet occludingStates = CollectionUtil.createIntSet(377);
|
||||||
|
|
||||||
public static void update(UserConnection user, Position position) {
|
public static void update(UserConnection user, Position position) {
|
||||||
for (BlockFace face : BlockFace.values()) {
|
for (BlockFace face : BlockFace.values()) {
|
||||||
|
@ -4,15 +4,15 @@ import us.myles.ViaVersion.api.Via;
|
|||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.minecraft.BlockFace;
|
import us.myles.ViaVersion.api.minecraft.BlockFace;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class FlowerConnectionHandler extends ConnectionHandler {
|
public class FlowerConnectionHandler extends ConnectionHandler {
|
||||||
private static final Map<Integer, Integer> flowers = new HashMap<>();
|
private static final IntMap flowers = CollectionUtil.createIntMap();
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final Set<String> baseFlower = new HashSet<>();
|
final Set<String> baseFlower = new HashSet<>();
|
||||||
@ -38,8 +38,8 @@ public class FlowerConnectionHandler extends ConnectionHandler {
|
|||||||
@Override
|
@Override
|
||||||
public int connect(UserConnection user, Position position, int blockState) {
|
public int connect(UserConnection user, Position position, int blockState) {
|
||||||
int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM));
|
int blockBelowId = getBlockData(user, position.getRelative(BlockFace.BOTTOM));
|
||||||
Integer connectBelow = flowers.get(blockBelowId);
|
int connectBelow = flowers.get(blockBelowId);
|
||||||
if (connectBelow != null) {
|
if (connectBelow != -1) {
|
||||||
int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP));
|
int blockAboveId = getBlockData(user, position.getRelative(BlockFace.TOP));
|
||||||
if (Via.getConfig().isStemWhenBlockAbove()) {
|
if (Via.getConfig().isStemWhenBlockAbove()) {
|
||||||
if (blockAboveId == 0) {
|
if (blockAboveId == 0) {
|
||||||
|
@ -3,16 +3,16 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections;
|
|||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.minecraft.BlockFace;
|
import us.myles.ViaVersion.api.minecraft.BlockFace;
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
import us.myles.ViaVersion.api.minecraft.Position;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RedstoneConnectionHandler extends ConnectionHandler {
|
public class RedstoneConnectionHandler extends ConnectionHandler {
|
||||||
private static final Set<Integer> redstone = new HashSet<>();
|
private static final Set<Integer> redstone = new HashSet<>();
|
||||||
private static final Map<Short, Integer> connectedBlockStates = new HashMap<>();
|
private static final IntMap connectedBlockStates = CollectionUtil.createIntMap(1296);
|
||||||
private static final Map<Integer, Integer> powerMappings = new HashMap<>();
|
private static final IntMap powerMappings = CollectionUtil.createIntMap(1296);
|
||||||
|
|
||||||
static ConnectionData.ConnectorInitAction init() {
|
static ConnectionData.ConnectorInitAction init() {
|
||||||
final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler();
|
final RedstoneConnectionHandler connectionHandler = new RedstoneConnectionHandler();
|
||||||
@ -22,7 +22,7 @@ public class RedstoneConnectionHandler extends ConnectionHandler {
|
|||||||
redstone.add(blockData.getSavedBlockStateId());
|
redstone.add(blockData.getSavedBlockStateId());
|
||||||
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
|
||||||
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
connectedBlockStates.put(getStates(blockData), blockData.getSavedBlockStateId());
|
||||||
powerMappings.put(blockData.getSavedBlockStateId(), Integer.valueOf(blockData.getValue("power")));
|
powerMappings.put(blockData.getSavedBlockStateId(), Integer.parseInt(blockData.getValue("power")));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +57,7 @@ public class RedstoneConnectionHandler extends ConnectionHandler {
|
|||||||
b |= connects(user, position, BlockFace.SOUTH) << 4;
|
b |= connects(user, position, BlockFace.SOUTH) << 4;
|
||||||
b |= connects(user, position, BlockFace.WEST) << 6;
|
b |= connects(user, position, BlockFace.WEST) << 6;
|
||||||
b |= powerMappings.get(blockState) << 8;
|
b |= powerMappings.get(blockState) << 8;
|
||||||
final Integer newBlockState = connectedBlockStates.get(b);
|
return connectedBlockStates.getOrDefault(b, blockState);
|
||||||
return newBlockState == null ? blockState : newBlockState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int connects(UserConnection user, Position position, BlockFace side) {
|
private int connects(UserConnection user, Position position, BlockFace side) {
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class EntityTypeRewriter {
|
|
||||||
private static final Map<Integer, Integer> entityTypes = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
registerEntity(1, 32); // item - ajl
|
|
||||||
registerEntity(2, 22); // xp_orb - abx
|
|
||||||
registerEntity(3, 0); // area_effect_cloud - abp
|
|
||||||
registerEntity(4, 15); // elder_guardian - aju
|
|
||||||
registerEntity(5, 84); // wither_skeleton - aku
|
|
||||||
registerEntity(6, 71); // stray - akq
|
|
||||||
registerEntity(7, 74); // egg - alz
|
|
||||||
registerEntity(8, 35); // leash_knot - ajb
|
|
||||||
registerEntity(9, 49); // painting - ajd
|
|
||||||
registerEntity(10, 2); // arrow - all
|
|
||||||
registerEntity(11, 67); // snowball - alw
|
|
||||||
registerEntity(12, 34); // fireball - alq
|
|
||||||
registerEntity(13, 65); // small_fireball - alv
|
|
||||||
registerEntity(14, 75); // ender_pearl - ama
|
|
||||||
registerEntity(15, 23); // eye_of_ender_signal - alo
|
|
||||||
registerEntity(16, 77); // potion - amc
|
|
||||||
registerEntity(17, 76); // xp_bottle - amb
|
|
||||||
registerEntity(18, 33); // item_frame - aja
|
|
||||||
registerEntity(19, 85); // wither_skull - ame
|
|
||||||
registerEntity(20, 55); // tnt - ajm
|
|
||||||
registerEntity(21, 24); // falling_block - ajk
|
|
||||||
registerEntity(22, 25); // fireworks_rocket - alp
|
|
||||||
registerEntity(23, 30); // husk - akc
|
|
||||||
registerEntity(24, 68); // spectral_arrow - alx
|
|
||||||
registerEntity(25, 60); // shulker_bullet - alu
|
|
||||||
registerEntity(26, 13); // dragon_fireball - alm
|
|
||||||
registerEntity(27, 89); // zombie_villager - akw
|
|
||||||
registerEntity(28, 63); // skeleton_horse - aht
|
|
||||||
registerEntity(29, 88); // zombie_horse - ahv
|
|
||||||
registerEntity(30, 1); // armor_stand - aiy
|
|
||||||
registerEntity(31, 11); // donkey - aho
|
|
||||||
registerEntity(32, 46); // mule - ahs
|
|
||||||
registerEntity(33, 20); // evocation_fangs - aln
|
|
||||||
registerEntity(34, 21); // evocation_illager - ajy
|
|
||||||
registerEntity(35, 78); // vex - akr
|
|
||||||
registerEntity(36, 81); // vindication_illager - aks
|
|
||||||
registerEntity(37, 31); // illusion_illager - akd
|
|
||||||
registerEntity(40, 41); // commandblock_minecart - aml
|
|
||||||
registerEntity(41, 5); // boat - ami
|
|
||||||
registerEntity(42, 39); // minecart - amj
|
|
||||||
registerEntity(43, 40); // chest_minecart - amk
|
|
||||||
registerEntity(44, 42); // furnace_minecart - amm
|
|
||||||
registerEntity(45, 45); // tnt_minecart - amp
|
|
||||||
registerEntity(46, 43); // hopper_minecart - amn
|
|
||||||
registerEntity(47, 44); // spawner_minecart - amo
|
|
||||||
registerEntity(50, 10); // creeper - ajs
|
|
||||||
registerEntity(51, 62); // skeleton - akm
|
|
||||||
registerEntity(52, 69); // spider - akp
|
|
||||||
registerEntity(53, 27); // giant - aka
|
|
||||||
registerEntity(54, 87); // zombie - akv
|
|
||||||
registerEntity(55, 64); // slime - akn
|
|
||||||
registerEntity(56, 26); // ghast - ajz
|
|
||||||
registerEntity(57, 53); // zombie_pigman - akh
|
|
||||||
registerEntity(58, 18); // enderman - ajv
|
|
||||||
registerEntity(59, 6); // cave_spider - ajr
|
|
||||||
registerEntity(60, 61); // silverfish - akl
|
|
||||||
registerEntity(61, 4); // blaze - ajq
|
|
||||||
registerEntity(62, 38); // magma_cube - ake
|
|
||||||
registerEntity(63, 17); // ender_dragon - aic
|
|
||||||
registerEntity(64, 83); // wither - aiw
|
|
||||||
registerEntity(65, 3); // bat - agl
|
|
||||||
registerEntity(66, 82); // witch - akt
|
|
||||||
registerEntity(67, 19); // endermite - ajw
|
|
||||||
registerEntity(68, 28); // guardian - akb
|
|
||||||
registerEntity(69, 59); // shulker - akk
|
|
||||||
registerEntity(200, 16); // ender_crystal - aib
|
|
||||||
registerEntity(90, 51); // pig - agy
|
|
||||||
registerEntity(91, 58); // sheep - ahd
|
|
||||||
registerEntity(92, 9); // cow - ags
|
|
||||||
registerEntity(93, 7); // chicken - agq
|
|
||||||
registerEntity(94, 70); // squid - ahg
|
|
||||||
registerEntity(95, 86); // wolf - ahl
|
|
||||||
registerEntity(96, 47); // mooshroom - agv
|
|
||||||
registerEntity(97, 66); // snowman - ahf
|
|
||||||
registerEntity(98, 48); // ocelot - agw
|
|
||||||
registerEntity(99, 80); // villager_golem - ahj
|
|
||||||
registerEntity(100, 29); // horse - ahp
|
|
||||||
registerEntity(101, 56); // rabbit - ahb
|
|
||||||
registerEntity(102, 54); // polar_bear - agz
|
|
||||||
registerEntity(103, 36); // llama - ahr
|
|
||||||
registerEntity(104, 37); // llama_spit - alr
|
|
||||||
registerEntity(105, 50); // parrot - agx
|
|
||||||
registerEntity(120, 79); // villager - ala
|
|
||||||
|
|
||||||
// OBJECTS
|
|
||||||
// Couldn't find any object id change with mapped values
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void registerEntity(int type1_12, int type1_13) {
|
|
||||||
entityTypes.put(type1_12, type1_13);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<Integer> getNewId(int type1_12) {
|
|
||||||
return Optional.ofNullable(entityTypes.get(type1_12));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata;
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||||
import us.myles.ViaVersion.api.entities.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
@ -10,7 +11,6 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
|||||||
import us.myles.ViaVersion.api.type.types.Particle;
|
import us.myles.ViaVersion.api.type.types.Particle;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
||||||
@ -23,6 +23,7 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
|
|||||||
|
|
||||||
public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) {
|
public MetadataRewriter1_13To1_12_2(Protocol1_13To1_12_2 protocol) {
|
||||||
super(protocol, EntityTracker1_13.class);
|
super(protocol, EntityTracker1_13.class);
|
||||||
|
mapTypes(Entity1_12Types.EntityType.values(), Entity1_13Types.EntityType.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -100,11 +101,6 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter {
|
|||||||
// TODO: Boat has changed
|
// TODO: Boat has changed
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewEntityId(final int oldId) {
|
|
||||||
return EntityTypeRewriter.getNewId(oldId).orElse(oldId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EntityType getTypeFromId(int type) {
|
protected EntityType getTypeFromId(int type) {
|
||||||
return Entity1_13Types.getTypeFromId(type, false);
|
return Entity1_13Types.getTypeFromId(type, false);
|
||||||
|
@ -26,32 +26,32 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntSet;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class WorldPackets {
|
public class WorldPackets {
|
||||||
private static final Set<Integer> validBiomes = new HashSet<>();
|
private static final IntSet VALID_BIOMES = CollectionUtil.createIntSet(70);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Client will crash if it receives a invalid biome id
|
// Client will crash if it receives a invalid biome id
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
validBiomes.add(i);
|
VALID_BIOMES.add(i);
|
||||||
}
|
}
|
||||||
validBiomes.add(127);
|
VALID_BIOMES.add(127);
|
||||||
for (int i = 129; i <= 134; i++) {
|
for (int i = 129; i <= 134; i++) {
|
||||||
validBiomes.add(i);
|
VALID_BIOMES.add(i);
|
||||||
}
|
}
|
||||||
validBiomes.add(140);
|
VALID_BIOMES.add(140);
|
||||||
validBiomes.add(149);
|
VALID_BIOMES.add(149);
|
||||||
validBiomes.add(151);
|
VALID_BIOMES.add(151);
|
||||||
for (int i = 155; i <= 158; i++) {
|
for (int i = 155; i <= 158; i++) {
|
||||||
validBiomes.add(i);
|
VALID_BIOMES.add(i);
|
||||||
}
|
}
|
||||||
for (int i = 160; i <= 167; i++) {
|
for (int i = 160; i <= 167; i++) {
|
||||||
validBiomes.add(i);
|
VALID_BIOMES.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ public class WorldPackets {
|
|||||||
int latestBiomeWarn = Integer.MIN_VALUE;
|
int latestBiomeWarn = Integer.MIN_VALUE;
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
int biome = chunk.getBiomeData()[i];
|
int biome = chunk.getBiomeData()[i];
|
||||||
if (!validBiomes.contains(biome)) {
|
if (!VALID_BIOMES.contains(biome)) {
|
||||||
if (biome != 255 // is it generated naturally? *shrug*
|
if (biome != 255 // is it generated naturally? *shrug*
|
||||||
&& latestBiomeWarn != biome) {
|
&& latestBiomeWarn != biome) {
|
||||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
||||||
|
@ -11,25 +11,29 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Arrays;
|
||||||
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 final Map<Long, Pair<byte[], NibbleArray>> blockStorage = createLongObjectMap();
|
private static final short[] REVERSE_BLOCK_MAPPINGS = new short[8581];
|
||||||
|
|
||||||
private static final Map<Short, Short> reverseBlockMappings;
|
|
||||||
private static Constructor<?> fastUtilLongObjectHashMap;
|
private static Constructor<?> fastUtilLongObjectHashMap;
|
||||||
|
|
||||||
|
private final Map<Long, Pair<byte[], NibbleArray>> blockStorage = createLongObjectMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
fastUtilLongObjectHashMap = Class.forName("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap").getConstructor();
|
fastUtilLongObjectHashMap = Class.forName("it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap").getConstructor();
|
||||||
Via.getPlatform().getLogger().info("Using FastUtil Long2ObjectOpenHashMap for block connections");
|
Via.getPlatform().getLogger().info("Using FastUtil Long2ObjectOpenHashMap for block connections");
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
|
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
|
||||||
}
|
}
|
||||||
reverseBlockMappings = new HashMap<>();
|
|
||||||
|
Arrays.fill(REVERSE_BLOCK_MAPPINGS, (short) -1);
|
||||||
for (int i = 0; i < 4096; i++) {
|
for (int i = 0; i < 4096; i++) {
|
||||||
int newBlock = MappingData.blockMappings.getNewId(i);
|
int newBlock = MappingData.blockMappings.getNewId(i);
|
||||||
if (newBlock != -1) reverseBlockMappings.put((short) newBlock, (short) i);
|
if (newBlock != -1) {
|
||||||
|
REVERSE_BLOCK_MAPPINGS[newBlock] = (short) i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,15 +42,18 @@ public class BlockConnectionStorage extends StoredObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void store(int x, int y, int z, int blockState) {
|
public void store(int x, int y, int z, int blockState) {
|
||||||
Short mapping = reverseBlockMappings.get((short) blockState);
|
short mapping = REVERSE_BLOCK_MAPPINGS[blockState];
|
||||||
if (mapping == null) return;
|
if (mapping == -1) return;
|
||||||
|
|
||||||
blockState = mapping;
|
blockState = mapping;
|
||||||
long pair = getChunkSectionIndex(x, y, z);
|
long pair = getChunkSectionIndex(x, y, z);
|
||||||
Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
|
Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
|
||||||
int blockIndex = encodeBlockPos(x, y, z);
|
int blockIndex = encodeBlockPos(x, y, z);
|
||||||
map.getKey()[blockIndex] = (byte) (blockState >> 4);
|
map.getKey()[blockIndex] = (byte) (blockState >> 4);
|
||||||
NibbleArray nibbleArray = map.getValue();
|
NibbleArray nibbleArray = map.getValue();
|
||||||
if (nibbleArray != null) nibbleArray.set(blockIndex, blockState);
|
if (nibbleArray != null) {
|
||||||
|
nibbleArray.set(blockIndex, blockState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int get(int x, int y, int z) {
|
public int get(int x, int y, int z) {
|
||||||
|
@ -3,36 +3,39 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
|||||||
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.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntSet;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class BlockStorage extends StoredObject {
|
public class BlockStorage extends StoredObject {
|
||||||
private static final Set<Integer> whitelist = new HashSet<>();
|
private static final IntSet WHITELIST = CollectionUtil.createIntSet(46);
|
||||||
private final Map<Position, ReplacementData> blocks = new ConcurrentHashMap<>();
|
private final Map<Position, ReplacementData> blocks = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Flower pots
|
// Flower pots
|
||||||
whitelist.add(5266);
|
WHITELIST.add(5266);
|
||||||
|
|
||||||
// Add those red beds
|
// Add those red beds
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++) {
|
||||||
whitelist.add(972 + i);
|
WHITELIST.add(972 + i);
|
||||||
|
}
|
||||||
|
|
||||||
// Add the white banners
|
// Add the white banners
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++) {
|
||||||
whitelist.add(6854 + i);
|
WHITELIST.add(6854 + i);
|
||||||
|
}
|
||||||
|
|
||||||
// Add the white wall banners
|
// Add the white wall banners
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
whitelist.add(7110 + i);
|
WHITELIST.add(7110 + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skeleton skulls
|
// Skeleton skulls
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++) {
|
||||||
whitelist.add(5447 + i);
|
WHITELIST.add(5447 + i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockStorage(UserConnection user) {
|
public BlockStorage(UserConnection user) {
|
||||||
@ -44,14 +47,14 @@ public class BlockStorage extends StoredObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void store(Position position, int block, int replacementId) {
|
public void store(Position position, int block, int replacementId) {
|
||||||
if (!whitelist.contains(block))
|
if (!WHITELIST.contains(block))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
blocks.put(position, new ReplacementData(block, replacementId));
|
blocks.put(position, new ReplacementData(block, replacementId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWelcome(int block) {
|
public boolean isWelcome(int block) {
|
||||||
return whitelist.contains(block);
|
return WHITELIST.contains(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Position position) {
|
public boolean contains(Position position) {
|
||||||
|
@ -1,109 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class EntityTypeRewriter {
|
|
||||||
private static final Map<Integer, Integer> entityTypes = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
regEnt(6, 7); // cave_spider
|
|
||||||
regEnt(7, 8); // chicken
|
|
||||||
regEnt(8, 9); // cod
|
|
||||||
regEnt(9, 10); // cow
|
|
||||||
regEnt(10, 11); // creeper
|
|
||||||
regEnt(11, 12); // donkey
|
|
||||||
regEnt(12, 13); // dolphin
|
|
||||||
regEnt(13, 14); // dragon_fireball
|
|
||||||
regEnt(14, 15); // drowned
|
|
||||||
regEnt(15, 16); // elder_guardian
|
|
||||||
regEnt(16, 17); // end_crystal
|
|
||||||
regEnt(17, 18); // ender_dragon
|
|
||||||
regEnt(18, 19); // enderman
|
|
||||||
regEnt(19, 20); // endermite
|
|
||||||
regEnt(20, 21); // evoker_fangs
|
|
||||||
regEnt(21, 22); // evoker
|
|
||||||
regEnt(22, 23); // experience_orb
|
|
||||||
regEnt(23, 24); // eye_of_ender
|
|
||||||
regEnt(24, 25); // falling_block
|
|
||||||
regEnt(25, 26); // firework_rocket
|
|
||||||
regEnt(26, 28); // ghast
|
|
||||||
regEnt(27, 29); // giant
|
|
||||||
regEnt(28, 30); // guardian
|
|
||||||
regEnt(29, 31); // horse
|
|
||||||
regEnt(30, 32); // husk
|
|
||||||
regEnt(31, 33); // illusioner
|
|
||||||
regEnt(32, 34); // item
|
|
||||||
regEnt(33, 35); // item_frame
|
|
||||||
regEnt(34, 36); // fireball
|
|
||||||
regEnt(35, 37); // leash_knot
|
|
||||||
regEnt(36, 38); // llama
|
|
||||||
regEnt(37, 39); // llama_spit
|
|
||||||
regEnt(38, 40); // magma_cube
|
|
||||||
regEnt(39, 41); // minecart
|
|
||||||
regEnt(40, 42); // chest_minecart
|
|
||||||
regEnt(41, 43); // command_block_minecart
|
|
||||||
regEnt(42, 44); // furnace_minecart
|
|
||||||
regEnt(43, 45); // hopper_minecart
|
|
||||||
regEnt(44, 46); // spawner_minecart
|
|
||||||
regEnt(45, 47); // tnt_minecart
|
|
||||||
regEnt(46, 48); // mule
|
|
||||||
regEnt(47, 49); // mooshroom
|
|
||||||
regEnt(48, 6); // ocelot -> cat TODO Remap untamed ocelot to ocelot?
|
|
||||||
regEnt(49, 51); // painting
|
|
||||||
regEnt(50, 53); // parrot
|
|
||||||
regEnt(51, 54); // pig
|
|
||||||
regEnt(52, 55); // pufferfish
|
|
||||||
regEnt(53, 56); // zombie_pigman
|
|
||||||
regEnt(54, 57); // polar_bear
|
|
||||||
regEnt(55, 58); // tnt
|
|
||||||
regEnt(56, 59); // rabbit
|
|
||||||
regEnt(57, 60); // salmon
|
|
||||||
regEnt(58, 61); // sheep
|
|
||||||
regEnt(59, 62); // shulker
|
|
||||||
regEnt(60, 63); // shulker_bullet
|
|
||||||
regEnt(61, 64); // silverfish
|
|
||||||
regEnt(62, 65); // skeleton
|
|
||||||
regEnt(63, 66); // skeleton_horse
|
|
||||||
regEnt(64, 67); // slime
|
|
||||||
regEnt(65, 68); // small_fireball
|
|
||||||
regEnt(66, 69); // snowgolem
|
|
||||||
regEnt(67, 70); // snowball
|
|
||||||
regEnt(68, 71); // spectral_arrow
|
|
||||||
regEnt(69, 72); // spider
|
|
||||||
regEnt(70, 73); // squid
|
|
||||||
regEnt(71, 74); // stray
|
|
||||||
regEnt(72, 76); // tropical_fish
|
|
||||||
regEnt(73, 77); // turtle
|
|
||||||
regEnt(74, 78); // egg
|
|
||||||
regEnt(75, 79); // ender_pearl
|
|
||||||
regEnt(76, 80); // experience_bottle
|
|
||||||
regEnt(77, 81); // potion
|
|
||||||
regEnt(78, 83); // vex
|
|
||||||
regEnt(79, 84); // villager
|
|
||||||
regEnt(80, 85); // iron_golem
|
|
||||||
regEnt(81, 86); // vindicator
|
|
||||||
regEnt(82, 89); // witch
|
|
||||||
regEnt(83, 90); // wither
|
|
||||||
regEnt(84, 91); // wither_skeleton
|
|
||||||
regEnt(85, 92); // wither_skull
|
|
||||||
regEnt(86, 93); // wolf
|
|
||||||
regEnt(87, 94); // zombie
|
|
||||||
regEnt(88, 95); // zombie_horse
|
|
||||||
regEnt(89, 96); // zombie_villager
|
|
||||||
regEnt(90, 97); // phantom
|
|
||||||
regEnt(91, 99); // lightning_bolt
|
|
||||||
regEnt(92, 100); // player
|
|
||||||
regEnt(93, 101); // fishing_bobber
|
|
||||||
regEnt(94, 82); // trident
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void regEnt(int type1_13, int type1_14) {
|
|
||||||
entityTypes.put(type1_13, type1_14);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<Integer> getNewId(int type1_13) {
|
|
||||||
return Optional.ofNullable(entityTypes.get(type1_13));
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,19 +8,19 @@ import com.google.gson.JsonObject;
|
|||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
||||||
import us.myles.ViaVersion.api.data.Mappings;
|
import us.myles.ViaVersion.api.data.Mappings;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntSet;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class MappingData {
|
public class MappingData {
|
||||||
public static final BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
public static final BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
||||||
public static Mappings blockStateMappings;
|
public static Mappings blockStateMappings;
|
||||||
public static Mappings blockMappings;
|
public static Mappings blockMappings;
|
||||||
public static Mappings soundMappings;
|
public static Mappings soundMappings;
|
||||||
public static Set<Integer> motionBlocking;
|
public static IntSet motionBlocking;
|
||||||
public static Set<Integer> nonFullBlocks;
|
public static IntSet nonFullBlocks;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
|
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
|
||||||
@ -40,19 +40,19 @@ public class MappingData {
|
|||||||
|
|
||||||
JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
|
JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
|
||||||
JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
|
JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
|
||||||
us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.motionBlocking = new HashSet<>(motionBlocking.size());
|
MappingData.motionBlocking = CollectionUtil.createIntSet(motionBlocking.size());
|
||||||
for (JsonElement blockState : motionBlocking) {
|
for (JsonElement blockState : motionBlocking) {
|
||||||
String key = blockState.getAsString();
|
String key = blockState.getAsString();
|
||||||
Integer id = blockStateMap.get(key);
|
Integer id = blockStateMap.get(key);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :(");
|
Via.getPlatform().getLogger().warning("Unknown blockstate " + key + " :(");
|
||||||
} else {
|
} else {
|
||||||
us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.motionBlocking.add(id);
|
MappingData.motionBlocking.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getConfig().isNonFullBlockLightFix()) {
|
if (Via.getConfig().isNonFullBlockLightFix()) {
|
||||||
nonFullBlocks = new HashSet<>();
|
nonFullBlocks = CollectionUtil.createIntSet(1611);
|
||||||
for (Map.Entry<String, JsonElement> blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) {
|
for (Map.Entry<String, JsonElement> blockstates : mapping1_13_2.getAsJsonObject("blockstates").entrySet()) {
|
||||||
final String state = blockstates.getValue().getAsString();
|
final String state = blockstates.getValue().getAsString();
|
||||||
if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall["))
|
if (state.contains("_slab") || state.contains("_stairs") || state.contains("_wall["))
|
||||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata;
|
|||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.entities.Entity1_13Types;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||||
import us.myles.ViaVersion.api.entities.EntityType;
|
import us.myles.ViaVersion.api.entities.EntityType;
|
||||||
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
||||||
@ -13,7 +14,6 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.types.Particle;
|
import us.myles.ViaVersion.api.type.types.Particle;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
|
|||||||
|
|
||||||
public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) {
|
public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) {
|
||||||
super(protocol, EntityTracker1_14.class);
|
super(protocol, EntityTracker1_14.class);
|
||||||
|
mapTypes(Entity1_13Types.EntityType.values(), Entity1_14Types.EntityType.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -168,11 +169,6 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewEntityId(final int oldId) {
|
|
||||||
return EntityTypeRewriter.getNewId(oldId).orElse(oldId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EntityType getTypeFromId(int type) {
|
protected EntityType getTypeFromId(int type) {
|
||||||
return Entity1_14Types.getTypeFromId(type);
|
return Entity1_14Types.getTypeFromId(type);
|
||||||
|
@ -14,7 +14,6 @@ import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.metadata.MetadataRewriter1_14To1_13_2;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ public class EntityPackets {
|
|||||||
int typeId = wrapper.get(Type.VAR_INT, 1);
|
int typeId = wrapper.get(Type.VAR_INT, 1);
|
||||||
|
|
||||||
Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true);
|
Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true);
|
||||||
typeId = EntityTypeRewriter.getNewId(type1_13.getId()).orElse(type1_13.getId());
|
typeId = metadataRewriter.getNewEntityId(type1_13.getId());
|
||||||
Entity1_14Types.EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId);
|
Entity1_14Types.EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId);
|
||||||
|
|
||||||
if (type1_14 != null) {
|
if (type1_14 != null) {
|
||||||
|
@ -5,6 +5,8 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
|
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -17,7 +19,7 @@ public class ItemRewriter {
|
|||||||
private static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
private static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
|
||||||
private static final Map<Integer, String> POTION_ID_TO_NAME = new HashMap<>();
|
private static final Map<Integer, String> POTION_ID_TO_NAME = new HashMap<>();
|
||||||
|
|
||||||
private static final Map<Integer, Integer> POTION_INDEX = new HashMap<>();
|
private static final IntMap POTION_INDEX = CollectionUtil.createIntMap(36);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
/* Entities */
|
/* Entities */
|
||||||
@ -381,13 +383,13 @@ public class ItemRewriter {
|
|||||||
oldID -= 8192;
|
oldID -= 8192;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer index = POTION_INDEX.get(oldID);
|
int index = POTION_INDEX.get(oldID);
|
||||||
if (index != null) {
|
if (index != -1) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldID = POTION_NAME_TO_ID.get(potionNameFromDamage((short) oldID));
|
oldID = POTION_NAME_TO_ID.get(potionNameFromDamage((short) oldID));
|
||||||
return (index = POTION_INDEX.get(oldID)) != null ? index : 0;
|
return (index = POTION_INDEX.get(oldID)) != -1 ? index : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerEntity(Integer id, String name) {
|
private static void registerEntity(Integer id, String name) {
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import us.myles.ViaVersion.util.fastutil.CollectionUtil;
|
||||||
import java.util.Map;
|
import us.myles.ViaVersion.util.fastutil.IntMap;
|
||||||
|
|
||||||
public class Effect {
|
public class Effect {
|
||||||
|
|
||||||
private static final Map<Integer, Integer> effects;
|
private static final IntMap EFFECTS = CollectionUtil.createIntMap(17);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
effects = new HashMap<>();
|
|
||||||
addRewrite(1005, 1010); //Play music disc
|
addRewrite(1005, 1010); //Play music disc
|
||||||
addRewrite(1003, 1005); //Iron door open
|
addRewrite(1003, 1005); //Iron door open
|
||||||
addRewrite(1006, 1011); //Iron door close
|
addRewrite(1006, 1011); //Iron door close
|
||||||
@ -26,19 +25,17 @@ public class Effect {
|
|||||||
addRewrite(1020, 1029); //Anvil break
|
addRewrite(1020, 1029); //Anvil break
|
||||||
addRewrite(1021, 1030); //Anvil use
|
addRewrite(1021, 1030); //Anvil use
|
||||||
addRewrite(1022, 1031); //Anvil land
|
addRewrite(1022, 1031); //Anvil land
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNewId(int id) {
|
public static int getNewId(int id) {
|
||||||
Integer newId = effects.get(id);
|
return EFFECTS.getOrDefault(id, id);
|
||||||
return newId != null ? newId : id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean contains(int oldId) {
|
public static boolean contains(int oldId) {
|
||||||
return effects.containsKey(oldId);
|
return EFFECTS.containsKey(oldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addRewrite(int oldId, int newId) {
|
private static void addRewrite(int oldId, int newId) {
|
||||||
effects.put(oldId, newId);
|
EFFECTS.put(oldId, newId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,173 @@
|
|||||||
|
package us.myles.ViaVersion.util.fastutil;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class to possibly wrap FastUtil collections for faster access.
|
||||||
|
* These should only be used for high access and low/no change collections, since resizing FastUtil collections is expensive.
|
||||||
|
*/
|
||||||
|
public class CollectionUtil {
|
||||||
|
private static final boolean FAST_UTIL = hasFastUtil();
|
||||||
|
|
||||||
|
private static boolean hasFastUtil() {
|
||||||
|
try {
|
||||||
|
Class.forName("Int2IntMap");
|
||||||
|
return true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new FastUtil collection from the given map if present, else simply wraps the original.
|
||||||
|
*
|
||||||
|
* @param originalMap map to be reflected
|
||||||
|
* @return wrapped int map
|
||||||
|
*/
|
||||||
|
public static IntMap createIntMap(Map<Integer, Integer> originalMap) {
|
||||||
|
return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap(originalMap)) : new WrappedIntMap(originalMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new FastUtil collection if present, else simply wraps a normal HashMap.
|
||||||
|
*
|
||||||
|
* @param size expected size of the collection
|
||||||
|
* @return wrapped int map
|
||||||
|
*/
|
||||||
|
public static IntMap createIntMap(int size) {
|
||||||
|
return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap(size)) : new WrappedIntMap(new HashMap<>(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntMap createIntMap() {
|
||||||
|
return FAST_UTIL ? new WrappedFUIntMap(new Int2IntOpenHashMap()) : new WrappedIntMap(new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new FastUtil collection from the given set if present, else simply wraps the original.
|
||||||
|
*
|
||||||
|
* @param originalSet set to be reflected
|
||||||
|
* @return wrapped int set
|
||||||
|
*/
|
||||||
|
public static IntSet createIntSet(Set<Integer> originalSet) {
|
||||||
|
return FAST_UTIL ? new WrappedFUIntSet(new IntOpenHashSet(originalSet)) : new WrappedIntSet(originalSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new FastUtil collection if present, else simply wraps a normal HashSet.
|
||||||
|
*
|
||||||
|
* @param size expected size of the collection
|
||||||
|
* @return wrapped int set
|
||||||
|
*/
|
||||||
|
public static IntSet createIntSet(int size) {
|
||||||
|
return FAST_UTIL ? new WrappedFUIntSet(new IntOpenHashSet(size)) : new WrappedIntSet(new HashSet<>(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class WrappedFUIntMap implements IntMap {
|
||||||
|
private final Int2IntMap map;
|
||||||
|
|
||||||
|
private WrappedFUIntMap(Int2IntMap map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrDefault(int key, int def) {
|
||||||
|
return map.getOrDefault(key, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(int key) {
|
||||||
|
return map.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int put(int key, int value) {
|
||||||
|
return map.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int remove(int key) {
|
||||||
|
return map.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class WrappedIntMap implements IntMap {
|
||||||
|
private final Map<Integer, Integer> map;
|
||||||
|
|
||||||
|
private WrappedIntMap(Map<Integer, Integer> map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrDefault(int key, int def) {
|
||||||
|
return map.getOrDefault(key, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(int key) {
|
||||||
|
return map.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int put(int key, int value) {
|
||||||
|
return map.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int remove(int key) {
|
||||||
|
return map.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class WrappedFUIntSet implements IntSet {
|
||||||
|
private final it.unimi.dsi.fastutil.ints.IntSet set;
|
||||||
|
|
||||||
|
private WrappedFUIntSet(it.unimi.dsi.fastutil.ints.IntSet set) {
|
||||||
|
this.set = set;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(int key) {
|
||||||
|
return set.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(int key) {
|
||||||
|
return set.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(int key) {
|
||||||
|
return set.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class WrappedIntSet implements IntSet {
|
||||||
|
private final Set<Integer> set;
|
||||||
|
|
||||||
|
private WrappedIntSet(Set<Integer> set) {
|
||||||
|
this.set = set;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(int key) {
|
||||||
|
return set.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(int key) {
|
||||||
|
return set.add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(int key) {
|
||||||
|
return set.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java
Normale Datei
35
common/src/main/java/us/myles/ViaVersion/util/fastutil/IntMap.java
Normale Datei
@ -0,0 +1,35 @@
|
|||||||
|
package us.myles.ViaVersion.util.fastutil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Very simple wrapping interface to either be implemented by a HashMap or FastUtil's OpenHashMap.
|
||||||
|
*/
|
||||||
|
public interface IntMap {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return value if present, -1 otherwise
|
||||||
|
* @see java.util.HashMap#get(Object)
|
||||||
|
*/
|
||||||
|
default int get(int key) {
|
||||||
|
return getOrDefault(key, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashMap#getOrDefault(Object, Object) (Object)
|
||||||
|
*/
|
||||||
|
int getOrDefault(int key, int def);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashMap#containsKey(Object)
|
||||||
|
*/
|
||||||
|
boolean containsKey(int key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashMap#put(Object, Object)
|
||||||
|
*/
|
||||||
|
int put(int key, int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashMap#remove(Object)
|
||||||
|
*/
|
||||||
|
int remove(int key);
|
||||||
|
}
|
22
common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java
Normale Datei
22
common/src/main/java/us/myles/ViaVersion/util/fastutil/IntSet.java
Normale Datei
@ -0,0 +1,22 @@
|
|||||||
|
package us.myles.ViaVersion.util.fastutil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Very simple wrapping interface to either be implemented by a HashSet or FastUtil's OpenHashSet.
|
||||||
|
*/
|
||||||
|
public interface IntSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashSet#contains(Object)
|
||||||
|
*/
|
||||||
|
boolean contains(int key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashSet#add(Object)
|
||||||
|
*/
|
||||||
|
boolean add(int key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see java.util.HashSet#remove(Object)
|
||||||
|
*/
|
||||||
|
boolean remove(int key);
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren