mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Merge current FAWE master (227d6d91
) into new-vector-system
Signed-off-by: Byron Marohn <combustible@live.com>
This commit is contained in:
@ -19,9 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
<<<<<<< HEAD
|
||||
import com.sk89q.worldedit.Vector;
|
||||
=======
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
@ -30,13 +27,20 @@ import com.sk89q.worldedit.registry.state.DirectionalProperty;
|
||||
import com.sk89q.worldedit.registry.state.EnumProperty;
|
||||
import com.sk89q.worldedit.registry.state.IntegerProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
final class ForgeAdapter {
|
||||
|
||||
private ForgeAdapter() {
|
||||
@ -71,9 +75,6 @@ final class ForgeAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public static BlockPos toBlockPos(Vector vector) {
|
||||
=======
|
||||
public static Direction adaptEnumFacing(EnumFacing face) {
|
||||
switch (face) {
|
||||
case NORTH: return Direction.NORTH;
|
||||
@ -88,8 +89,27 @@ final class ForgeAdapter {
|
||||
}
|
||||
|
||||
public static BlockPos toBlockPos(BlockVector3 vector) {
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
|
||||
}
|
||||
|
||||
public static Property<?> adaptProperty(IProperty<?> property) {
|
||||
if (property instanceof PropertyBool) {
|
||||
return new BooleanProperty(property.getName(), ImmutableList.copyOf(((PropertyBool) property).getAllowedValues()));
|
||||
}
|
||||
if (property instanceof PropertyInteger) {
|
||||
return new IntegerProperty(property.getName(), ImmutableList.copyOf(((PropertyInteger) property).getAllowedValues()));
|
||||
}
|
||||
if (property instanceof PropertyDirection) {
|
||||
return new DirectionalProperty(property.getName(), ((PropertyDirection) property).getAllowedValues().stream()
|
||||
.map(ForgeAdapter::adaptEnumFacing)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
if (property instanceof PropertyEnum) {
|
||||
return new EnumProperty(property.getName(), ((PropertyEnum<?>) property).getAllowedValues().stream()
|
||||
.map(e -> e.getName())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
return new IPropertyAdapter<>(property);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.forge;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
|
||||
|
||||
import net.minecraft.block.material.EnumPushReaction;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Forge block material that pulls as much info as possible from the Minecraft
|
||||
* Material, and passes the rest to another implementation, typically the
|
||||
* bundled block info.
|
||||
*/
|
||||
public class ForgeBlockMaterial extends PassthroughBlockMaterial {
|
||||
|
||||
private final Material delegate;
|
||||
|
||||
public ForgeBlockMaterial(Material delegate, @Nullable BlockMaterial secondary) {
|
||||
super(secondary);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return delegate == Material.AIR || super.isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaque() {
|
||||
return delegate.isOpaque();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return delegate.isLiquid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return delegate.isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFragileWhenPushed() {
|
||||
return delegate.getMobilityFlag() == EnumPushReaction.DESTROY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnpushable() {
|
||||
return delegate.getMobilityFlag() == EnumPushReaction.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMovementBlocker() {
|
||||
return delegate.blocksMovement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBurnable() {
|
||||
return delegate.getCanBurn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToolRequired() {
|
||||
return !delegate.isToolNotRequired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplacedDuringPlacement() {
|
||||
return delegate.isReplaceable();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.forge;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ForgeBlockRegistry extends BundledBlockRegistry {
|
||||
|
||||
private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public BlockMaterial getMaterial(BlockType blockType) {
|
||||
return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(),
|
||||
m -> new ForgeBlockMaterial(m, super.getMaterial(blockType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
|
||||
Map<String, Property<?>> map = new TreeMap<>();
|
||||
Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId())
|
||||
.getDefaultState()
|
||||
.getPropertyKeys();
|
||||
for (IProperty<?> key : propertyKeys) {
|
||||
map.put(key.getName(), ForgeAdapter.adaptProperty(key));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
* 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.forge;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
import com.sk89q.worldedit.world.registry.BlockRegistry;
|
||||
import com.sk89q.worldedit.world.registry.BundledRegistries;
|
||||
import com.sk89q.worldedit.world.registry.ItemRegistry;
|
||||
|
||||
@ -29,9 +30,15 @@ import com.sk89q.worldedit.world.registry.ItemRegistry;
|
||||
class ForgeRegistries extends BundledRegistries {
|
||||
|
||||
private static final ForgeRegistries INSTANCE = new ForgeRegistries();
|
||||
private final BlockRegistry blockRegistry = new ForgeBlockRegistry();
|
||||
private final BiomeRegistry biomeRegistry = new ForgeBiomeRegistry();
|
||||
private final ItemRegistry itemRegistry = new ForgeItemRegistry();
|
||||
|
||||
@Override
|
||||
public BlockRegistry getBlockRegistry() {
|
||||
return blockRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeRegistry getBiomeRegistry() {
|
||||
return biomeRegistry;
|
||||
|
@ -23,39 +23,44 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
<<<<<<< HEAD
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
=======
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.internal.Constants;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
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.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||
import com.sk89q.worldedit.world.weather.WeatherTypes;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLeaves;
|
||||
import net.minecraft.block.BlockOldLeaf;
|
||||
import net.minecraft.block.BlockOldLog;
|
||||
import net.minecraft.block.BlockPlanks;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
@ -67,7 +72,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@ -90,14 +97,17 @@ import net.minecraft.world.gen.feature.WorldGenTaiga1;
|
||||
import net.minecraft.world.gen.feature.WorldGenTaiga2;
|
||||
import net.minecraft.world.gen.feature.WorldGenTrees;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -174,7 +184,11 @@ public class ForgeWorld extends AbstractWorld {
|
||||
Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
IBlockState old = chunk.getBlockState(pos);
|
||||
IBlockState newState = Block.getBlockById(block.getBlockType().getLegacyId()).getDefaultState(); // TODO .getStateFromMeta(block.getData());
|
||||
Block mcBlock = Block.getBlockFromName(block.getBlockType().getId());
|
||||
IBlockState newState = mcBlock.getDefaultState();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Property<?>, Object> states = block.getStates();
|
||||
newState = applyProperties(mcBlock.getBlockState(), newState, states);
|
||||
IBlockState successState = chunk.setBlockState(pos, newState);
|
||||
boolean successful = successState != null;
|
||||
|
||||
@ -200,16 +214,39 @@ public class ForgeWorld extends AbstractWorld {
|
||||
return successful;
|
||||
}
|
||||
|
||||
// Can't get the "Object" to be right for withProperty w/o this
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) {
|
||||
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
|
||||
|
||||
IProperty property = stateContainer.getProperty(state.getKey().getName());
|
||||
Comparable value = (Comparable) state.getValue();
|
||||
// we may need to adapt this value, depending on the source prop
|
||||
if (property instanceof PropertyDirection) {
|
||||
Direction dir = (Direction) value;
|
||||
value = ForgeAdapter.adapt(dir);
|
||||
} else if (property instanceof PropertyEnum) {
|
||||
String enumName = (String) value;
|
||||
value = ((PropertyEnum<?>) property).parseValue((String) value).or(() -> {
|
||||
throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName);
|
||||
});
|
||||
}
|
||||
|
||||
newState = newState.withProperty(property, value);
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockLightLevel(BlockVector3 position) {
|
||||
checkNotNull(position);
|
||||
return getWorld().getLight(ForgeAdapter.toBlockPos(position));
|
||||
return getWorld().getLight(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearContainerBlockContents(BlockVector3 position) {
|
||||
checkNotNull(position);
|
||||
TileEntity tile = getWorld().getTileEntity(ForgeAdapter.toBlockPos(position));
|
||||
TileEntity tile = getWorld().getTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
|
||||
if ((tile instanceof IInventory)) {
|
||||
IInventory inv = (IInventory) tile;
|
||||
int size = inv.getSizeInventory();
|
||||
@ -356,8 +393,6 @@ public class ForgeWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
public void checkLoadedChunk(BlockVector3 pt) {
|
||||
getWorld().getChunkFromBlockCoords(ForgeAdapter.toBlockPos(pt));
|
||||
}
|
||||
@ -382,34 +417,74 @@ public class ForgeWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
public WeatherType getWeather() {
|
||||
// TODO Weather implementation
|
||||
return null;
|
||||
WorldInfo info = getWorld().getWorldInfo();
|
||||
if (info.isThundering()) {
|
||||
return WeatherTypes.THUNDER_STORM;
|
||||
}
|
||||
if (info.isRaining()) {
|
||||
return WeatherTypes.RAIN;
|
||||
}
|
||||
return WeatherTypes.CLEAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRemainingWeatherDuration() {
|
||||
return 0;
|
||||
WorldInfo info = getWorld().getWorldInfo();
|
||||
if (info.isThundering()) {
|
||||
return info.getThunderTime();
|
||||
}
|
||||
if (info.isRaining()) {
|
||||
return info.getRainTime();
|
||||
}
|
||||
return info.getCleanWeatherTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(WeatherType weatherType) {
|
||||
|
||||
setWeather(weatherType, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(WeatherType weatherType, long duration) {
|
||||
|
||||
WorldInfo info = getWorld().getWorldInfo();
|
||||
if (WeatherTypes.THUNDER_STORM.equals(weatherType)) {
|
||||
info.setCleanWeatherTime(0);
|
||||
info.setThundering(true);
|
||||
info.setThunderTime((int) duration);
|
||||
} else if (WeatherTypes.RAIN.equals(weatherType)) {
|
||||
info.setCleanWeatherTime(0);
|
||||
info.setRaining(true);
|
||||
info.setRainTime((int) duration);
|
||||
} else if (WeatherTypes.CLEAR.equals(weatherType)) {
|
||||
info.setRaining(false);
|
||||
info.setThundering(false);
|
||||
info.setCleanWeatherTime((int) duration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
World world = getWorld();
|
||||
BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
IBlockState mcState = world.getBlockState(pos);
|
||||
|
||||
return LegacyMapper.getInstance().getBlockFromLegacy(Block.getIdFromBlock(state.getBlock()), state.getBlock().getMetaFromState(state));
|
||||
BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getNameForObject(mcState.getBlock()).toString());
|
||||
return blockType.getState(adaptProperties(blockType, mcState.getProperties()));
|
||||
}
|
||||
|
||||
private Map<Property<?>, Object> adaptProperties(BlockType block, Map<IProperty<?>, Comparable<?>> mcProps) {
|
||||
Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName));
|
||||
for (Map.Entry<IProperty<?>, Comparable<?>> prop : mcProps.entrySet()) {
|
||||
Object value = prop.getValue();
|
||||
if (prop.getKey() instanceof PropertyDirection) {
|
||||
value = ForgeAdapter.adaptEnumFacing((EnumFacing) value);
|
||||
} else if (prop.getKey() instanceof PropertyEnum) {
|
||||
value = ((IStringSerializable) value).getName();
|
||||
}
|
||||
props.put(block.getProperty(prop.getKey().getName()), value);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,6 +38,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
@ -125,12 +126,18 @@ public class ForgeWorldEdit {
|
||||
this.provider = new ForgePermissionsProvider.VanillaPermissionsProvider(platform);
|
||||
}
|
||||
|
||||
for (Block block : Block.REGISTRY) {
|
||||
BlockTypes.register(new BlockType(Block.REGISTRY.getNameForObject(block).toString()));
|
||||
for (ResourceLocation name : Block.REGISTRY.getKeys()) {
|
||||
String nameStr = name.toString();
|
||||
if (!BlockType.REGISTRY.keySet().contains(nameStr)) {
|
||||
BlockTypes.register(new BlockType(nameStr));
|
||||
}
|
||||
}
|
||||
|
||||
for (Item item : Item.REGISTRY) {
|
||||
ItemTypes.register(new ItemType(Item.REGISTRY.getNameForObject(item).toString()));
|
||||
for (ResourceLocation name : Item.REGISTRY.getKeys()) {
|
||||
String nameStr = name.toString();
|
||||
if (!ItemType.REGISTRY.keySet().contains(nameStr)) {
|
||||
ItemTypes.register(new ItemType(nameStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.forge;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class IPropertyAdapter<T extends Comparable<T>> implements Property<T> {
|
||||
|
||||
private final IProperty<T> property;
|
||||
private final List<T> values;
|
||||
|
||||
public IPropertyAdapter(IProperty<T> property) {
|
||||
this.property = property;
|
||||
this.values = ImmutableList.copyOf(property.getAllowedValues());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return property.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValueFor(String string) throws IllegalArgumentException {
|
||||
Optional<T> val = property.parseValue(string);
|
||||
checkArgument(val.isPresent(), "%s has no value for %s", getName(), string);
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Property)) {
|
||||
return false;
|
||||
}
|
||||
return getName().equals(((Property<?>) obj).getName());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user