Copy paste/merge FAWE classes to this WorldEdit fork

- so certain people can look at the diff and complain about my sloppy code :(

Signed-off-by: Jesse Boyd <jessepaleg@gmail.com>
This commit is contained in:
Jesse Boyd
2018-08-13 00:03:07 +10:00
parent a920c77cb8
commit a629d15c74
994 changed files with 117583 additions and 10745 deletions

View File

@ -22,9 +22,8 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.BiomeData;
import java.util.List;
import javax.annotation.Nullable;
import java.util.List;
/**
* Provides information on biomes.

View File

@ -1,154 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.world.registry;
/**
* Describes the material for a block.
*/
public interface BlockMaterial {
/**
* Get whether this block is a full sized cube.
*
* @return the value of the test
*/
boolean isFullCube();
/**
* Get whether this block is opaque.
*
* @return the value of the test
*/
boolean isOpaque();
/**
* Get whether this block emits a Redstone signal.
*
* @return the value of the test
*/
boolean isPowerSource();
/**
* Get whether this block is a liquid.
*
* @return the value of the test
*/
boolean isLiquid();
/**
* Get whether this block is a solid.
*
* @return the value of the test
*/
boolean isSolid();
/**
* Get the hardness factor for this block.
*
* @return the hardness factor
*/
float getHardness();
/**
* Get the resistance factor for this block.
*
* @return the resistance factor
*/
float getResistance();
/**
* Get the slipperiness factor for this block.
*
* @return the slipperiness factor
*/
float getSlipperiness();
/**
* Get the light value for this block.
*
* @return the light value
*/
int getLightValue();
/**
* Get whether this block breaks when it is pushed by a piston.
*
* @return true if the block breaks
*/
boolean isFragileWhenPushed();
/**
* Get whether this block can be pushed by a piston.
*
* @return true if the block cannot be pushed
*/
boolean isUnpushable();
/**
* Get whether this block is ticked randomly.
*
* @return true if this block is ticked randomly
*/
boolean isTicksRandomly();
/**
* Get whether this block prevents movement.
*
* @return true if this block blocks movement
*/
boolean isMovementBlocker();
/**
* Get whether this block will burn.
*
* @return true if this block will burn
*/
boolean isBurnable();
/**
* Get whether this block needs to be broken by a tool for maximum
* speed.
*
* @return true if a tool is required
*/
boolean isToolRequired();
/**
* Get whether this block is replaced when a block is placed over it
* (for example, tall grass).
*
* @return true if the block is replaced
*/
boolean isReplacedDuringPlacement();
/**
* Get whether this block is translucent.
*
* @return true if the block is translucent
*/
boolean isTranslucent();
/**
* Gets whether the block has a container (Item container)
*
* @return If it has a container
*/
boolean hasContainer();
}

View File

@ -19,9 +19,13 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockType;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
@ -48,4 +52,11 @@ public interface BlockRegistry {
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
/**
* Register all blocks
*/
default Collection<String> registerBlocks() {
return Collections.emptyList();
}
}

View File

@ -24,6 +24,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.util.gson.VectorAdapter;
import java.io.IOException;
@ -136,4 +137,4 @@ public class BundledBlockData {
private SimpleBlockMaterial material = new SimpleBlockMaterial();
}
}
}

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockType;
@ -45,4 +46,4 @@ public class BundledBlockRegistry implements BlockRegistry {
return Collections.emptyMap(); // Oof
}
}
}

View File

@ -24,6 +24,8 @@ import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
/**
* A item registry that uses {@link BundledItemRegistry} to serve information
@ -37,4 +39,9 @@ public class BundledItemRegistry implements ItemRegistry {
ItemType itemType = ItemTypes.get(id);
return itemType == null ? null : new BaseItem(itemType);
}
@Override
public Collection<String> registerItems() {
return Collections.emptyList();
}
}

View File

@ -22,6 +22,8 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseItem;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
public interface ItemRegistry {
@ -34,4 +36,11 @@ public interface ItemRegistry {
@Nullable
BaseItem createFromId(String id);
/**
* Register all items
*/
default Collection<String> registerItems() {
return Collections.emptyList();
}
}

View File

@ -19,24 +19,27 @@
package com.sk89q.worldedit.world.registry;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
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.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.util.gson.VectorAdapter;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.util.gson.VectorAdapter;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -48,10 +51,10 @@ public class LegacyMapper {
private static final Logger log = Logger.getLogger(LegacyMapper.class.getCanonicalName());
private static LegacyMapper INSTANCE;
private Multimap<String, BlockState> stringToBlockMap = HashMultimap.create();
private Multimap<BlockState, String> blockToStringMap = HashMultimap.create();
private Multimap<String, ItemType> stringToItemMap = HashMultimap.create();
private Multimap<ItemType, String> itemToStringMap = HashMultimap.create();
private final Int2ObjectArrayMap<Integer> blockStateToLegacyId4Data = new Int2ObjectArrayMap<>();
private final Int2ObjectArrayMap<Integer> extraId4DataToStateId = new Int2ObjectArrayMap<>();
private final int[] blockArr = new int[4096];
private final BiMap<Integer, ItemTypes> itemMap = HashBiMap.create();
/**
* Create a new instance.
@ -60,6 +63,7 @@ public class LegacyMapper {
try {
loadFromResource();
} catch (Throwable e) {
e.printStackTrace();
log.log(Level.WARNING, "Failed to load the built-in legacy id registry", e);
}
}
@ -77,8 +81,8 @@ public class LegacyMapper {
if (url == null) {
throw new IOException("Could not find legacy.json");
}
String data = Resources.toString(url, Charset.defaultCharset());
LegacyDataFile dataFile = gson.fromJson(data, new TypeToken<LegacyDataFile>() {}.getType());
String source = Resources.toString(url, Charset.defaultCharset());
LegacyDataFile dataFile = gson.fromJson(source, new TypeToken<LegacyDataFile>() {}.getType());
ParserContext parserContext = new ParserContext();
parserContext.setPreferringWildcard(false);
@ -87,65 +91,114 @@ public class LegacyMapper {
for (Map.Entry<String, String> blockEntry : dataFile.blocks.entrySet()) {
try {
String id = blockEntry.getKey();
BlockState state = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState();
blockToStringMap.put(state, id);
stringToBlockMap.put(id, state);
BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue());
BlockTypes type = blockState.getBlockType();
if (type.hasProperty(PropertyKey.WATERLOGGED)) {
blockState = blockState.with(PropertyKey.WATERLOGGED, false);
}
int combinedId = getCombinedId(blockEntry.getKey());
blockArr[combinedId] = blockState.getInternalId();
blockStateToLegacyId4Data.put(blockState.getInternalId(), (Integer) combinedId);
blockStateToLegacyId4Data.putIfAbsent(blockState.getInternalBlockTypeId(), combinedId);
} catch (Exception e) {
log.warning("Unknown block: " + blockEntry.getValue());
log.fine("Unknown block: " + blockEntry.getValue());
}
}
for (int id = 0; id < 256; id++) {
int combinedId = id << 4;
int base = blockArr[combinedId];
if (base != 0) {
for (int data = 0; data < 16; data++, combinedId++) {
if (blockArr[combinedId] == 0) blockArr[combinedId] = base;
}
}
}
for (Map.Entry<String, String> itemEntry : dataFile.items.entrySet()) {
try {
String id = itemEntry.getKey();
ItemType type = ItemTypes.get(itemEntry.getValue());
itemToStringMap.put(type, id);
stringToItemMap.put(id, type);
itemMap.put(getCombinedId(itemEntry.getKey()), ItemTypes.get(itemEntry.getValue()));
} catch (Exception e) {
log.warning("Unknown item: " + itemEntry.getValue());
log.fine("Unknown item: " + itemEntry.getValue());
}
}
}
@Nullable
public ItemType getItemFromLegacy(int legacyId) {
return getItemFromLegacy(legacyId, 0);
private int getCombinedId(String input) {
String[] split = input.split(":");
return (Integer.parseInt(split[0]) << 4) + (split.length == 2 ? Integer.parseInt(split[1]) : 0);
}
@Nullable
public ItemType getItemFromLegacy(int legacyId, int data) {
return stringToItemMap.get(legacyId + ":" + data).stream().findFirst().orElse(null);
public ItemTypes getItemFromLegacy(int legacyId) {
return itemMap.get(legacyId << 4);
}
public ItemTypes getItemFromLegacy(String input) {
if (input.startsWith("minecraft:")) input = input.substring(10);
return itemMap.get(getCombinedId(input));
}
public BlockState getBlockFromLegacy(String input) {
if (input.startsWith("minecraft:")) input = input.substring(10);
return BlockState.get(blockArr[getCombinedId(input)]);
}
@Nullable
public int[] getLegacyFromItem(ItemType itemType) {
if (!itemToStringMap.containsKey(itemType)) {
return null;
} else {
String value = itemToStringMap.get(itemType).stream().findFirst().get();
return Arrays.stream(value.split(":")).mapToInt(Integer::parseInt).toArray();
}
public ItemTypes getItemFromLegacy(int legacyId, int data) {
return itemMap.get((legacyId << 4) + data);
}
@Nullable
public Integer getLegacyFromItem(ItemType itemType) {
return itemMap.inverse().get(itemType);
}
@Nullable
public BlockState getBlockFromLegacy(int legacyId) {
return getBlockFromLegacy(legacyId, 0);
return getBlock(legacyId << 4);
}
@Nullable
public BlockState getBlockFromLegacyCombinedId(int combinedId) {
return getBlock(combinedId);
}
@Nullable
public BlockState getBlockFromLegacy(int legacyId, int data) {
return stringToBlockMap.get(legacyId + ":" + data).stream().findFirst().orElse(null);
return getBlock((legacyId << 4) + data);
}
private BlockState getBlock(int combinedId) {
if (combinedId < blockArr.length) {
return BlockState.get(blockArr[combinedId]);
}
Integer extra = extraId4DataToStateId.get(combinedId);
if (extra == null) {
extra = extraId4DataToStateId.get(combinedId & 0xFF0);
}
if (extra != null) {
return BlockState.get(extra);
}
return BlockTypes.AIR.getDefaultState();
}
public void register(int id, int data, BlockStateHolder state) {
int combinedId = ((id << 4) + data);
extraId4DataToStateId.put((int) combinedId, (Integer) state.getInternalId());
blockStateToLegacyId4Data.putIfAbsent(state.getInternalId(), combinedId);
}
@Nullable
public int[] getLegacyFromBlock(BlockState blockState) {
if (!blockToStringMap.containsKey(blockState)) {
return null;
} else {
String value = blockToStringMap.get(blockState).stream().findFirst().get();
return Arrays.stream(value.split(":")).mapToInt(Integer::parseInt).toArray();
}
public Integer getLegacyFromBlock(BlockState blockState) {
Integer result = blockStateToLegacyId4Data.get(blockState.getInternalId());
if (result == null) result = blockStateToLegacyId4Data.get(blockState.getInternalBlockTypeId());
return result;
}
@Nullable
public Integer getLegacyFromBlock(BlockType type) {
return blockStateToLegacyId4Data.get(type.getDefaultState());
}
public static LegacyMapper getInstance() {

View File

@ -22,11 +22,10 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.BiomeData;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
/**
* A biome registry that knows nothing.
*/

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BlockMaterial;
import javax.annotation.Nullable;
public class PassthroughBlockMaterial implements BlockMaterial {
@ -29,6 +31,15 @@ public class PassthroughBlockMaterial implements BlockMaterial {
this.blockMaterial = material;
}
@Override
public boolean isAir() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isAir();
}
}
@Override
public boolean isFullCube() {
if (blockMaterial == null) {
@ -110,6 +121,15 @@ public class PassthroughBlockMaterial implements BlockMaterial {
}
}
@Override
public int getLightOpacity() {
if (blockMaterial == null) {
return 0;
} else {
return blockMaterial.getLightOpacity();
}
}
@Override
public boolean isFragileWhenPushed() {
if (blockMaterial == null) {

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BlockMaterial;
class SimpleBlockMaterial implements BlockMaterial {
private boolean fullCube;
@ -39,6 +41,26 @@ class SimpleBlockMaterial implements BlockMaterial {
private boolean replacedDuringPlacement;
private boolean isTranslucent;
private boolean hasContainer;
private int lightOpacity;
private boolean isAir;
@Override
public boolean isAir() {
return isAir;
}
public void setAir(boolean air) {
isAir = air;
}
@Override
public int getLightOpacity() {
return lightOpacity;
}
public void setLightOpacity(int lightOpacity) {
this.lightOpacity = lightOpacity;
}
@Override
public boolean isFullCube() {