Revert more changes

This commit is contained in:
MattBDev 2020-01-29 15:32:51 -05:00
parent 020c674c01
commit df60e50c96
2 changed files with 24 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry;
import com.sk89q.worldedit.world.registry.Registries; import com.sk89q.worldedit.world.registry.Registries;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -21,7 +22,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BlockTypesCache { public class BlockTypesCache {
@ -127,7 +127,10 @@ public class BlockTypesCache {
int[] result = new int[maxStateId]; int[] result = new int[maxStateId];
Arrays.fill(result, -1); Arrays.fill(result, -1);
int[] state = new int[props.size()]; int[] state = new int[props.size()];
int[] sizes = props.stream().mapToInt(prop -> prop.getValues().size()).toArray(); int[] sizes = new int[props.size()];
for (int i = 0; i < props.size(); i++) {
sizes[i] = props.get(i).getValues().size();
}
int index = 0; int index = 0;
outer: outer:
while (true) { while (true) {
@ -174,11 +177,7 @@ public class BlockTypesCache {
Registries registries = platform.getRegistries(); Registries registries = platform.getRegistries();
BlockRegistry blockReg = registries.getBlockRegistry(); BlockRegistry blockReg = registries.getBlockRegistry();
Collection<String> blocks = blockReg.values(); Collection<String> blocks = blockReg.values();
Map<String, String> blockMap = blocks.stream().collect(Collectors.toMap(item -> { Map<String, String> blockMap = blocks.stream().collect(Collectors.toMap(item -> item.charAt(item.length() - 1) == ']' ? item.substring(0, item.indexOf('[')) : item, item -> item));
return item.charAt(item.length() - 1) == ']' ? item.substring(0, item.indexOf('['))
: item;
},
Function.identity()));
int size = blockMap.size() + 1; int size = blockMap.size() + 1;
Field[] idFields = BlockID.class.getDeclaredFields(); Field[] idFields = BlockID.class.getDeclaredFields();
@ -209,22 +208,21 @@ public class BlockTypesCache {
} }
} }
// Register new blocks { // Register new blocks
int internalId = 1; int internalId = 1;
for (Map.Entry<String, String> entry : blockMap.entrySet()) { for (Map.Entry<String, String> entry : blockMap.entrySet()) {
String defaultState = entry.getValue(); String defaultState = entry.getValue();
// Skip already registered ids // Skip already registered ids
while (values[internalId] != null) { for (; values[internalId] != null; internalId++);
internalId++; BlockType type = register(defaultState, internalId, stateList);
values[internalId] = type;
} }
BlockType type = register(defaultState, internalId, stateList);
values[internalId] = type;
} }
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
if (values[i] == null) values[i] = values[0]; if (values[i] == null) values[i] = values[0];
} }
states = stateList.toArray(new BlockState[0]); states = stateList.toArray(new BlockState[stateList.size()]);
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -77,7 +77,6 @@ public final class LegacyMapper {
} catch (Throwable e) { } catch (Throwable e) {
log.warn("Failed to load the built-in legacy id registry", e); log.warn("Failed to load the built-in legacy id registry", e);
} }
} }
/** /**
@ -104,7 +103,7 @@ public final class LegacyMapper {
for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) { for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) {
String id = blockEntry.getKey(); String id = blockEntry.getKey();
int combinedId = getCombinedId(blockEntry.getKey()); Integer combinedId = getCombinedId(blockEntry.getKey());
final String value = blockEntry.getValue(); final String value = blockEntry.getValue();
blockEntries.put(id, value); blockEntries.put(id, value);
@ -117,6 +116,7 @@ public final class LegacyMapper {
} }
} catch (InputParseException f) { } catch (InputParseException f) {
BlockFactory blockFactory = WorldEdit.getInstance().getBlockFactory(); BlockFactory blockFactory = WorldEdit.getInstance().getBlockFactory();
// if fixer is available, try using that first, as some old blocks that were renamed share names with new blocks // if fixer is available, try using that first, as some old blocks that were renamed share names with new blocks
if (fixer != null) { if (fixer != null) {
try { try {
@ -125,6 +125,7 @@ public final class LegacyMapper {
} catch (InputParseException e) { } catch (InputParseException e) {
} }
} }
// if it's still null, the fixer was unavailable or failed // if it's still null, the fixer was unavailable or failed
if (state == null) { if (state == null) {
try { try {
@ -132,6 +133,7 @@ public final class LegacyMapper {
} catch (InputParseException e) { } catch (InputParseException e) {
} }
} }
// if it's still null, both fixer and default failed // if it's still null, both fixer and default failed
if (state == null) { if (state == null) {
log.debug("Unknown block: " + value); log.debug("Unknown block: " + value);
@ -143,8 +145,8 @@ public final class LegacyMapper {
} }
if (state != null) { if (state != null) {
blockArr[combinedId] = state.getInternalId(); blockArr[combinedId] = state.getInternalId();
blockStateToLegacyId4Data.put(state.getInternalId(), Integer.valueOf(combinedId)); blockStateToLegacyId4Data.put(state.getInternalId(), (Integer) combinedId);
blockStateToLegacyId4Data.putIfAbsent(state.getInternalBlockTypeId(), Integer.valueOf(combinedId)); blockStateToLegacyId4Data.putIfAbsent(state.getInternalBlockTypeId(), combinedId);
} }
} }
for (int id = 0; id < 256; id++) { for (int id = 0; id < 256; id++) {
@ -168,8 +170,6 @@ public final class LegacyMapper {
if (type == null) { if (type == null) {
log.debug("Unknown item: " + value); log.debug("Unknown item: " + value);
} else { } else {
itemToStringMap.put(type, id);
stringToItemMap.put(id, type);
try { try {
itemMap.put(getCombinedId(id), type); itemMap.put(getCombinedId(id), type);
} catch (Exception ignored) { } catch (Exception ignored) {
@ -216,10 +216,10 @@ public final class LegacyMapper {
@Nullable @Nullable
public int[] getLegacyFromItem(ItemType itemType) { public int[] getLegacyFromItem(ItemType itemType) {
Integer combinedId = getLegacyCombined(itemType); Integer combinedId = getLegacyCombined(itemType);
if (combinedId != null) { if (combinedId == null) {
return new int[]{combinedId >> 4, combinedId & 0xF};
} else {
return null; return null;
} else {
return new int[]{combinedId >> 4, combinedId & 0xF};
} }
} }