Remove all raw usages of BSH, improve API generics

This commit is contained in:
Kenzie Togami 2018-12-26 16:39:10 -08:00 committed by IronApollo
parent 1d87642b52
commit 590b7e23a9
105 changed files with 372 additions and 347 deletions

View File

@ -29,7 +29,6 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.*;
@ -53,6 +52,7 @@ import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock;
import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import javax.annotation.Nullable;
@ -357,7 +357,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
@SuppressWarnings("unchecked")
@Override
public Map<String, ? extends Property> getProperties(BlockType blockType) {
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Block block;
try {
block = IRegistry.BLOCK.getOrDefault(new MinecraftKey(blockType.getNamespace(), blockType.getResource()));
@ -369,7 +369,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
logger.warning("Failed to find properties for " + blockType.getId());
return Collections.emptyMap();
}
Map<String, Property> properties = Maps.newLinkedHashMap();
Map<String, Property<?>> properties = Maps.newLinkedHashMap();
BlockStateList<Block, IBlockData> blockStateList = block.getStates();
for (IBlockState state : blockStateList.d()) {
Property property;
@ -552,6 +552,16 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
@Override
public void notifyAndLightBlock(Location position, BlockState previousType) {
this.setBlock(position.getChunk(), position.getBlockX(), position.getBlockY(), position.getBlockZ(), previousType, true);
}
@Override
public boolean setBlock(Location location, BlockStateHolder<?> state, boolean notifyAndLight) {
return this.setBlock(location.getChunk(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), state, notifyAndLight);
}
@Override
public void sendFakeOP(Player player) {
// TODO Auto-generated method stub
}

View File

@ -146,8 +146,8 @@ public enum BukkitAdapter {
return getAdapter().adapt(material);
}
public static BlockData adapt(BlockStateHolder block) {
return getAdapter().adapt(block);
public static <B extends BlockStateHolder<B>> BlockData adapt(B block) {
return getAdapter().adapt(block);
}
public static BlockData getBlockData(int combinedId) {

View File

@ -290,4 +290,22 @@ public class BukkitPlayer extends AbstractPlayerActor {
}
@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
if (block == null) {
player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
} else {
player.sendBlockChange(loc, BukkitAdapter.adapt(block));
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData());
if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) {
adapter.sendFakeOP(player);
}
}
}
}
}
}

View File

@ -452,7 +452,7 @@ public class BukkitWorld extends AbstractWorld {
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
try {

View File

@ -22,15 +22,10 @@ package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
@ -38,6 +33,7 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Map;
@ -76,9 +72,18 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
*/
BlockState getBlock(Location location);
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder state, boolean update);
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder<?> state, boolean update);
boolean isChunkInUse(Chunk chunk);
/**
* Set the block at the given location.
*
* @param location the location
* @param state the block
* @param notifyAndLight notify and light if set
* @return true if a block was likely changed
*/
boolean setBlock(Location location, BlockStateHolder<?> state, boolean notifyAndLight);
/**
* Notifies the simulation that the block at the given location has
@ -114,19 +119,11 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param blockType The block type
* @return The properties map
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
default BlockMaterial getMaterial(BlockType blockType) {
return null;
}
/**
* Send the given NBT data to the player.
*
* @param player The player
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData);
default BlockMaterial getMaterial(BlockState blockState) {
return null;
@ -139,4 +136,21 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
default T fromNative(Tag foreign) {
return null;
}
/**
* Send the given NBT data to the player.
*
* @param player The player
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData);
/**
* Make the client think it has operator status.
* This does not give them any operator capabilities.
*
* @param player The player
*/
void sendFakeOP(Player player);
}

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.object;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.extent.ExtentHeightCacher;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -40,12 +41,12 @@ public class DataAnglePattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
BlockStateHolder block = extent.getBlock(position);
int slope = getSlope(block, position);
if (slope == -1) return block;
if (slope == -1) return block.toBaseBlock();
int data = (Math.min(slope, 255)) >> 4;
return block.withPropertyId(data);
return block.withPropertyId(data).toBaseBlock();
}
@Override

View File

@ -5,7 +5,7 @@ import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.DataAnglePattern;
import com.boydti.fawe.util.TextureHolder;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
@ -32,14 +32,14 @@ public class AngleColorPattern extends DataAnglePattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
BlockStateHolder block = extent.getBlock(position);
public BaseBlock apply(BlockVector3 position) {
BaseBlock block = extent.getFullBlock(position);
int slope = getSlope(block, position);
if (slope == -1) return block;
int color = util.getTextureUtil().getColor(block.getBlockType());
if (color == 0) return block;
int newColor = getColor(color, slope);
return util.getTextureUtil().getNearestBlock(newColor).getDefaultState();
return util.getTextureUtil().getNearestBlock(newColor).getDefaultState().toBaseBlock();
}
@Override

View File

@ -4,7 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.util.TextureHolder;
import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
@ -26,12 +26,12 @@ public class AverageColorPattern extends AbstractExtentPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
BlockStateHolder block = getExtent().getBlock(position);
public BaseBlock apply(BlockVector3 position) {
BaseBlock block = getExtent().getFullBlock(position);
TextureUtil util = holder.getTextureUtil();
int currentColor = util.getColor(block.getBlockType());
int newColor = util.averageColor(currentColor, color);
return util.getNearestBlock(newColor).getDefaultState();
return util.getNearestBlock(newColor).getDefaultState().toBaseBlock();
}
@Override

View File

@ -5,7 +5,7 @@ import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
import com.boydti.fawe.util.FaweTimer;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -33,7 +33,7 @@ public class BufferedPattern extends AbstractPattern implements ResettablePatter
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
return pattern.apply(position);
}

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.boydti.fawe.FaweCache;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
@ -22,9 +22,9 @@ public class DataPattern extends AbstractExtentPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
BlockStateHolder oldBlock = getExtent().getBlock(position);
BlockStateHolder newBlock = pattern.apply(position);
return oldBlock.withPropertyId(newBlock.getInternalPropertiesId());
public BaseBlock apply(BlockVector3 position) {
BaseBlock oldBlock = getExtent().getFullBlock(position);
BaseBlock newBlock = pattern.apply(position);
return oldBlock.withPropertyId(newBlock.getInternalPropertiesId()).toBaseBlock();
}
}

View File

@ -4,7 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.util.TextureHolder;
import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -26,7 +26,7 @@ public class DesaturatePattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
BlockType block = extent.getBlockType(position);
TextureUtil util = holder.getTextureUtil();
int color = util.getColor(block);
@ -39,7 +39,7 @@ public class DesaturatePattern extends AbstractPattern {
int green = (int) (g + value * (l - g));
int blue = (int) (b + value * (l - b));
int newColor = (alpha << 24) + (red << 16) + (green << 8) + (blue << 0);
return util.getNearestBlock(newColor).getDefaultState();
return util.getNearestBlock(newColor).getDefaultState().toBaseBlock();
}
@Override

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
@ -14,8 +14,8 @@ public class ExistingPattern extends AbstractExtentPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
return getExtent().getBlock(position);
public BaseBlock apply(BlockVector3 position) {
return getExtent().getFullBlock(position);
}
@Override

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.internal.expression.Expression;
@ -49,16 +50,16 @@ public class ExpressionPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 vector) {
public BaseBlock apply(BlockVector3 vector) {
try {
if (expression.getEnvironment() instanceof WorldEditExpressionEnvironment) {
((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector.toVector3());
}
double combined = expression.evaluate(vector.getX(), vector.getY(), vector.getZ());
return BlockState.getFromInternalId((int) combined);
return BlockState.getFromInternalId((int) combined).toBaseBlock();
} catch (EvaluationException e) {
e.printStackTrace();
return EditSession.nullBlock;
return EditSession.nullBlock.toBaseBlock();
} catch (Throwable e) {
e.printStackTrace();
throw e;

View File

@ -21,11 +21,11 @@ public class IdDataMaskPattern extends AbstractExtentPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
BlockStateHolder oldBlock = getExtent().getBlock(position);
BlockStateHolder newBlock = pattern.apply(position);
public BaseBlock apply(BlockVector3 position) {
BaseBlock oldBlock = getExtent().getFullBlock(position);
BaseBlock newBlock = pattern.apply(position);
int oldData = oldBlock.getInternalPropertiesId();
int newData = newBlock.getInternalPropertiesId() + oldData - (oldData & bitMask);
return newBlock.withPropertyId(newData);
return newBlock.withPropertyId(newData).toBaseBlock();
}
}

View File

@ -3,6 +3,7 @@ package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import static com.google.common.base.Preconditions.checkNotNull;
@ -17,9 +18,9 @@ public class IdPattern extends AbstractExtentPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
BlockStateHolder oldBlock = getExtent().getBlock(position);
BlockStateHolder newBlock = pattern.apply(position);
return newBlock.withPropertyId(oldBlock.getInternalPropertiesId());
public BaseBlock apply(BlockVector3 position) {
BaseBlock oldBlock = getExtent().getFullBlock(position);
BaseBlock newBlock = pattern.apply(position);
return newBlock.withPropertyId(oldBlock.getInternalPropertiesId()).toBaseBlock();
}
}

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -18,7 +18,7 @@ public class Linear2DBlockPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
int index = (position.getBlockX() + position.getBlockZ()) % patternsArray.length;
if (index < 0) {
index += patternsArray.length;

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -18,7 +18,7 @@ public class Linear3DBlockPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length;
if (index < 0) {
index += patternsArray.length;

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -19,7 +19,7 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
if (index == patternsArray.length) {
index = 0;
}

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
@ -24,10 +24,10 @@ public class MaskedPattern extends AbstractPattern {
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
patternExtent.setTarget(position);
if (mask.test(position)) {
return patternExtent.getAndResetTarget();
return patternExtent.getAndResetTarget().toBaseBlock();
}
return secondaryPattern.apply(position);
}

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -22,7 +22,7 @@ public class NoXPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 pos) {
public BaseBlock apply(BlockVector3 pos) {
// mutable.mutY((pos.getY()));
// mutable.mutZ((pos.getZ()));
// return pattern.apply(mutable.toBlockVector3());

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -23,7 +23,7 @@ public class NoYPattern extends AbstractPattern {
// private transient MutableBlockVector mutable = new MutableBlockVector();
@Override
public BlockStateHolder apply(BlockVector3 pos) {
public BaseBlock apply(BlockVector3 pos) {
// mutable.mutX((pos.getX()));
// mutable.mutZ((pos.getZ()));
return pattern.apply(pos);

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -23,7 +23,7 @@ public class NoZPattern extends AbstractPattern {
// private transient MutableBlockVector mutable = new MutableBlockVector();
@Override
public BlockStateHolder apply(BlockVector3 pos) {
public BaseBlock apply(BlockVector3 pos) {
// mutable.mutX((pos.getX()));
// mutable.mutY((pos.getY()));
return pattern.apply(pos);

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -26,7 +26,7 @@ public class OffsetPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
// mutable.mutX((position.getX() + dx));
// mutable.mutY((position.getY() + dy));
// mutable.mutZ((position.getZ() + dz));

View File

@ -123,7 +123,7 @@ public class PatternExtent extends AbstractPattern implements Extent {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
return pattern.apply(position);
}

View File

@ -192,25 +192,25 @@ public class PropertyPattern extends AbstractExtentPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
BlockState block = getExtent().getBlock(position);
public BaseBlock apply(BlockVector3 position) {
BaseBlock block = getExtent().getFullBlock(position);
return apply(block, block);
}
public BlockState apply(BlockState block, BlockState orDefault) {
public BaseBlock apply(BaseBlock block, BaseBlock orDefault) {
int ordinal = block.getOrdinal();
int newOrdinal = transformed[ordinal];
if (newOrdinal != ordinal) {
CompoundTag nbt = block.getNbtData();
BlockState newState = BlockState.getFromOrdinal(newOrdinal);
return nbt != null ? new BaseBlock(newState, nbt).toImmutableState() : newState;
return nbt != null ? new BaseBlock(newState, nbt) : newState.toBaseBlock();
}
return orDefault;
}
@Override
public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException {
BlockState block = getExtent().getBlock(get);
BaseBlock block = getExtent().getFullBlock(get);
block = apply(block, null);
if (block != null) {
return extent.setBlock(set, block);

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -34,7 +34,7 @@ public class RandomOffsetPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
mutable.mutX((position.getX() + r.nextInt(dx2) - dx));
mutable.mutY((position.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz));

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -23,7 +23,7 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter
}
@Override
public BlockStateHolder apply(BlockVector3 pos) {
public BaseBlock apply(BlockVector3 pos) {
if (origin == null) {
origin = pos;
}

View File

@ -4,7 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.util.TextureHolder;
import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -28,12 +28,12 @@ public class SaturatePattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
BlockType block = extent.getBlockType(position);
TextureUtil util = holder.getTextureUtil();
int currentColor = util.getColor(block);
int newColor = util.multiplyColor(currentColor, color);
return util.getNearestBlock(newColor).getDefaultState();
return util.getNearestBlock(newColor).getDefaultState().toBaseBlock();
}
@Override

View File

@ -2,7 +2,7 @@ package com.boydti.fawe.object.pattern;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
@ -28,9 +28,9 @@ public class ShadePattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
BlockType block = extent.getBlockType(position);
return (darken ? util.getDarkerBlock(block) : util.getLighterBlock(block)).getDefaultState();
return (darken ? util.getDarkerBlock(block) : util.getLighterBlock(block)).getDefaultState().toBaseBlock();
}
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {

View File

@ -2,7 +2,7 @@ package com.boydti.fawe.object.pattern;
import com.boydti.fawe.FaweCache;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
@ -43,11 +43,11 @@ public class SolidRandomOffsetPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
mutable.mutX((position.getX() + r.nextInt(dx2) - dx));
mutable.mutY((position.getY() + r.nextInt(dy2) - dy));
mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz));
BlockStateHolder block = pattern.apply(mutable.toBlockVector3());
BaseBlock block = pattern.apply(mutable.toBlockVector3());
if (solid[block.getInternalBlockTypeId()]) {
return block;
} else {

View File

@ -2,7 +2,7 @@ package com.boydti.fawe.object.pattern;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.PseudoRandom;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.function.pattern.AbstractPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
@ -38,7 +38,7 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
return pattern.apply(travel(position));
}

View File

@ -1027,7 +1027,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return whether the block changed
* @throws WorldEditException thrown on a set error
*/
public boolean setBlock(BlockVector3 position, BlockStateHolder block, Stage stage) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException {
this.changes++;
switch (stage) {
case BEFORE_HISTORY:
@ -1041,7 +1041,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
throw new RuntimeException("New enum entry added that is unhandled here");
}
public boolean rawSetBlock(BlockVector3 position, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) {
try {
return this.bypassAll.setBlock(position, block);
} catch (final WorldEditException e) {
@ -1056,7 +1056,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @param block the block
* @return whether the block changed
*/
public boolean smartSetBlock(BlockVector3 position, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean smartSetBlock(BlockVector3 position, B block) {
try {
return setBlock(position, block, Stage.BEFORE_REORDER);
} catch (WorldEditException e) {
@ -1065,7 +1065,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException {
this.changes++;
try {
return this.extent.setBlock(position, block);
@ -1611,7 +1611,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
@SuppressWarnings("deprecation")
public int setBlocks(final Region region, final BlockStateHolder block) {
public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) {
checkNotNull(region);
checkNotNull(block);
if (canBypassAll(region, false, true) && !block.hasNbtData()) {
@ -1670,7 +1670,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int replaceBlocks(Region region, Set<BlockStateHolder> filter, BlockStateHolder replacement) throws MaxChangedBlocksException {
public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BlockStateHolder> filter, B replacement) throws MaxChangedBlocksException {
return replaceBlocks(region, filter, new BlockPattern(replacement));
}
@ -1748,7 +1748,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
@SuppressWarnings("deprecation")
public int makeCuboidFaces(final Region region, final BlockStateHolder block) {
public <B extends BlockStateHolder<B>> int makeCuboidFaces(final Region region, final B block) {
return this.makeCuboidFaces(region, (Pattern) (block));
}
@ -1803,7 +1803,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
@SuppressWarnings("deprecation")
public int makeCuboidWalls(final Region region, final BlockStateHolder block) {
public <B extends BlockStateHolder<B>> int makeCuboidWalls(final Region region, final B block) {
return this.makeCuboidWalls(region, (Pattern) (block));
}
@ -1865,7 +1865,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int overlayCuboidBlocks(Region region, BlockStateHolder block) throws MaxChangedBlocksException {
public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException {
checkNotNull(block);
return this.overlayCuboidBlocks(region, (Pattern) (block));
}
@ -2947,7 +2947,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
final ArbitraryShape shape = new ArbitraryShape(region) {
@Override
public BlockStateHolder getMaterial(final int x, final int y, final int z, final BlockStateHolder defaultMaterial) {
public BaseBlock getMaterial(final int x, final int y, final int z, final BaseBlock defaultMaterial) {
//TODO Optimize - avoid vector creation (math)
// final Vector3 current = mutablev.setComponents(x, y, z);
// protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) {
@ -2961,7 +2961,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
return null;
}
return BlockTypes.get((int) typeVariable.getValue()).withPropertyId((int) dataVariable.getValue());
return BlockTypes.get((int) typeVariable.getValue()).withPropertyId((int) dataVariable.getValue()).toBaseBlock();
} catch (final Exception e) {
Fawe.debug("Failed to create shape: " + e);
return null;

View File

@ -180,9 +180,9 @@ public final class Blocks {
* @param o the block
* @return true if the collection contains the given block
*/
public static boolean containsFuzzy(Collection<? extends BlockStateHolder> collection, BlockStateHolder o) {
public static <B extends BlockStateHolder<B>> boolean containsFuzzy(Collection<? extends BlockStateHolder<?>> collection, B o) {
// Allow masked data in the searchBlocks to match various types
for (BlockStateHolder b : collection) {
for (BlockStateHolder<?> b : collection) {
if (b.equalsFuzzy(o)) {
return true;
}

View File

@ -45,7 +45,6 @@ import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
@Command(aliases = {}, desc = "Commands for moving the player around: [More Info](https://goo.gl/uQTUiT)")
public class NavigationCommands {
@SuppressWarnings("unused")
private final WorldEdit worldEdit;
/**

View File

@ -74,6 +74,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.biome.Biomes;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

View File

@ -88,6 +88,7 @@ import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.util.command.parametric.ParameterData;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.imageio.ImageIO;

View File

@ -36,7 +36,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
/**
* A mode that replaces one block.

View File

@ -30,8 +30,7 @@ import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
/**
* A tool that can place (or remove) blocks at a distance.
@ -60,7 +59,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
try {
// eS.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BlockStateHolder applied = secondary.apply(blockPoint);
BaseBlock applied = secondary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(blockPoint, secondary);
} else {
@ -82,7 +81,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
try {
// eS.disableBuffering();
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BlockStateHolder applied = primary.apply(blockPoint);
BaseBlock applied = primary.apply(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(blockPoint, primary);
} else {

View File

@ -28,7 +28,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
/**
* Looks up information about a block.
@ -46,7 +46,7 @@ public class QueryTool implements BlockTool {
World world = (World) clicked.getExtent();
EditSession editSession = session.createEditSession(player);
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
BlockStateHolder block = editSession.getFullBlock(blockPoint);
BaseBlock block = editSession.getFullBlock(blockPoint);
player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e"
+ block.getBlockType().getName() + "\u00A77" + " ("

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.pattern.Pattern;
@ -47,23 +46,11 @@ public class GravityBrush implements Brush {
int endY = position.getBlockY() + size;
int startPerformY = Math.max(0, position.getBlockY() - size);
int startCheckY = fullHeight ? 0 : startPerformY;
// Vector mutablePos = new Vector(0, 0, 0);
for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
int freeSpot = startCheckY;
for (int y = startCheckY; y <= endY; y++) {
BlockStateHolder block = editSession.getLazyBlock(x, y, z);
//=======
// public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
// final double startY = fullHeight ? editSession.getWorld().getMaxY() : position.getBlockY() + size;
// for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
// for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
// double y = startY;
// final List<BlockStateHolder> blockTypes = new ArrayList<>();
// for (; y > position.getBlockY() - size; --y) {
// final BlockVector3 pt = new BlockVector3(x, y, z);
// final BlockStateHolder block = editSession.getBlock(pt);
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
if (!block.getBlockType().getMaterial().isAir()) {
if (y != freeSpot) {
editSession.setBlock(x, y, z, EditSession.nullBlock);
@ -72,17 +59,6 @@ public class GravityBrush implements Brush {
freeSpot = y + 1;
}
}
//<<<<<<< HEAD
//=======
// BlockVector3 pt = new BlockVector3(x, y, z);
// Collections.reverse(blockTypes);
// for (int i = 0; i < blockTypes.size();) {
// if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) {
// editSession.setBlock(pt, blockTypes.get(i++));
// }
// pt = pt.add(0, 1, 0);
// }
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
}
}

View File

@ -276,5 +276,5 @@ public interface Player extends Entity, Actor {
* @param pos The position of the block
* @param block The block to send, null to reset
*/
void sendFakeBlock(BlockVector3 pos, @Nullable BlockStateHolder block);
<B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, @Nullable B block);
}

View File

@ -23,10 +23,11 @@ import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.extension.factory.parser.DefaultBlockParser;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.HashSet;
import java.util.Set;
@ -37,7 +38,7 @@ import java.util.Set;
* <p>Instances of this class can be taken from
* {@link WorldEdit#getBlockFactory()}.</p>
*/
public class BlockFactory extends AbstractFactory<BlockStateHolder> {
public class BlockFactory extends AbstractFactory<BaseBlock> {
/**
* Create a new instance.
@ -58,8 +59,8 @@ public class BlockFactory extends AbstractFactory<BlockStateHolder> {
* @return a set of blocks
* @throws InputParseException thrown in error with the input
*/
public Set<BlockStateHolder> parseFromListInput(String input, ParserContext context) throws InputParseException {
Set<BlockStateHolder> blocks = new HashSet<>();
public Set<BaseBlock> parseFromListInput(String input, ParserContext context) throws InputParseException {
Set<BaseBlock> blocks = new HashSet<>();
String[] splits = input.split(",");
for (String token : StringUtil.parseListInQuotes(splits, ',', '[', ']')) {
blocks.add(parseFromInput(token, context));

View File

@ -34,7 +34,6 @@ import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.SkullBlock;
@ -53,8 +52,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World;
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.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
@ -69,7 +68,7 @@ import java.util.stream.Stream;
/**
* Parses block input strings.
*/
public class DefaultBlockParser extends InputParser<BlockStateHolder> {
public class DefaultBlockParser extends InputParser<BaseBlock> {
public DefaultBlockParser(WorldEdit worldEdit) {
super(worldEdit);
@ -89,13 +88,14 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
}
}
public BlockStateHolder parseFromInput(String input, ParserContext context)
@Override
public BaseBlock parseFromInput(String input, ParserContext context)
throws InputParseException {
String originalInput = input;
input = input.replace(";", "|");
Exception suppressed = null;
try {
BlockStateHolder modified = parseLogic(input, context);
BaseBlock modified = parseLogic(input, context);
if (modified != null) {
return modified;
}
@ -164,7 +164,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
}
}
private BlockStateHolder parseLogic(String input, ParserContext context) throws InputParseException {
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
String[] blockAndExtraData = input.trim().split("\\|", 2);
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
@ -320,7 +320,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
return new SkullBlock(state, type.replace(" ", "_")); // valid MC usernames
} else {
return state;
return state.toBaseBlock();
}
}
}

View File

@ -28,7 +28,7 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
public class RandomPatternParser extends InputParser<Pattern> {
@ -43,7 +43,7 @@ public class RandomPatternParser extends InputParser<Pattern> {
String[] splits = input.split(",");
for (String token : StringUtil.parseListInQuotes(splits, ',', '[', ']')) {
BlockStateHolder block;
BaseBlock block;
double chance;

View File

@ -532,7 +532,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
}
@Override
public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
}
}

View File

@ -187,7 +187,7 @@ public class PlayerProxy extends AbstractPlayerActor {
}
@Override
public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) {
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
basePlayer.sendFakeBlock(pos, block);
}
}

View File

@ -64,7 +64,7 @@ public class ChangeSetExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
BlockStateHolder previous = getBlock(location);
changeSet.add(new BlockChange(location, previous, block));
return super.setBlock(location, block);

View File

@ -73,7 +73,7 @@ public class MaskingExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
return mask.test(location) && super.setBlock(location, block);
}

View File

@ -105,7 +105,7 @@ public class NullExtent implements Extent {
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
return false;
}

View File

@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.AbstractRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -47,7 +48,7 @@ import java.util.Map;
*/
public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern {
private final Map<BlockVector3, BlockStateHolder> buffer = new LinkedHashMap<>();
private final Map<BlockVector3, BaseBlock> buffer = new LinkedHashMap<>();
private final Mask mask;
private BlockVector3 min = null;
private BlockVector3 max = null;
@ -76,7 +77,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
// Update minimum
if (min == null) {
min = location;
@ -93,7 +94,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
BlockVector3 blockVector = location;
if (mask.test(blockVector)) {
buffer.put(blockVector, block);
buffer.put(blockVector, block.toBaseBlock());
return true;
} else {
return getExtent().setBlock(location, block);
@ -101,12 +102,12 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat
}
@Override
public BlockStateHolder apply(BlockVector3 pos) {
BlockStateHolder block = buffer.get(pos);
public BaseBlock apply(BlockVector3 pos) {
BaseBlock block = buffer.get(pos);
if (block != null) {
return block;
} else {
return BlockTypes.AIR.getDefaultState();
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
}

View File

@ -135,6 +135,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public void close() {
IMP.close();
}
@Override
@ -197,18 +198,10 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) {
//<<<<<<< HEAD
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
//=======
// BlockVector3 v = position.subtract(region.getMinimumPoint());
// BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()];
// if (block != null) {
// return block.toImmutableState();
// }
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
return EditSession.nullBlock;
}
@ -239,21 +232,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (region.contains(location)) {
final int x = location.getBlockX();
final int y = location.getBlockY();
final int z = location.getBlockZ();
return setBlock(x, y, z, block);
//=======
// public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
// if (region.contains(position)) {
// BlockVector3 v = position.subtract(region.getMinimumPoint());
// blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block;
// return true;
// } else {
// return false;
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
return false;
}
@ -266,7 +250,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
x -= mx;
y -= my;
z -= mz;

View File

@ -26,6 +26,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Map;
public interface NBTCompatibilityHandler {
boolean isAffectedBlock(BlockStateHolder block);
void updateNBT(BlockStateHolder block, Map<String, Tag> values);
<B extends BlockStateHolder<B>> boolean isAffectedBlock(B block);
<B extends BlockStateHolder<B>> void updateNBT(B block, Map<String, Tag> values);
}

View File

@ -33,13 +33,14 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Map;
public class SignCompatibilityHandler implements NBTCompatibilityHandler {
@Override
public boolean isAffectedBlock(BlockStateHolder block) {
public <B extends BlockStateHolder<B>> boolean isAffectedBlock(B block) {
return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN;
}
@Override
public void updateNBT(BlockStateHolder block, Map<String, Tag> values) {
public <B extends BlockStateHolder<B>> void updateNBT(B block, Map<String, Tag> values) {
for (int i = 0; i < 4; ++i) {
String key = "Text" + (i + 1);
Tag value = values.get(key);

View File

@ -86,12 +86,12 @@ public class BlockBagExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 pos, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 pos, B block) throws WorldEditException {
return setBlock(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), block);
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if(blockBag != null) {
BlockStateHolder lazyBlock = getExtent().getLazyBlock(x, y, z);
BlockType fromType = lazyBlock.getBlockType();

View File

@ -73,7 +73,7 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (!enabled) {
return getExtent().setBlock(location, block);
}

View File

@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.LocatedBlock;
import com.sk89q.worldedit.util.collection.LocatedBlockList;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -108,7 +109,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
* @param block The block
* @return The priority
*/
public int getPlacementPriority(BlockStateHolder block) {
public <B extends BlockStateHolder<B>> int getPlacementPriority(B block) {
if (Blocks.shouldPlaceLate(block.getBlockType())) {
return 1;
} else if (Blocks.shouldPlaceLast(block.getBlockType())) {
@ -123,7 +124,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (!enabled) {
return super.setBlock(location, block);
}

View File

@ -77,7 +77,7 @@ public class BlockChangeLimiter extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (limit >= 0) {
if (count >= limit) {
throw new MaxChangedBlocksException(limit);

View File

@ -49,7 +49,7 @@ public class DataValidatorExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
final int y = location.getBlockY();
final BlockType type = block.getBlockType();
if (y < 0 || y > world.getMaxY()) {

View File

@ -51,7 +51,7 @@ public class BlockQuirkExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
BlockType existing = getExtent().getBlock(position).getBlockType();
if (existing.getMaterial().hasContainer()) {

View File

@ -61,7 +61,7 @@ public class ChunkLoadingExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
world.checkLoadedChunk(location);
return super.setBlock(location, block);
}

View File

@ -99,8 +99,8 @@ public class FastModeExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
if (enabled) {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (enabled || postEditSimulation) {
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4));
if (world.setBlock(location, block, false)) {

View File

@ -81,7 +81,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
if (toolUse && block.getBlockType().getMaterial().isAir()) {
world.simulateBlockMine(location);
return true;

View File

@ -25,7 +25,6 @@ import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.ArrayList;
import java.util.Collections;
@ -36,27 +35,27 @@ import java.util.Map;
public class BlockDistributionCounter implements RegionFunction {
private Extent extent;
private boolean fuzzy;
private boolean separateStates;
private List<Countable<BlockStateHolder>> distribution = new ArrayList<>();
private Map<BlockStateHolder, Countable<BlockStateHolder>> map = new HashMap<>();
private List<Countable<BlockState>> distribution = new ArrayList<>();
private Map<BlockState, Countable<BlockState>> map = new HashMap<>();
public BlockDistributionCounter(Extent extent, boolean fuzzy) {
public BlockDistributionCounter(Extent extent, boolean separateStates) {
this.extent = extent;
this.fuzzy = fuzzy;
this.separateStates = separateStates;
}
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockStateHolder blk = extent.getBlock(position);
if (fuzzy) {
blk = ((BlockState) blk).toFuzzy();
BlockState blk = extent.getBlock(position);
if (!separateStates) {
blk = blk.getBlockType().getDefaultState();
}
if (map.containsKey(blk)) {
map.get(blk).increment();
} else {
Countable<BlockStateHolder> c = new Countable<>(blk, 1);
Countable<BlockState> c = new Countable<>(blk, 1);
map.put(blk, c);
distribution.add(c);
}
@ -69,7 +68,7 @@ public class BlockDistributionCounter implements RegionFunction {
*
* @return The distribution
*/
public List<Countable<BlockStateHolder>> getDistribution() {
public List<Countable<BlockState>> getDistribution() {
Collections.sort(distribution);
Collections.reverse(distribution);
return this.distribution;

View File

@ -27,6 +27,8 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
/**
@ -104,7 +106,7 @@ public class FloraGenerator implements RegionFunction {
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockStateHolder block = editSession.getBlock(position);
BlockState block = editSession.getBlock(position);
if (block.getBlockType() == BlockTypes.GRASS_BLOCK) {
editSession.setBlock(position.add(0, 1, 0), temperatePattern.apply(position));

View File

@ -24,7 +24,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -50,7 +50,7 @@ public class ForestGenerator implements RegionFunction {
@Override
public boolean apply(BlockVector3 position) throws WorldEditException {
BlockStateHolder block = editSession.getBlock(position);
BlockState block = editSession.getBlock(position);
BlockType t = block.getBlockType();
if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) {

View File

@ -198,7 +198,7 @@ public class GardenPatchGenerator implements RegionFunction {
* @return if block was changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
private static boolean setBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException {
private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException {
return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block);
}

View File

@ -11,11 +11,14 @@ import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;
import java.util.ArrayList;

View File

@ -12,10 +12,15 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
@Deprecated
public class BlockPattern implements Pattern {
private BlockStateHolder block;
private BaseBlock block;
public BlockPattern(BlockStateHolder block) {
this.block = block;
/**
* Create a new pattern with the given block.
*
* @param block the block
*/
public BlockPattern(BlockStateHolder<?> block) {
setBlock(block);
}
/**
@ -23,7 +28,7 @@ public class BlockPattern implements Pattern {
*
* @return the block that is always returned
*/
public BlockStateHolder getBlock() {
public BaseBlock getBlock() {
return block;
}
@ -32,13 +37,13 @@ public class BlockPattern implements Pattern {
*
* @param block the block
*/
public void setBlock(BlockStateHolder block) {
public void setBlock(BlockStateHolder<?> block) {
checkNotNull(block);
this.block = block;
this.block = block.toBaseBlock();
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
return block;
}

View File

@ -6,7 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
import static com.google.common.base.Preconditions.checkNotNull;
@ -37,23 +37,14 @@ public class ClipboardPattern extends AbstractPattern {
}
@Override
//<<<<<<< HEAD
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
int xp = position.getBlockX() % sx;
int yp = position.getBlockY() % sy;
int zp = position.getBlockZ() % sz;
if (xp < 0) xp += sx;
if (yp < 0) yp += sy;
if (zp < 0) zp += sz;
return clipboard.getBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
//=======
// public BlockStateHolder apply(BlockVector3 position) {
// int xp = Math.abs(position.getBlockX()) % size.getBlockX();
// int yp = Math.abs(position.getBlockY()) % size.getBlockY();
// int zp = Math.abs(position.getBlockZ()) % size.getBlockZ();
//
// return clipboard.getFullBlock(clipboard.getMinimumPoint().add(xp, yp, zp));
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
return clipboard.getFullBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
}

View File

@ -7,6 +7,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.NullExtent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
/**
@ -17,7 +18,7 @@ import com.sk89q.worldedit.world.block.BlockState;
public interface FawePattern extends Pattern {
@Deprecated
default BlockStateHolder apply(BlockVector3 position) {
default BaseBlock apply(BlockVector3 position) {
throw new UnsupportedOperationException("Please use apply(extent, get, set)");
}

View File

@ -28,6 +28,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.NullExtent;
import com.sk89q.worldedit.internal.expression.runtime.Return;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
@ -55,7 +56,7 @@ public interface Pattern{
* @param position the position
* @return a block
*/
BlockStateHolder apply(BlockVector3 position);
BaseBlock apply(BlockVector3 position);
default boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, apply(get));

View File

@ -10,7 +10,7 @@ import com.sk89q.worldedit.extent.Extent;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.HashMap;
import java.util.LinkedHashSet;
@ -56,24 +56,8 @@ public class RandomPattern extends AbstractPattern {
this.patterns.add(pattern);
}
//<<<<<<< HEAD
public Set<Pattern> getPatterns() {
return patterns;
//=======
// @Override
// public BlockStateHolder apply(BlockVector3 position) {
// double r = random.nextDouble();
// double offset = 0;
//
// for (Chance chance : patterns) {
// if (r <= (offset + chance.getChance()) / max) {
// return chance.getPattern().apply(position);
// }
// offset += chance.getChance();
// }
//
// throw new RuntimeException("ProportionalFillPattern");
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
}
public RandomCollection<Pattern> getCollection() {
@ -81,7 +65,7 @@ public class RandomPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 get) {
public BaseBlock apply(BlockVector3 get) {
return collection.next(get.getBlockX(), get.getBlockY(), get.getBlockZ()).apply(get);
}

View File

@ -23,11 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.world.block.BaseBlock;
/**
* Returns the blocks from {@link Extent}, repeating when out of bounds.
@ -87,7 +83,7 @@ public class RepeatingExtentPattern extends AbstractPattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
public BaseBlock apply(BlockVector3 position) {
BlockVector3 base = position.add(offset);
BlockVector3 size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
int x = base.getBlockX() % size.getBlockX();

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
/**
@ -37,8 +38,8 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
public class BlockChange implements Change {
private final BlockVector3 position;
private final BlockStateHolder previous;
private final BlockStateHolder current;
private final BaseBlock previous;
private final BaseBlock current;
/**
* Create a new block change.
@ -47,13 +48,13 @@ public class BlockChange implements Change {
* @param previous the previous block
* @param current the current block
*/
public BlockChange(BlockVector3 position, BlockStateHolder previous, BlockStateHolder current) {
public <BP extends BlockStateHolder<BP>, BC extends BlockStateHolder<BC>> BlockChange(BlockVector3 position, BP previous, BC current) {
checkNotNull(position);
checkNotNull(previous);
checkNotNull(current);
this.position = position;
this.previous = previous;
this.current = current;
this.previous = previous.toBaseBlock();
this.current = current.toBaseBlock();
}
/**
@ -70,7 +71,7 @@ public class BlockChange implements Change {
*
* @return the previous block
*/
public BlockStateHolder getPrevious() {
public BaseBlock getPrevious() {
return previous;
}
@ -79,7 +80,7 @@ public class BlockChange implements Change {
*
* @return the current block
*/
public BlockStateHolder getCurrent() {
public BaseBlock getCurrent() {
return current;
}

View File

@ -202,10 +202,10 @@ public class WorldEditBinding extends BindingHelper {
return result instanceof BlockState ? (BlockState) result : result.toImmutableState();
}
@BindingMatch(type = BaseBlock.class,
@BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class},
behavior = BindingBehavior.CONSUMES,
consumedCount = 1)
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
return new BaseBlock(getBlockState(context));
}
@ -360,7 +360,6 @@ public class WorldEditBinding extends BindingHelper {
String input = context.next();
if (input != null) {
if (MathMan.isInteger(input)) return new BaseBiome(Integer.parseInt(input));
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
List<BaseBiome> knownBiomes = biomeRegistry.getBiomes();

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.internal.registry;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;

View File

@ -131,7 +131,7 @@ public class RegionIntersection extends AbstractRegion {
return false;
}
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings({"unchecked"})
@Override
public Iterator<BlockVector3> iterator() {
Iterator<BlockVector3>[] iterators = (Iterator<BlockVector3>[]) new Iterator[regions.size()];

View File

@ -121,7 +121,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
@Override
public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) {
if (position.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) {
if (position.equals(region.getCenter().toBlockPoint()) && region.getRadius().lengthSq() == 0) {
return false;
}

View File

@ -24,7 +24,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
/**
* Generates solid and hollow shapes according to materials returned by the
@ -51,7 +51,7 @@ public abstract class ArbitraryShape {
* @param defaultMaterial The material returned by the pattern for the current block.
* @return material to place or null to not place anything.
*/
protected abstract BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial);
protected abstract BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial);
/**
* Generates the shape.
@ -71,7 +71,7 @@ public abstract class ArbitraryShape {
int z = position.getBlockZ();
if (!hollow) {
final BlockStateHolder material = getMaterial(x, y, z, pattern.apply(position));
BaseBlock material = getMaterial(x, y, z, pattern.apply(position));
if (material != null && editSession.setBlock(position, material)) {
++affected;
}
@ -79,7 +79,7 @@ public abstract class ArbitraryShape {
continue;
}
final BlockStateHolder material = getMaterial(x, y, z, pattern.apply(position));
BaseBlock material = getMaterial(x, y, z, pattern.apply(position));
if (material == null) {
continue;
}

View File

@ -21,7 +21,7 @@ package com.sk89q.worldedit.regions.shape;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
/**
* Generates solid and hollow shapes according to materials returned by the
@ -34,7 +34,7 @@ public class RegionShape extends ArbitraryShape {
}
@Override
protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) {
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
if (!this.extent.contains(BlockVector3.at(x, y, z))) {
return null;
}

View File

@ -131,6 +131,6 @@ public class AbstractProperty<T> implements Property<T> {
if (!(obj instanceof Property)) {
return false;
}
return getName().equals(((Property) obj).getName());
return getName().equals(((Property<?>) obj).getName());
}
}

View File

@ -29,6 +29,7 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.io.file.FilenameException;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.io.File;
import java.util.ArrayList;
@ -153,7 +154,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @throws UnknownItemException
* @throws DisallowedItemException
*/
public BlockStateHolder getBlock(String input, boolean allAllowed) throws WorldEditException {
public BaseBlock getBlock(String input, boolean allAllowed) throws WorldEditException {
ParserContext context = new ParserContext();
context.setActor(player);
context.setWorld(player.getWorld());
@ -172,7 +173,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @throws UnknownItemException
* @throws DisallowedItemException
*/
public BlockStateHolder getBlock(String id) throws WorldEditException {
public BaseBlock getBlock(String id) throws WorldEditException {
return getBlock(id, false);
}
@ -201,7 +202,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @throws UnknownItemException
* @throws DisallowedItemException
*/
public Set<BlockStateHolder> getBlocks(String list, boolean allBlocksAllowed) throws WorldEditException {
public Set<BaseBlock> getBlocks(String list, boolean allBlocksAllowed) throws WorldEditException {
ParserContext context = new ParserContext();
context.setActor(player);
context.setWorld(player.getWorld());

View File

@ -22,7 +22,7 @@ package com.sk89q.worldedit.util;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.Objects;
@ -32,9 +32,9 @@ import java.util.Objects;
public final class LocatedBlock {
private final BlockVector3 location;
private final BlockStateHolder block;
private final BaseBlock block;
public LocatedBlock(BlockVector3 location, BlockStateHolder block) {
public LocatedBlock(BlockVector3 location, BaseBlock block) {
this.location = checkNotNull(location);
this.block = checkNotNull(block);
}
@ -43,7 +43,7 @@ public final class LocatedBlock {
return location;
}
public BlockStateHolder getBlock() {
public BaseBlock getBlock() {
return block;
}

View File

@ -250,7 +250,7 @@ public class TreeGenerator {
* @return whether a block was changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
private static boolean setChanceBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block, double probability)
private static <B extends BlockStateHolder<B>> boolean setChanceBlockIfAir(EditSession session, BlockVector3 position, B block, double probability)
throws MaxChangedBlocksException {
return Math.random() <= probability && setBlockIfAir(session, position, block);
}
@ -263,7 +263,7 @@ public class TreeGenerator {
* @return if block was changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
private static boolean setBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException {
private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException {
return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block);
}
}

View File

@ -51,8 +51,8 @@ public class LocatedBlockList implements Iterable<LocatedBlock> {
list.add(setBlockCall);
}
public void add(BlockVector3 location, BlockStateHolder block) {
add(new LocatedBlock(location, block));
public <B extends BlockStateHolder<B>> void add(BlockVector3 location, B block) {
add(new LocatedBlock(location, block.toBaseBlock()));
}
public int size() {

View File

@ -53,7 +53,7 @@ public abstract class AbstractWorld implements World {
}
@Override
public final boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException {
public final <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 pt, B block) throws WorldEditException {
return setBlock(pt, block, true);
}
@ -144,6 +144,7 @@ public abstract class AbstractWorld implements World {
this.priority = priority;
}
@SuppressWarnings("deprecation")
public void play() {
playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4);
}

View File

@ -60,7 +60,7 @@ public class NullWorld extends AbstractWorld {
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
return false;
}

View File

@ -54,7 +54,7 @@ public interface SimpleWorld extends World {
}
@Override
default boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
return setBlock(position, block);
}
@ -64,7 +64,7 @@ public interface SimpleWorld extends World {
}
@Override
boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException;
<B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 pt, B block) throws WorldEditException;
@Override
default int getMaxY() {

View File

@ -38,8 +38,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.weather.WeatherType;
import java.util.Vector;
/**
* Represents a world (dimension).
*/
@ -96,7 +94,7 @@ public interface World extends Extent {
* @param notifyAndLight true to to notify and light
* @return true if the block was successfully set (return value may not be accurate)
*/
boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException;
<B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException;
/**
* Notifies the simulation that the block at the given location has

View File

@ -52,7 +52,7 @@ public class BlockCategory extends Category<BlockType> {
* @param blockStateHolder The blockstateholder
* @return If it's a part of this category
*/
public boolean contains(BlockStateHolder blockStateHolder) {
public <B extends BlockStateHolder<B>> boolean contains(B blockStateHolder) {
return this.getAll().contains(blockStateHolder.getBlockType());
}
}

View File

@ -63,6 +63,18 @@ public class BlockState implements BlockStateHolder<BlockState> {
this.emptyBaseBlock = baseBlock;
}
/**
* Creates a fuzzy BlockState. This can be used for partial matching.
*
* @param blockType The block type
* @param values The block state values
*/
private BlockState(BlockType blockType, Map<Property<?>, Object> values) {
this.blockType = blockType;
// this.values = values;
// this.fuzzy = true;
}
/**
* Returns a temporary BlockState for a given internal id
* @param combinedId
@ -224,8 +236,8 @@ public class BlockState implements BlockStateHolder<BlockState> {
}
@Override
public BlockState apply(BlockVector3 position) {
return this;
public BaseBlock apply(BlockVector3 position) {
return this.toBaseBlock();
}
@Override
@ -330,15 +342,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
return this.blockType;
}
/**
* Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense
* @return
*/
@Deprecated
public BlockState toFuzzy() {
return this;
}
@Override
public int hashCode() {
return getOrdinal();
@ -349,10 +352,42 @@ public class BlockState implements BlockStateHolder<BlockState> {
return this == obj;
}
public BlockState toFuzzy() {
return new BlockState(this.getBlockType(), new HashMap<>());
}
@Override
@Deprecated
public boolean equalsFuzzy(BlockStateHolder o) {
return o.getOrdinal() == this.getOrdinal();
public boolean equalsFuzzy(BlockStateHolder<?> o) {
if (this == o) {
// Added a reference equality check for
return true;
}
if (!getBlockType().equals(o.getBlockType())) {
return false;
}
Set<Property<?>> differingProperties = new HashSet<>();
for (Object state : o.getStates().keySet()) {
if (getState((Property<?>) state) == null) {
differingProperties.add((Property<?>) state);
}
}
for (Property<?> property : getStates().keySet()) {
if (o.getState(property) == null) {
differingProperties.add(property);
}
}
for (Property<?> property : getStates().keySet()) {
if (differingProperties.contains(property)) {
continue;
}
if (!Objects.equals(getState(property), o.getState(property))) {
return false;
}
}
return true;
}
@Override

View File

@ -31,7 +31,7 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.util.Map;
import java.util.stream.Collectors;
public interface BlockStateHolder<T extends BlockStateHolder> extends FawePattern, TileEntityBlock {
public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePattern, TileEntityBlock {
/**
* Get the block type
@ -121,8 +121,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
* @param o other block
* @return true if equal
*/
@Deprecated
boolean equalsFuzzy(BlockStateHolder o);
boolean equalsFuzzy(BlockStateHolder<?> o);
/**
* Returns an immutable {@link BlockState} from this BlockStateHolder.

View File

@ -326,8 +326,8 @@ public class BlockType implements FawePattern {
}
@Override
public BlockStateHolder apply(BlockVector3 position) {
return this.getDefaultState();
public BaseBlock apply(BlockVector3 position) {
return this.getDefaultState().toBaseBlock();
}
public Mask toMask(Extent extent) {

View File

@ -32,8 +32,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
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.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
@ -254,14 +254,14 @@ public class AnvilChunk implements Chunk {
}
@Override
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
public BaseBlock getBlock(BlockVector3 position) throws DataException {
int id = getBlockID(position);
int data = getBlockData(position);
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (state == null) {
WorldEdit.logger.warning("Unknown legacy block " + id + ":" + data + " found when loading legacy anvil chunk.");
return BlockTypes.AIR.getDefaultState();
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
if (state.getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position);
@ -269,6 +269,8 @@ public class AnvilChunk implements Chunk {
return new BaseBlock(state, tileEntity);
}
}
return state; }
return state.toBaseBlock();
}
}

View File

@ -32,7 +32,6 @@ import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.DataException;
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.block.BlockTypes;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
@ -231,7 +230,7 @@ public class AnvilChunk13 implements Chunk {
}
@Override
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
public BaseBlock getBlock(BlockVector3 position) throws DataException {
int x = position.getX() - rootX * 16;
int y = position.getY();
int z = position.getZ() - rootZ * 16;
@ -249,7 +248,8 @@ public class AnvilChunk13 implements Chunk {
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) return new BaseBlock(state, tileEntity);
}
return state;
return state.toBaseBlock();
}
}

View File

@ -22,7 +22,7 @@ package com.sk89q.worldedit.world.chunk;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
/**
* A 16 by 16 block chunk.
@ -36,6 +36,6 @@ public interface Chunk {
* @return block the block
* @throws DataException thrown on data error
*/
BlockStateHolder getBlock(BlockVector3 position) throws DataException;
BaseBlock getBlock(BlockVector3 position) throws DataException;
}

View File

@ -30,8 +30,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
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.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
@ -154,13 +154,9 @@ public class OldChunk implements Chunk {
}
@Override
//<<<<<<< HEAD
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
if(position.getBlockY() >= 128) return BlockTypes.VOID_AIR.getDefaultState();
//=======
// public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
// if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
public BaseBlock getBlock(BlockVector3 position) throws DataException {
if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
int id, dataVal;
int x = position.getX() - rootX * 16;
@ -189,13 +185,13 @@ public class OldChunk implements Chunk {
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, dataVal);
if (state == null) {
WorldEdit.logger.warning("Unknown legacy block " + id + ":" + dataVal + " found when loading legacy anvil chunk.");
return BlockTypes.AIR.getDefaultState();
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
if (state.getBlockType().getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) return new BaseBlock(state, tileEntity);
}
return state;
return state.toBaseBlock();
}
}

View File

@ -66,7 +66,6 @@ public interface BlockRegistry {
*/
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
/**
* Register all blocks
*/

View File

@ -230,7 +230,7 @@ public class LegacyMapper {
return INSTANCE;
}
@SuppressWarnings({"MismatchedQueryAndUpdateOfCollection", "unused"})
@SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
private static class LegacyDataFile {
private Map<String, String> blocks;
private Map<String, String> items;

View File

@ -175,8 +175,12 @@ public class ForgePlayer extends AbstractPlayerActor {
@Override
<<<<<<< HEAD
<<<<<<< HEAD
=======
public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) {
=======
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
>>>>>>> 3fefcbf9... Remove all raw usages of BSH, improve API generics
BlockPos loc = ForgeAdapter.toBlockPos(pos);
if (block == null) {
// TODO

Some files were not shown because too many files have changed in this diff Show More