mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Major command changes that don't work yet.
This commit is contained in:
@ -23,6 +23,8 @@ import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -64,6 +66,14 @@ public interface BlockRegistry {
|
||||
*/
|
||||
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
|
||||
|
||||
/**
|
||||
* Retrieve the internal ID for a given state, if possible.
|
||||
*
|
||||
* @param state The block state
|
||||
* @return the internal ID of the state
|
||||
*/
|
||||
OptionalInt getInternalBlockStateId(BlockState state);
|
||||
|
||||
/**
|
||||
* Register all blocks
|
||||
*/
|
||||
|
@ -20,16 +20,19 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.util.io.ResourceLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
@ -47,7 +50,7 @@ import java.util.Map;
|
||||
* reading fails (which occurs when this class is first instantiated), then
|
||||
* the methods will return {@code null}s for all blocks.</p>
|
||||
*/
|
||||
public class BundledBlockData {
|
||||
public final class BundledBlockData {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BundledBlockData.class);
|
||||
private static BundledBlockData INSTANCE;
|
||||
@ -73,20 +76,19 @@ public class BundledBlockData {
|
||||
private void loadFromResource() throws IOException {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(int.class, (JsonDeserializer<Integer>) (json, typeOfT, context) -> {
|
||||
JsonPrimitive primitive = (JsonPrimitive) json;
|
||||
if (primitive.isString()) {
|
||||
String value = primitive.getAsString();
|
||||
if (value.charAt(0) == '#') return Integer.parseInt(value.substring(1), 16);
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
return primitive.getAsInt();
|
||||
});
|
||||
Gson gson = gsonBuilder.create();
|
||||
URL url = BundledBlockData.class.getResource("blocks.json");
|
||||
URL url = null;
|
||||
final int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataVersion();
|
||||
if (dataVersion > 1900) { // > MC 1.13
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "blocks.114.json");
|
||||
}
|
||||
if (url == null) {
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "blocks.json");
|
||||
}
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find blocks.json");
|
||||
}
|
||||
log.debug("Using {} for bundled block data.", url);
|
||||
String data = Resources.toString(url, Charset.defaultCharset());
|
||||
List<BlockEntry> entries = gson.fromJson(data, new TypeToken<List<BlockEntry>>() {}.getType());
|
||||
|
||||
|
@ -20,12 +20,13 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/**
|
||||
* A block registry that uses {@link BundledBlockData} to serve information
|
||||
@ -52,4 +53,9 @@ public class BundledBlockRegistry implements BlockRegistry {
|
||||
return Collections.emptyMap(); // Oof
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt getInternalBlockStateId(BlockState state) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,8 +23,11 @@ import com.google.common.io.Resources;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.util.io.ResourceLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -47,7 +50,7 @@ import java.util.Map;
|
||||
* reading fails (which occurs when this class is first instantiated), then
|
||||
* the methods will return {@code null}s for all items.</p>
|
||||
*/
|
||||
public class BundledItemData {
|
||||
public final class BundledItemData {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BundledItemData.class);
|
||||
private static BundledItemData INSTANCE;
|
||||
@ -74,10 +77,18 @@ public class BundledItemData {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
Gson gson = gsonBuilder.create();
|
||||
URL url = BundledItemData.class.getResource("items.json");
|
||||
URL url = null;
|
||||
final int dataVersion = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataVersion();
|
||||
if (dataVersion > 1900) { // > MC 1.13
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "items.114.json");
|
||||
}
|
||||
if (url == null) {
|
||||
url = ResourceLoader.getResource(BundledBlockData.class, "items.json");
|
||||
}
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find items.json");
|
||||
}
|
||||
log.debug("Using {} for bundled item data.", url);
|
||||
String data = Resources.toString(url, Charset.defaultCharset());
|
||||
List<ItemEntry> entries = gson.fromJson(data, new TypeToken<List<ItemEntry>>() {}.getType());
|
||||
|
||||
|
@ -20,13 +20,14 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.registry.Category;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A registry of categories. Minecraft internally calls these 'Tags'.
|
||||
*/
|
||||
public interface CategoryRegistry<T> {
|
||||
public interface CategoryRegistry<T extends Keyed> {
|
||||
|
||||
/**
|
||||
* Gets a set of values with a given category.
|
||||
|
@ -19,13 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
@ -28,10 +28,15 @@ import com.google.common.io.Resources;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.util.gson.VectorAdapter;
|
||||
import com.sk89q.worldedit.util.io.ResourceLoader;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@ -49,7 +54,7 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
public class LegacyMapper {
|
||||
public final class LegacyMapper {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(LegacyMapper.class);
|
||||
private static LegacyMapper INSTANCE;
|
||||
@ -66,7 +71,6 @@ public class LegacyMapper {
|
||||
try {
|
||||
loadFromResource();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
log.warn("Failed to load the built-in legacy id registry", e);
|
||||
}
|
||||
}
|
||||
@ -80,12 +84,14 @@ public class LegacyMapper {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
Gson gson = gsonBuilder.disableHtmlEscaping().create();
|
||||
URL url = LegacyMapper.class.getResource("legacy.json");
|
||||
URL url = ResourceLoader.getResource(LegacyMapper.class, "legacy.json");
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find legacy.json");
|
||||
}
|
||||
String source = Resources.toString(url, Charset.defaultCharset());
|
||||
LegacyDataFile dataFile = gson.fromJson(source, new TypeToken<LegacyDataFile>() {}.getType());
|
||||
|
||||
DataFixer fixer = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getDataFixer();
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setPreferringWildcard(false);
|
||||
parserContext.setRestricted(false);
|
||||
@ -93,7 +99,7 @@ public class LegacyMapper {
|
||||
|
||||
for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) {
|
||||
try {
|
||||
BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue());
|
||||
BlockState blockState = BlockState.get(null, blockEntry.getValue());
|
||||
BlockType type = blockState.getBlockType();
|
||||
if (type.hasProperty(PropertyKey.WATERLOGGED)) {
|
||||
blockState = blockState.with(PropertyKey.WATERLOGGED, false);
|
||||
@ -103,7 +109,7 @@ public class LegacyMapper {
|
||||
|
||||
blockStateToLegacyId4Data.put(blockState.getInternalId(), (Integer) combinedId);
|
||||
blockStateToLegacyId4Data.putIfAbsent(blockState.getInternalBlockTypeId(), combinedId);
|
||||
} catch (Exception e) {
|
||||
} catch (InputParseException e) {
|
||||
log.warn("Unknown block: " + blockEntry.getValue());
|
||||
}
|
||||
}
|
||||
@ -143,7 +149,12 @@ public class LegacyMapper {
|
||||
|
||||
public BlockState getBlockFromLegacy(String input) {
|
||||
if (input.startsWith("minecraft:")) input = input.substring(10);
|
||||
return BlockState.getFromInternalId(blockArr[getCombinedId(input)]);
|
||||
try {
|
||||
return BlockState.getFromInternalId(blockArr[getCombinedId(input)]);
|
||||
} catch (InputParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -186,7 +197,11 @@ public class LegacyMapper {
|
||||
try {
|
||||
int internalId = blockArr[combinedId];
|
||||
if (internalId == 0) return null;
|
||||
return BlockState.getFromInternalId(internalId);
|
||||
try {
|
||||
return BlockState.getFromInternalId(internalId);
|
||||
} catch (InputParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IndexOutOfBoundsException ignore) {
|
||||
return null;
|
||||
}
|
||||
@ -196,14 +211,18 @@ public class LegacyMapper {
|
||||
extra = extraId4DataToStateId.get(combinedId & 0xFF0);
|
||||
}
|
||||
if (extra != null) {
|
||||
return BlockState.getFromInternalId(extra);
|
||||
try {
|
||||
return BlockState.getFromInternalId(extra);
|
||||
} catch (InputParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void register(int id, int data, BlockStateHolder state) {
|
||||
int combinedId = ((id << 4) + data);
|
||||
extraId4DataToStateId.put((int) combinedId, (Integer) state.getInternalId());
|
||||
extraId4DataToStateId.put(combinedId, (Integer) state.getInternalId());
|
||||
blockStateToLegacyId4Data.putIfAbsent(state.getInternalId(), combinedId);
|
||||
}
|
||||
|
||||
@ -229,7 +248,7 @@ public class LegacyMapper {
|
||||
if(plotBlock instanceof StringPlotBlock) {
|
||||
try {
|
||||
return BlockTypes.get(plotBlock.toString()).getDefaultState().toBaseBlock();
|
||||
}catch(Throwable failed) {
|
||||
} catch (Throwable failed) {
|
||||
log.error("Unable to convert StringPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
failed.printStackTrace();
|
||||
return null;
|
||||
@ -237,7 +256,7 @@ public class LegacyMapper {
|
||||
}else if(plotBlock instanceof LegacyPlotBlock) {
|
||||
try {
|
||||
return BaseBlock.getState(((LegacyPlotBlock)plotBlock).getId(), ((LegacyPlotBlock)plotBlock).getData()).toBaseBlock();
|
||||
}catch(Throwable failed) {
|
||||
} catch (Throwable failed) {
|
||||
log.error("Unable to convert LegacyPlotBlock " + plotBlock + " to BaseBlock!");
|
||||
failed.printStackTrace();
|
||||
return null;
|
||||
|
@ -178,7 +178,7 @@ public class PassthroughBlockMaterial implements BlockMaterial {
|
||||
if (blockMaterial == null) {
|
||||
return true;
|
||||
} else {
|
||||
return blockMaterial.isOpaque();
|
||||
return blockMaterial.isBurnable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ class SimpleBlockMaterial implements BlockMaterial {
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return isAir;
|
||||
return this.isAir;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user