Plenty of changes to core block behavior to become more compatible with upstream WorldEdit (still more to be done!)

This commit is contained in:
IronApollo 2019-01-31 10:08:58 -05:00
parent 271b45f3ba
commit e53535319d
116 changed files with 3666 additions and 3774 deletions

View File

@ -1,5 +1,6 @@
package com.thevoxelbox.voxelsniper.brush; package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Undo; import com.thevoxelbox.voxelsniper.Undo;
@ -82,7 +83,7 @@ public class BlendBallBrush extends BlendBrushBase
} }
// Find most common neighboring material. // Find most common neighboring material.
for (BlockTypes type : BlockTypes.values) for (BlockType type : BlockTypes.values)
{ {
int i = type.getInternalId(); int i = type.getInternalId();
if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
@ -94,7 +95,7 @@ public class BlendBallBrush extends BlendBrushBase
// Make sure there'world not a tie for most common // Make sure there'world not a tie for most common
for (int i = 0; i < modeMatId; i++) for (int i = 0; i < modeMatId; i++)
{ {
BlockTypes type = BlockTypes.get(i); BlockType type = BlockTypes.get(i);
if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
{ {
tiecheck = false; tiecheck = false;

View File

@ -1,5 +1,6 @@
package com.thevoxelbox.voxelsniper.brush; package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Undo; import com.thevoxelbox.voxelsniper.Undo;
@ -69,7 +70,7 @@ public class BlendDiscBrush extends BlendBrushBase
} }
// Find most common neighboring material. // Find most common neighboring material.
for (BlockTypes type : BlockTypes.values) for (BlockType type : BlockTypes.values)
{ {
int i = type.getInternalId(); int i = type.getInternalId();
if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
@ -81,7 +82,7 @@ public class BlendDiscBrush extends BlendBrushBase
// Make sure there'world not a tie for most common // Make sure there'world not a tie for most common
for (int i = 0; i < modeMatId; i++) for (int i = 0; i < modeMatId; i++)
{ {
BlockTypes type = BlockTypes.get(i); BlockType type = BlockTypes.get(i);
if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
{ {
tiecheck = false; tiecheck = false;

View File

@ -1,5 +1,6 @@
package com.thevoxelbox.voxelsniper.brush; package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Undo; import com.thevoxelbox.voxelsniper.Undo;
@ -82,7 +83,7 @@ public class BlendVoxelBrush extends BlendBrushBase
} }
// Find most common neighboring material. // Find most common neighboring material.
for (BlockTypes type : BlockTypes.values) for (BlockType type : BlockTypes.values)
{ {
int i = type.getInternalId(); int i = type.getInternalId();
if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
@ -94,7 +95,7 @@ public class BlendVoxelBrush extends BlendBrushBase
// Make sure there'world not a tie for most common // Make sure there'world not a tie for most common
for (int i = 0; i < modeMatId; i++) for (int i = 0; i < modeMatId; i++)
{ {
BlockTypes type = BlockTypes.get(i); BlockType type = BlockTypes.get(i);
if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
{ {
tiecheck = false; tiecheck = false;

View File

@ -1,5 +1,6 @@
package com.thevoxelbox.voxelsniper.brush; package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
import com.thevoxelbox.voxelsniper.Undo; import com.thevoxelbox.voxelsniper.Undo;
@ -69,7 +70,7 @@ public class BlendVoxelDiscBrush extends BlendBrushBase
} }
// Find most common neighboring material. // Find most common neighboring material.
for (BlockTypes type : BlockTypes.values) for (BlockType type : BlockTypes.values)
{ {
int i = type.getInternalId(); int i = type.getInternalId();
if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] > modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
@ -81,7 +82,7 @@ public class BlendVoxelDiscBrush extends BlendBrushBase
// Make sure there'world not a tie for most common // Make sure there'world not a tie for most common
for (int i = 0; i < modeMatId; i++) for (int i = 0; i < modeMatId; i++)
{ {
BlockTypes type = BlockTypes.get(i); BlockType type = BlockTypes.get(i);
if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER))) if (materialFrequency[i] == modeMatCount && !(this.excludeAir && type.getMaterial().isAir()) && !(this.excludeWater && (type == BlockTypes.WATER)))
{ {
tiecheck = false; tiecheck = false;

View File

@ -1,5 +1,6 @@
package com.thevoxelbox.voxelsniper.brush; package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.Message;
@ -72,11 +73,11 @@ public class OverlayBrush extends PerformBrush
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private boolean isIgnoredBlock(int materialId) private boolean isIgnoredBlock(int materialId)
{ {
BlockTypes type = BlockTypes.get(materialId); BlockType type = BlockTypes.get(materialId);
switch (type) { switch (type.getResource().toUpperCase()) {
case WATER: case "WATER":
case LAVA: case "LAVA":
case CACTUS: case "CACTUS":
return true; return true;
} }
BlockMaterial mat = type.getMaterial(); BlockMaterial mat = type.getMaterial();
@ -123,7 +124,7 @@ public class OverlayBrush extends PerformBrush
if (!this.allBlocks) if (!this.allBlocks)
{ // if the override parameter has not been activated, go to the switch that filters out manmade stuff. { // if the override parameter has not been activated, go to the switch that filters out manmade stuff.
BlockTypes type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)); BlockType type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z));
BlockMaterial mat = type.getMaterial(); BlockMaterial mat = type.getMaterial();
if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer()) { if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer()) {
for (int d = 1; (d < this.depth + 1); d++) { for (int d = 1; (d < this.depth + 1); d++) {

View File

@ -95,14 +95,14 @@ public class SnowConeBrush extends Brush
if (snowData > snowconeData[x][z]) if (snowData > snowconeData[x][z])
{ {
switch (BlockTypes.get(snowcone[x][z])) switch (BlockTypes.get(snowcone[x][z]).getResource().toUpperCase())
{ {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
snowconeData[x][z] = snowData; snowconeData[x][z] = snowData;
snowcone[x][z] = BlockTypes.SNOW.getInternalId(); snowcone[x][z] = BlockTypes.SNOW.getInternalId();
case SNOW_BLOCK: case "SNOW_BLOCK":
snowconeData[x][z] = snowData; snowconeData[x][z] = snowData;
break; break;
default: default:

View File

@ -2,6 +2,7 @@ package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.Message;
@ -724,7 +725,7 @@ public class SpiralStaircaseBrush extends Brush
// step/slab // step/slab
try { try {
BlockTypes type = BlockTypes.parse(par[i]); BlockType type = BlockTypes.parse(par[i]);
this.stairtype = par[i].toLowerCase().intern(); this.stairtype = par[i].toLowerCase().intern();
v.sendMessage(ChatColor.BLUE + "Staircase type: " + this.stairtype); v.sendMessage(ChatColor.BLUE + "Staircase type: " + this.stairtype);
return; return;

View File

@ -1,5 +1,6 @@
package com.thevoxelbox.voxelsniper.brush; package com.thevoxelbox.voxelsniper.brush;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.thevoxelbox.voxelsniper.Message; import com.thevoxelbox.voxelsniper.Message;
@ -135,7 +136,7 @@ public class SplatterOverlayBrush extends PerformBrush
if (!this.allBlocks) if (!this.allBlocks)
{ {
// if the override parameter has not been activated, go to the switch that filters out manmade stuff. // if the override parameter has not been activated, go to the switch that filters out manmade stuff.
BlockTypes type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)); BlockType type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z));
BlockMaterial mat = type.getMaterial(); BlockMaterial mat = type.getMaterial();
if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer()) { if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer()) {
final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth; final int depth = randomizeHeight ? generator.nextInt(this.depth) : this.depth;
@ -268,7 +269,7 @@ public class SplatterOverlayBrush extends PerformBrush
if (!this.allBlocks) if (!this.allBlocks)
{ // if the override parameter has not been activated, go to the switch that filters out manmade stuff. { // if the override parameter has not been activated, go to the switch that filters out manmade stuff.
BlockTypes type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z)); BlockType type = BlockTypes.get(this.getBlockIdAt(this.getTargetBlock().getX() + x, y, this.getTargetBlock().getZ() + z));
BlockMaterial mat = type.getMaterial(); BlockMaterial mat = type.getMaterial();
if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer()) if (mat.isSolid() && mat.isFullCube() && !mat.hasContainer())
{ {

View File

@ -2,6 +2,7 @@ package com.thevoxelbox.voxelsniper.command;
import com.bekvon.bukkit.residence.commands.material; import com.bekvon.bukkit.residence.commands.material;
import com.boydti.fawe.bukkit.wrapper.AsyncBlock; import com.boydti.fawe.bukkit.wrapper.AsyncBlock;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.RangeBlockHelper;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
@ -39,7 +40,7 @@ public class VoxelReplaceCommand extends VoxelCommand
return true; return true;
} }
BlockTypes weType = BlockTypes.parse(args[0]); BlockType weType = BlockTypes.parse(args[0]);
if (weType != null) if (weType != null)
{ {
snipeData.setReplaceId(weType.getInternalId()); snipeData.setReplaceId(weType.getInternalId());

View File

@ -29,6 +29,7 @@ import com.bekvon.bukkit.residence.commands.material;
import com.boydti.fawe.bukkit.favs.PatternUtil; import com.boydti.fawe.bukkit.favs.PatternUtil;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.thevoxelbox.voxelsniper.RangeBlockHelper; import com.thevoxelbox.voxelsniper.RangeBlockHelper;
import com.thevoxelbox.voxelsniper.SnipeData; import com.thevoxelbox.voxelsniper.SnipeData;
@ -53,7 +54,7 @@ public class VoxelVoxelCommand extends VoxelCommand {
Block block = (new RangeBlockHelper(player, sniper.getWorld())).getTargetBlock(); Block block = (new RangeBlockHelper(player, sniper.getWorld())).getTargetBlock();
Material blockType = block.getType(); Material blockType = block.getType();
BlockTypes weType = BukkitAdapter.adapt(blockType); BlockType weType = BukkitAdapter.adapt(blockType);
if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(weType)) { if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(weType)) {
player.sendMessage("You are not allowed to use " + blockType.name() + ". (WorldEdit config.yml)"); player.sendMessage("You are not allowed to use " + blockType.name() + ". (WorldEdit config.yml)");
return true; return true;
@ -65,7 +66,7 @@ public class VoxelVoxelCommand extends VoxelCommand {
return true; return true;
} else { } else {
BlockTypes weType = BlockTypes.parse(args[0]); BlockType weType = BlockTypes.parse(args[0]);
if(weType != null) { if(weType != null) {
if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(weType)) { if(!player.hasPermission("voxelsniper.ignorelimitations") && WorldEdit.getInstance().getConfiguration().disallowedBlocks.contains(weType)) {
player.sendMessage("You are not allowed to use " + weType + "."); player.sendMessage("You are not allowed to use " + weType + ".");

View File

@ -190,7 +190,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
@Override @Override
public BlockMaterial getMaterial(BlockState state) { public BlockMaterial getMaterial(BlockState state) {
BlockTypes type = state.getBlockType(); BlockType type = state.getBlockType();
IBlockData bs = ((CraftBlockData) Bukkit.createBlockData(state.getAsString())).getState(); IBlockData bs = ((CraftBlockData) Bukkit.createBlockData(state.getAsString())).getState();
return new BlockMaterial_1_13(bs.getBlock(), bs); return new BlockMaterial_1_13(bs.getBlock(), bs);
} }
@ -233,7 +233,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
if (te != null) { if (te != null) {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
readTileEntityIntoTag(te, tag); // Load data readTileEntityIntoTag(te, tag); // Load data
return new BaseBlock(state, (CompoundTag) toNative(tag)); return new BaseBlock(state, (CompoundTag) toNative(tag)).toImmutableState();
} }
} }

View File

@ -232,12 +232,12 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
if (combined == 0) continue; if (combined == 0) continue;
int xx = bx + x; int xx = bx + x;
BlockTypes type = BlockTypes.getFromStateId(combined); BlockType type = BlockTypes.getFromStateId(combined);
if (type == BlockTypes.__RESERVED__) continue; if (type == BlockTypes.__RESERVED__) continue;
switch (type) { switch (type.getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
if (!place) { if (!place) {
mutableLoc.setX(xx); mutableLoc.setX(xx);
mutableLoc.setY(yy); mutableLoc.setY(yy);
@ -277,12 +277,12 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
for (;index < 4096; index++) { for (;index < 4096; index++) {
int j = place ? index : 4095 - index; int j = place ? index : 4095 - index;
int combined = newArray[j]; int combined = newArray[j];
BlockTypes type = BlockTypes.getFromStateId(combined); BlockType type = BlockTypes.getFromStateId(combined);
if (type == BlockTypes.__RESERVED__) continue; if (type == BlockTypes.__RESERVED__) continue;
switch (type) { switch (type.getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
if (!place) { if (!place) {
int x = cacheX[j]; int x = cacheX[j];
int z = cacheZ[j]; int z = cacheZ[j];

View File

@ -9,6 +9,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.FluidCollisionMode; import org.bukkit.FluidCollisionMode;
@ -214,10 +215,10 @@ public class AsyncBlock implements Block {
@Override @Override
public AsyncBlockState getState() { public AsyncBlockState getState() {
int combined = queue.getCombinedId4Data(x, y, z, 0); int combined = queue.getCombinedId4Data(x, y, z, 0);
BlockTypes type = BlockTypes.getFromStateId(combined); BlockType type = BlockTypes.getFromStateId(combined);
switch (type) { switch (type.getResource().toUpperCase()) {
case SIGN: case "SIGN":
case WALL_SIGN: case "WALL_SIGN":
return new AsyncSign(this, combined); return new AsyncSign(this, combined);
} }
return new AsyncBlockState(this, combined); return new AsyncBlockState(this, combined);
@ -284,7 +285,7 @@ public class AsyncBlock implements Block {
@Override @Override
public boolean isLiquid() { public boolean isLiquid() {
int combined = queue.getCombinedId4Data(x, y, z, 0); int combined = queue.getCombinedId4Data(x, y, z, 0);
BlockTypes type = BlockTypes.getFromStateId(combined); BlockType type = BlockTypes.getFromStateId(combined);
return type.getMaterial().isLiquid(); return type.getMaterial().isLiquid();
} }

View File

@ -22,6 +22,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -272,7 +273,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue
public int getHighestBlockYAt(int x, int z) { public int getHighestBlockYAt(int x, int z) {
for (int y = getMaxHeight() - 1; y >= 0; y--) { for (int y = getMaxHeight() - 1; y >= 0; y--) {
int stateId = queue.getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId()); int stateId = queue.getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
BlockTypes type = BlockTypes.getFromStateId(stateId); BlockType type = BlockTypes.getFromStateId(stateId);
if (!type.getMaterial().isAir()) return y; if (!type.getMaterial().isAir()) return y;
} }
return 0; return 0;

View File

@ -142,7 +142,7 @@ public enum BukkitAdapter {
return getAdapter().adapt(blockData); return getAdapter().adapt(blockData);
} }
public static BlockTypes adapt(Material material) { public static BlockType adapt(Material material) {
return getAdapter().adapt(material); return getAdapter().adapt(material);
} }

View File

@ -83,7 +83,7 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
@Nullable @Nullable
@Override @Override
public Map<String, ? extends Property> getProperties(BlockType blockType) { public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) { if (adapter != null) {
return adapter.getProperties(blockType); return adapter.getProperties(blockType);

View File

@ -96,7 +96,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
public void giveItem(BaseItemStack itemStack) { public void giveItem(BaseItemStack itemStack) {
final PlayerInventory inv = player.getInventory(); final PlayerInventory inv = player.getInventory();
ItemStack newItem = BukkitAdapter.adapt(itemStack); ItemStack newItem = BukkitAdapter.adapt(itemStack);
if (itemStack.getType() == WorldEdit.getInstance().getConfiguration().wandItem) { if (itemStack.getType().getId().equalsIgnoreCase(WorldEdit.getInstance().getConfiguration().wandItem)) {
inv.remove(newItem); inv.remove(newItem);
} }
final ItemStack item = player.getItemInHand(); final ItemStack item = player.getItemInHand();

View File

@ -478,10 +478,10 @@ public class BukkitWorld extends AbstractWorld {
} }
@Override @Override
public com.sk89q.worldedit.world.block.BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) { if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)); return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)).toBaseBlock();
} else { } else {
return getBlock(position).toBaseBlock(); return getBlock(position).toBaseBlock();
} }

View File

@ -5,6 +5,7 @@ import com.sk89q.worldedit.bukkit.adapter.IBukkitAdapter;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
@ -52,17 +53,17 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
@Override @Override
public ItemType asItemType(Material material) { public ItemType asItemType(Material material) {
try { try {
return ItemTypes.values[itemTypes[material.ordinal()]]; return ItemTypes.get(itemTypes[material.ordinal()]);
} catch (NullPointerException e) { } catch (NullPointerException e) {
if (init()) return asItemType(material); if (init()) return asItemType(material);
return ItemTypes.values[itemTypes[material.ordinal()]]; return ItemTypes.get(itemTypes[material.ordinal()]);
} }
} }
@Override @Override
public BlockTypes adapt(Material material) { public BlockType adapt(Material material) {
try { try {
return BlockTypes.values[blockTypes[material.ordinal()]]; return BlockTypes.values[blockTypes[material.ordinal()]];
} catch (NullPointerException e) { } catch (NullPointerException e) {
if (init()) return adapt(material); if (init()) return adapt(material);
throw e; throw e;
@ -80,7 +81,7 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
try { try {
checkNotNull(blockData); checkNotNull(blockData);
Material material = blockData.getMaterial(); Material material = blockData.getMaterial();
BlockTypes type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]); BlockType type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]);
List<? extends Property> propList = type.getProperties(); List<? extends Property> propList = type.getProperties();
if (propList.size() == 0) return type.getDefaultState(); if (propList.size() == 0) return type.getDefaultState();
String properties = blockData.getAsString(); String properties = blockData.getAsString();

View File

@ -284,7 +284,7 @@ public interface IBukkitAdapter {
*/ */
BlockState adapt(BlockData blockData); BlockState adapt(BlockData blockData);
BlockTypes adapt(Material material); BlockType adapt(Material material);
/** /**
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder * Create a Bukkit BlockData from a WorldEdit BlockStateHolder

View File

@ -1,6 +1,7 @@
package com.sk89q.worldedit.bukkit.adapter; package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -31,7 +32,7 @@ public class SimpleBukkitAdapter extends CachedBukkitAdapter {
int typeId = block.getInternalBlockTypeId(); int typeId = block.getInternalBlockTypeId();
BlockData[] dataCache = blockDataCache[typeId]; BlockData[] dataCache = blockDataCache[typeId];
if (dataCache == null) { if (dataCache == null) {
BlockTypes type = BlockTypes.get(typeId); BlockType type = BlockTypes.get(typeId);
blockDataCache[typeId] = dataCache = new BlockData[type.getMaxStateId() + 1]; blockDataCache[typeId] = dataCache = new BlockData[type.getMaxStateId() + 1];
} }
int propId = block.getInternalPropertiesId(); int propId = block.getInternalPropertiesId();

View File

@ -79,7 +79,7 @@ public class LazyBlock extends BaseBlock {
@Override @Override
public CompoundTag getNbtData() { public CompoundTag getNbtData() {
if (!loaded) { if (!loaded) {
BlockState loadedBlock = extent.getFullBlock(position); BlockState loadedBlock = extent.getFullBlock(position).toImmutableState();
this.nbtData = loadedBlock.getNbtData(); this.nbtData = loadedBlock.getNbtData();
loaded = true; loaded = true;
} }

View File

@ -31,6 +31,7 @@ import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.internal.registry.AbstractFactory; import com.sk89q.worldedit.internal.registry.AbstractFactory;
import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -222,7 +223,7 @@ public class FaweAPI {
* @see com.boydti.fawe.object.schematic.Schematic * @see com.boydti.fawe.object.schematic.Schematic
*/ */
public static Schematic load(File file) throws IOException { public static Schematic load(File file) throws IOException {
return ClipboardFormat.SCHEMATIC.load(file); return ClipboardFormats.findByFile(file).load(file);
} }
/** /**

View File

@ -22,7 +22,6 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;

View File

@ -36,7 +36,9 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
@ -502,7 +504,7 @@ public class CFICommands extends MethodCommands {
HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();
World world = fp.getWorld(); World world = fp.getWorld();
MultiClipboardHolder multi = ClipboardFormat.SCHEMATIC.loadAllFromInput(fp.getPlayer(), schematic, null, true); MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(fp.getPlayer(), schematic, null, true);
if (multi == null) { if (multi == null) {
return; return;
} }

View File

@ -202,10 +202,10 @@ public abstract class IntFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
} }
vs[j] = combinedId; vs[j] = combinedId;
this.count[i]++; this.count[i]++;
switch (BlockTypes.getFromStateId(combinedId)) { switch (BlockTypes.getFromStateId(combinedId).getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
this.air[i]++; this.air[i]++;
return; return;
default: default:

View File

@ -201,25 +201,25 @@ public class SchematicStreamer extends NBTStreamer {
fc.forEach(new FaweClipboard.BlockReader() { fc.forEach(new FaweClipboard.BlockReader() {
@Override @Override
public void run(int x, int y, int z, BlockState block) { public void run(int x, int y, int z, BlockState block) {
BlockTypes type = block.getBlockType(); BlockType type = block.getBlockType();
switch (type) { switch (type.getResource().toUpperCase()) {
case ACACIA_STAIRS: case "ACACIA_STAIRS":
case BIRCH_STAIRS: case "BIRCH_STAIRS":
case BRICK_STAIRS: case "BRICK_STAIRS":
case COBBLESTONE_STAIRS: case "COBBLESTONE_STAIRS":
case DARK_OAK_STAIRS: case "DARK_OAK_STAIRS":
case DARK_PRISMARINE_STAIRS: case "DARK_PRISMARINE_STAIRS":
case JUNGLE_STAIRS: case "JUNGLE_STAIRS":
case NETHER_BRICK_STAIRS: case "NETHER_BRICK_STAIRS":
case OAK_STAIRS: case "OAK_STAIRS":
case PRISMARINE_BRICK_STAIRS: case "PRISMARINE_BRICK_STAIRS":
case PRISMARINE_STAIRS: case "PRISMARINE_STAIRS":
case PURPUR_STAIRS: case "PURPUR_STAIRS":
case QUARTZ_STAIRS: case "QUARTZ_STAIRS":
case RED_SANDSTONE_STAIRS: case "RED_SANDSTONE_STAIRS":
case SANDSTONE_STAIRS: case "SANDSTONE_STAIRS":
case SPRUCE_STAIRS: case "SPRUCE_STAIRS":
case STONE_BRICK_STAIRS: case "STONE_BRICK_STAIRS":
Object half = block.getState(PropertyKey.HALF); Object half = block.getState(PropertyKey.HALF);
Direction facing = block.getState(PropertyKey.FACING); Direction facing = block.getState(PropertyKey.FACING);
@ -228,19 +228,19 @@ public class SchematicStreamer extends NBTStreamer {
Direction right = facing.getRight(); Direction right = facing.getRight();
BlockStateHolder forwardBlock = fc.getBlock(x + forward.getBlockX(), y + forward.getBlockY(), z + forward.getBlockZ()); BlockStateHolder forwardBlock = fc.getBlock(x + forward.getBlockX(), y + forward.getBlockY(), z + forward.getBlockZ());
BlockTypes forwardType = forwardBlock.getBlockType(); BlockType forwardType = forwardBlock.getBlockType();
if (forwardType.hasProperty(PropertyKey.SHAPE) && forwardType.hasProperty(PropertyKey.FACING)) { if (forwardType.hasProperty(PropertyKey.SHAPE) && forwardType.hasProperty(PropertyKey.FACING)) {
Direction forwardFacing = (Direction) forwardBlock.getState(PropertyKey.FACING); Direction forwardFacing = (Direction) forwardBlock.getState(PropertyKey.FACING);
if (forwardFacing == left) { if (forwardFacing == left) {
BlockStateHolder rightBlock = fc.getBlock(x + right.getBlockX(), y + right.getBlockY(), z + right.getBlockZ()); BlockStateHolder rightBlock = fc.getBlock(x + right.getBlockX(), y + right.getBlockY(), z + right.getBlockZ());
BlockTypes rightType = rightBlock.getBlockType(); BlockType rightType = rightBlock.getBlockType();
if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) { if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_left")); fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_left"));
} }
return; return;
} else if (forwardFacing == right) { } else if (forwardFacing == right) {
BlockStateHolder leftBlock = fc.getBlock(x + left.getBlockX(), y + left.getBlockY(), z + left.getBlockZ()); BlockStateHolder leftBlock = fc.getBlock(x + left.getBlockX(), y + left.getBlockY(), z + left.getBlockZ());
BlockTypes leftType = leftBlock.getBlockType(); BlockType leftType = leftBlock.getBlockType();
if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) { if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_right")); fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "inner_right"));
} }
@ -249,19 +249,19 @@ public class SchematicStreamer extends NBTStreamer {
} }
BlockStateHolder backwardsBlock = fc.getBlock(x - forward.getBlockX(), y - forward.getBlockY(), z - forward.getBlockZ()); BlockStateHolder backwardsBlock = fc.getBlock(x - forward.getBlockX(), y - forward.getBlockY(), z - forward.getBlockZ());
BlockTypes backwardsType = backwardsBlock.getBlockType(); BlockType backwardsType = backwardsBlock.getBlockType();
if (backwardsType.hasProperty(PropertyKey.SHAPE) && backwardsType.hasProperty(PropertyKey.FACING)) { if (backwardsType.hasProperty(PropertyKey.SHAPE) && backwardsType.hasProperty(PropertyKey.FACING)) {
Direction backwardsFacing = (Direction) backwardsBlock.getState(PropertyKey.FACING); Direction backwardsFacing = (Direction) backwardsBlock.getState(PropertyKey.FACING);
if (backwardsFacing == left) { if (backwardsFacing == left) {
BlockStateHolder rightBlock = fc.getBlock(x + right.getBlockX(), y + right.getBlockY(), z + right.getBlockZ()); BlockStateHolder rightBlock = fc.getBlock(x + right.getBlockX(), y + right.getBlockY(), z + right.getBlockZ());
BlockTypes rightType = rightBlock.getBlockType(); BlockType rightType = rightBlock.getBlockType();
if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) { if (!rightType.hasProperty(PropertyKey.SHAPE) || rightBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_left")); fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_left"));
} }
return; return;
} else if (backwardsFacing == right) { } else if (backwardsFacing == right) {
BlockStateHolder leftBlock = fc.getBlock(x + left.getBlockX(), y + left.getBlockY(), z + left.getBlockZ()); BlockStateHolder leftBlock = fc.getBlock(x + left.getBlockX(), y + left.getBlockY(), z + left.getBlockZ());
BlockTypes leftType = leftBlock.getBlockType(); BlockType leftType = leftBlock.getBlockType();
if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) { if (!leftType.hasProperty(PropertyKey.SHAPE) || leftBlock.getState(PropertyKey.FACING) != facing) {
fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_right")); fc.setBlock(x, y, z, block.with(PropertyKey.SHAPE, "outer_right"));
} }
@ -301,43 +301,43 @@ public class SchematicStreamer extends NBTStreamer {
private boolean merge(int group, int x, int y, int z) { private boolean merge(int group, int x, int y, int z) {
BlockStateHolder block = fc.getBlock(x, y, z); BlockStateHolder block = fc.getBlock(x, y, z);
BlockTypes type = block.getBlockType(); BlockType type = block.getBlockType();
return group(type) == group || fullCube.apply(type); return group(type) == group || fullCube.apply(type);
} }
private int group(BlockTypes type) { private int group(BlockType type) {
switch (type) { switch (type.getResource().toUpperCase()) {
case ACACIA_FENCE: case "ACACIA_FENCE":
case BIRCH_FENCE: case "BIRCH_FENCE":
case DARK_OAK_FENCE: case "DARK_OAK_FENCE":
case JUNGLE_FENCE: case "JUNGLE_FENCE":
case OAK_FENCE: case "OAK_FENCE":
case SPRUCE_FENCE: case "SPRUCE_FENCE":
return 0; return 0;
case NETHER_BRICK_FENCE: case "NETHER_BRICK_FENCE":
return 1; return 1;
case COBBLESTONE_WALL: case "COBBLESTONE_WALL":
case MOSSY_COBBLESTONE_WALL: case "MOSSY_COBBLESTONE_WALL":
return 2; return 2;
case IRON_BARS: case "IRON_BARS":
case BLACK_STAINED_GLASS_PANE: case "BLACK_STAINED_GLASS_PANE":
case BLUE_STAINED_GLASS_PANE: case "BLUE_STAINED_GLASS_PANE":
case BROWN_MUSHROOM_BLOCK: case "BROWN_MUSHROOM_BLOCK":
case BROWN_STAINED_GLASS_PANE: case "BROWN_STAINED_GLASS_PANE":
case CYAN_STAINED_GLASS_PANE: case "CYAN_STAINED_GLASS_PANE":
case GLASS_PANE: case "GLASS_PANE":
case GRAY_STAINED_GLASS_PANE: case "GRAY_STAINED_GLASS_PANE":
case GREEN_STAINED_GLASS_PANE: case "GREEN_STAINED_GLASS_PANE":
case LIGHT_BLUE_STAINED_GLASS_PANE: case "LIGHT_BLUE_STAINED_GLASS_PANE":
case LIGHT_GRAY_STAINED_GLASS_PANE: case "LIGHT_GRAY_STAINED_GLASS_PANE":
case LIME_STAINED_GLASS_PANE: case "LIME_STAINED_GLASS_PANE":
case MAGENTA_STAINED_GLASS_PANE: case "MAGENTA_STAINED_GLASS_PANE":
case ORANGE_STAINED_GLASS_PANE: case "ORANGE_STAINED_GLASS_PANE":
case PINK_STAINED_GLASS_PANE: case "PINK_STAINED_GLASS_PANE":
case PURPLE_STAINED_GLASS_PANE: case "PURPLE_STAINED_GLASS_PANE":
case RED_STAINED_GLASS_PANE: case "RED_STAINED_GLASS_PANE":
case WHITE_STAINED_GLASS_PANE: case "WHITE_STAINED_GLASS_PANE":
case YELLOW_STAINED_GLASS_PANE: case "YELLOW_STAINED_GLASS_PANE":
return 3; return 3;
default: default:
return -1; return -1;
@ -450,6 +450,7 @@ public class SchematicStreamer extends NBTStreamer {
public Clipboard getClipboard() throws IOException { public Clipboard getClipboard() throws IOException {
try { try {
setupClipboard(0);
addDimensionReaders(); addDimensionReaders();
addBlockReaders(); addBlockReaders();
readFully(); readFully();

View File

@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.TextureUtil;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -80,12 +81,12 @@ public final class HeightMapMCADrawer {
if (height + 1 < waterHeight) { if (height + 1 < waterHeight) {
int waterId = gen.primtives.waterId; int waterId = gen.primtives.waterId;
int waterColor = 0; int waterColor = 0;
BlockTypes waterType = BlockTypes.get(waterId); BlockType waterType = BlockTypes.get(waterId);
switch (waterType) { switch (waterType.getResource().toUpperCase()) {
case WATER: case "WATER":
color = tu.averageColor((0x11 << 16) + (0x66 << 8) + (0xCC), color); color = tu.averageColor((0x11 << 16) + (0x66 << 8) + (0xCC), color);
break; break;
case LAVA: case "LAVA":
color = (0xCC << 16) + (0x33 << 8) + (0); color = (0xCC << 16) + (0x33 << 8) + (0);
break; break;
default: default:

View File

@ -445,9 +445,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
private final void setLayerHeight(int index, int blockHeight, int layerHeight) { private final void setLayerHeight(int index, int blockHeight, int layerHeight) {
int floorState = floor.get()[index]; int floorState = floor.get()[index];
switch (BlockTypes.getFromStateId(floorState)) { switch (BlockTypes.getFromStateId(floorState).getResource().toUpperCase()) {
case SNOW: case "SNOW":
case SNOW_BLOCK: case "SNOW_BLOCK":
if (layerHeight != 0) { if (layerHeight != 0) {
this.heights.setByte(index, (byte) (blockHeight + 1)); this.heights.setByte(index, (byte) (blockHeight + 1));
this.floor.setInt(index, (BlockTypes.SNOW.getInternalId() + layerHeight)); this.floor.setInt(index, (BlockTypes.SNOW.getInternalId() + layerHeight));
@ -470,9 +470,9 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
private final void setLayerHeightRaw(int index, int blockHeight, int layerHeight) { private final void setLayerHeightRaw(int index, int blockHeight, int layerHeight) {
int floorState = floor.get()[index]; int floorState = floor.get()[index];
switch (BlockTypes.getFromStateId(floorState)) { switch (BlockTypes.getFromStateId(floorState).getResource().toUpperCase()) {
case SNOW: case "SNOW":
case SNOW_BLOCK: case "SNOW_BLOCK":
if (layerHeight != 0) { if (layerHeight != 0) {
this.heights.getByteArray()[index] = (byte) (blockHeight + 1); this.heights.getByteArray()[index] = (byte) (blockHeight + 1);
this.floor.getIntArray()[index] = (BlockTypes.SNOW.getInternalId() + layerHeight); this.floor.getIntArray()[index] = (BlockTypes.SNOW.getInternalId() + layerHeight);

View File

@ -172,9 +172,9 @@ public class CavesGen extends GenBase {
if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) { if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) {
BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z); BlockStateHolder material = chunk.getLazyBlock(bx + local_x, local_y, bz + local_z);
BlockStateHolder materialAbove = chunk.getLazyBlock(bx + local_x, local_y + 1, bz + local_z); BlockStateHolder materialAbove = chunk.getLazyBlock(bx + local_x, local_y + 1, bz + local_z);
switch (material.getBlockType()) { switch (material.getBlockType().getResource().toUpperCase()) {
case GRASS: case "GRASS":
case MYCELIUM: case "MYCELIUM":
grassFound = true; grassFound = true;
break; break;
} }
@ -205,13 +205,13 @@ public class CavesGen extends GenBase {
} }
protected boolean isSuitableBlock(BlockStateHolder material, BlockStateHolder materialAbove) { protected boolean isSuitableBlock(BlockStateHolder material, BlockStateHolder materialAbove) {
switch (material.getBlockType()) { switch (material.getBlockType().getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
case WATER: case "WATER":
case LAVA: case "LAVA":
case BEDROCK: case "BEDROCK":
return false; return false;
default: default:
return true; return true;

View File

@ -5,6 +5,7 @@ import com.boydti.fawe.object.changeset.FaweChangeSet;
import com.boydti.fawe.object.queue.DelegateFaweQueue; import com.boydti.fawe.object.queue.DelegateFaweQueue;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
public class ChangeSetFaweQueue extends DelegateFaweQueue { public class ChangeSetFaweQueue extends DelegateFaweQueue {
@ -28,7 +29,7 @@ public class ChangeSetFaweQueue extends DelegateFaweQueue {
if (super.setBlock(x, y, z, combinedId)) { if (super.setBlock(x, y, z, combinedId)) {
int combinedFrom = getParent().getCombinedId4Data(x, y, z); int combinedFrom = getParent().getCombinedId4Data(x, y, z);
BlockTypes typeFrom = BlockTypes.getFromStateId(combinedFrom); BlockType typeFrom = BlockTypes.getFromStateId(combinedFrom);
if (typeFrom.getMaterial().hasContainer()) { if (typeFrom.getMaterial().hasContainer()) {
CompoundTag nbt = getParent().getTileEntity(x, y, z); CompoundTag nbt = getParent().getTileEntity(x, y, z);
if (nbt != null) { if (nbt != null) {

View File

@ -120,7 +120,7 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
try { try {
CompoundTag tile = getTile(x & 15, y, z & 15); CompoundTag tile = getTile(x & 15, y, z & 15);
if (tile != null) { if (tile != null) {
return BaseBlock.getFromInternalId(combined, tile); return BaseBlock.getFromInternalId(combined, tile).toImmutableState();
} }
} catch (Throwable e) { } catch (Throwable e) {
MainUtil.handleError(e); MainUtil.handleError(e);

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import java.io.File; import java.io.File;
@ -78,7 +79,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
if (state.getMaterial().hasContainer()) { if (state.getMaterial().hasContainer()) {
CompoundTag tile = getTileEntity(x, y, z); CompoundTag tile = getTileEntity(x, y, z);
if (tile != null) { if (tile != null) {
return BaseBlock.getFromInternalId(combinedId4Data, tile); return BaseBlock.getFromInternalId(combinedId4Data, tile).toImmutableState();
} }
} }
return state; return state;
@ -94,8 +95,8 @@ public interface FaweQueue extends HasFaweQueue, Extent {
} }
@Override @Override
default BlockState getFullBlock(BlockVector3 position) { default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()).toBaseBlock();
} }
@Override @Override
@ -275,18 +276,18 @@ public interface FaweQueue extends HasFaweQueue, Extent {
for (int y = 0; y <= getMaxY(); y++) { for (int y = 0; y <= getMaxY(); y++) {
int combined = getCombinedId4Data(xx, y, zz); int combined = getCombinedId4Data(xx, y, zz);
BlockState state = BlockState.getFromInternalId(combined); BlockState state = BlockState.getFromInternalId(combined);
BlockTypes type = state.getBlockType(); BlockType type = state.getBlockType();
switch (type.getTypeEnum()) { switch (type.getResource().toUpperCase()) {
case AIR: case "AIR":
case VOID_AIR: case "VOID_AIR":
case CAVE_AIR: case "CAVE_AIR":
continue; continue;
} }
mutable.mutY(y); mutable.mutY(y);
CompoundTag tile = getTileEntity(x, y, z); CompoundTag tile = getTileEntity(x, y, z);
if (tile != null) { if (tile != null) {
BaseBlock block = BaseBlock.getFromInternalId(combined, tile); BaseBlock block = BaseBlock.getFromInternalId(combined, tile);
onEach.run(mutable.toBlockVector3(), block); onEach.run(mutable.toBlockVector3(), block.toImmutableState());
} else { } else {
onEach.run(mutable.toBlockVector3(), state); onEach.run(mutable.toBlockVector3(), state);
} }
@ -308,7 +309,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
if (combined == 0) { if (combined == 0) {
continue; continue;
} }
BlockTypes type = BlockTypes.getFromStateId(combined); BlockType type = BlockTypes.getFromStateId(combined);
if (type.getMaterial().hasContainer()) { if (type.getMaterial().hasContainer()) {
CompoundTag tile = getTileEntity(x, y, z); CompoundTag tile = getTileEntity(x, y, z);
if (tile != null) { if (tile != null) {
@ -316,7 +317,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
mutable.mutZ(zz); mutable.mutZ(zz);
mutable.mutY(y); mutable.mutY(y);
BaseBlock block = BaseBlock.getFromInternalId(combined, tile); BaseBlock block = BaseBlock.getFromInternalId(combined, tile);
onEach.run(mutable.toBlockVector3(), block); onEach.run(mutable.toBlockVector3(), block.toImmutableState());
} }
} }
} }

View File

@ -10,6 +10,7 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import java.io.IOException; import java.io.IOException;
@ -34,7 +35,7 @@ public abstract class ScrollAction implements ScrollTool {
} }
String filename = split[1]; String filename = split[1];
try { try {
MultiClipboardHolder multi = ClipboardFormat.SCHEMATIC.loadAllFromInput(player, filename, null, message); MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, filename, null, message);
if (multi == null) { if (multi == null) {
return null; return null;
} }

View File

@ -10,6 +10,7 @@ import com.sk89q.worldedit.event.platform.PlayerInputEvent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.SimpleWorld; import com.sk89q.worldedit.world.SimpleWorld;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -22,8 +23,8 @@ public interface VirtualWorld extends SimpleWorld, FaweQueue, Closeable {
FaweChunk getSnapshot(int chunkX, int chunkZ); FaweChunk getSnapshot(int chunkX, int chunkZ);
@Override @Override
default BlockState getFullBlock(BlockVector3 position) { default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position); return getLazyBlock(position).toBaseBlock();
} }
@Override @Override

View File

@ -115,10 +115,10 @@ public class VisualChunk extends FaweChunk<FaweChunk> {
public void setBlock(int x, int y, int z, int combinedId) { public void setBlock(int x, int y, int z, int combinedId) {
int index = getIndex(x, y, z); int index = getIndex(x, y, z);
try { try {
switch (BlockTypes.getFromStateId(combinedId)) { switch (BlockTypes.getFromStateId(combinedId).getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
add.clear(index); add.clear(index);
remove.set(index); remove.set(index);
break; break;

View File

@ -11,6 +11,7 @@ import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
public class MutableFullBlockChange implements Change { public class MutableFullBlockChange implements Change {
@ -60,9 +61,9 @@ public class MutableFullBlockChange implements Change {
} }
public void perform(FaweQueue queue) { public void perform(FaweQueue queue) {
BlockTypes idFrom = BlockTypes.getFromStateId(from); BlockType idFrom = BlockTypes.getFromStateId(from);
if (blockBag != null) { if (blockBag != null) {
BlockTypes idTo = BlockTypes.getFromStateId(to); BlockType idTo = BlockTypes.getFromStateId(to);
if (idFrom != idTo) { if (idFrom != idTo) {
if (allowFetch && from != 0) { if (allowFetch && from != 0) {
try { try {

View File

@ -17,6 +17,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import java.util.ArrayList; import java.util.ArrayList;
@ -147,12 +148,12 @@ public class CPUOptimizedClipboard extends FaweClipboard {
@Override @Override
public BlockState getBlock(int index) { public BlockState getBlock(int index) {
int combinedId = states[index]; int combinedId = states[index];
BlockTypes type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId); BlockState state = type.withStateId(combinedId);
if (type.getMaterial().hasContainer()) { if (type.getMaterial().hasContainer()) {
CompoundTag nbt = getTag(index); CompoundTag nbt = getTag(index);
if (nbt != null) { if (nbt != null) {
return new BaseBlock(state, nbt); return new BaseBlock(state, nbt).toImmutableState();
} }
} }
return state; return state;
@ -174,10 +175,10 @@ public class CPUOptimizedClipboard extends FaweClipboard {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) { for (int x = 0; x < width; x++, index++) {
BlockState block = getBlock(index); BlockState block = getBlock(index);
switch (block.getBlockType()) { switch (block.getBlockType().getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
continue; continue;
default: default:
task.run(x, y, z, block); task.run(x, y, z, block);

View File

@ -21,6 +21,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import java.io.Closeable; import java.io.Closeable;
@ -371,14 +372,14 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, pos += 4) { for (int x = 0; x < width; x++, pos += 4) {
int combinedId = mbb.getInt(pos); int combinedId = mbb.getInt(pos);
BlockTypes type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId); BlockState state = type.withStateId(combinedId);
if (type.getMaterial().hasContainer()) { if (type.getMaterial().hasContainer()) {
trio.set(x, y, z); trio.set(x, y, z);
CompoundTag nbt = nbtMap.get(trio); CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) { if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt); BaseBlock block = new BaseBlock(state, nbt);
task.run(x, y, z, block); task.run(x, y, z, block.toImmutableState());
continue; continue;
} }
} }
@ -402,11 +403,11 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, pos += 4) { for (int x = 0; x < width; x++, pos += 4) {
int combinedId = mbb.getInt(pos); int combinedId = mbb.getInt(pos);
BlockTypes type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
switch (type) { switch (type.getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
continue; continue;
default: default:
BlockState state = type.withStateId(combinedId); BlockState state = type.withStateId(combinedId);
@ -415,7 +416,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
CompoundTag nbt = nbtMap.get(trio); CompoundTag nbt = nbtMap.get(trio);
if (nbt != null) { if (nbt != null) {
BaseBlock block = new BaseBlock(state, nbt); BaseBlock block = new BaseBlock(state, nbt);
task.run(x, y, z, block); task.run(x, y, z, block.toImmutableState());
continue; continue;
} }
} }
@ -436,12 +437,12 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
try { try {
int index = HEADER_SIZE + (getIndex(x, y, z) << 2); int index = HEADER_SIZE + (getIndex(x, y, z) << 2);
int combinedId = mbb.getInt(index); int combinedId = mbb.getInt(index);
BlockTypes type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId); BlockState state = type.withStateId(combinedId);
if (type.getMaterial().hasContainer() && !nbtMap.isEmpty()) { if (type.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z)); CompoundTag nbt = nbtMap.get(new IntegerTrio(x, y, z));
if (nbt != null) { if (nbt != null) {
return new BaseBlock(state, nbt); return new BaseBlock(state, nbt).toImmutableState();
} }
} }
return state; return state;
@ -458,7 +459,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
try { try {
int diskIndex = (HEADER_SIZE) + (i << 2); int diskIndex = (HEADER_SIZE) + (i << 2);
int combinedId = mbb.getInt(diskIndex); int combinedId = mbb.getInt(diskIndex);
BlockTypes type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId); BlockState state = type.withStateId(combinedId);
if (type.getMaterial().hasContainer() && !nbtMap.isEmpty()) { if (type.getMaterial().hasContainer() && !nbtMap.isEmpty()) {
CompoundTag nbt; CompoundTag nbt;
@ -481,7 +482,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
nbt = nbtMap.get(new IntegerTrio(x, y, z)); nbt = nbtMap.get(new IntegerTrio(x, y, z));
} }
if (nbt != null) { if (nbt != null) {
return new BaseBlock(state, nbt); return new BaseBlock(state, nbt).toImmutableState();
} }
} }
return state; return state;

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.clipboard;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -73,8 +74,8 @@ public class EmptyClipboard implements Clipboard {
} }
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return EditSession.nullBlock; return EditSession.nullBlock.toBaseBlock();
} }
@Override @Override

View File

@ -18,6 +18,7 @@ import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import net.jpountz.util.SafeUtils; import net.jpountz.util.SafeUtils;
@ -203,10 +204,11 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
} }
} }
if (lastCombinedIds == null) { if (lastCombinedIds == null) {
switch (BlockTypes.getFromStateId(v)) { BlockType bt = BlockTypes.getFromStateId(v);
case AIR: switch (bt.getResource().toUpperCase()) {
case CAVE_AIR: case "AIR":
case VOID_AIR: case "CAVE_AIR":
case "VOID_AIR":
return; return;
} }
lastCombinedIds = new byte[BLOCK_SIZE]; lastCombinedIds = new byte[BLOCK_SIZE];
@ -270,12 +272,12 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
@Override @Override
public BlockState getBlock(int index) { public BlockState getBlock(int index) {
int combinedId = getCombinedId(index); int combinedId = getCombinedId(index);
BlockTypes type = BlockTypes.getFromStateId(combinedId); BlockType type = BlockTypes.getFromStateId(combinedId);
BlockState state = type.withStateId(combinedId); BlockState state = type.withStateId(combinedId);
if (type.getMaterial().hasContainer()) { if (type.getMaterial().hasContainer()) {
CompoundTag nbt = getTag(index); CompoundTag nbt = getTag(index);
if (nbt != null) { if (nbt != null) {
return new BaseBlock(state, nbt); return new BaseBlock(state, nbt).toImmutableState();
} }
} }
return state; return state;
@ -297,10 +299,10 @@ public class MemoryOptimizedClipboard extends FaweClipboard {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++, index++) { for (int x = 0; x < width; x++, index++) {
BlockState block = getBlock(index); BlockState block = getBlock(index);
switch (block.getBlockType()) { switch (block.getBlockType().getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
continue; continue;
default: default:
task.run(x, y, z, block); task.run(x, y, z, block);

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -44,8 +45,8 @@ public class EmptyExtent implements Extent {
} }
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return EditSession.nullBlock; return EditSession.nullBlock.toBaseBlock();
} }
@Override @Override

View File

@ -123,12 +123,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa
@Override @Override
public BlockState getLazyBlock(int x, int y, int z) { public BlockState getLazyBlock(int x, int y, int z) {
int combinedId4Data = queue.getCombinedId4Data(x, y, z, 0); int combinedId4Data = queue.getCombinedId4Data(x, y, z, 0);
BlockTypes type = BlockTypes.getFromStateId(combinedId4Data); BlockType type = BlockTypes.getFromStateId(combinedId4Data);
BlockState state = type.withStateId(combinedId4Data); BlockState state = type.withStateId(combinedId4Data);
if (type.getMaterial().hasContainer()) { if (type.getMaterial().hasContainer()) {
CompoundTag tile = queue.getTileEntity(x, y, z); CompoundTag tile = queue.getTileEntity(x, y, z);
if (tile != null) { if (tile != null) {
return new BaseBlock(state, tile); return new BaseBlock(state, tile).toImmutableState();
} }
} }
return state; return state;

View File

@ -53,12 +53,12 @@ public class NullExtent extends FaweRegionExtent {
} }
@Override @Override
public BaseBlock getBlock(final BlockVector3 arg0) { public BlockState getBlock(final BlockVector3 arg0) {
throw new FaweException(reason); throw new FaweException(reason);
} }
@Override @Override
public BaseBlock getLazyBlock(final BlockVector3 arg0) { public BlockState getLazyBlock(final BlockVector3 arg0) {
throw new FaweException(reason); throw new FaweException(reason);
} }
@ -78,7 +78,7 @@ public class NullExtent extends FaweRegionExtent {
} }
@Override @Override
public BaseBlock getLazyBlock(int x, int y, int z) { public BlockState getLazyBlock(int x, int y, int z) {
throw new FaweException(reason); throw new FaweException(reason);
} }

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.extent; package com.boydti.fawe.object.extent;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent; import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
@ -80,17 +81,22 @@ public class TransformExtent extends BlockTransformExtent {
@Override @Override
public BlockState getLazyBlock(int x, int y, int z) { public BlockState getLazyBlock(int x, int y, int z) {
return transformFast(super.getLazyBlock(getPos(x, y, z))); return transformFast(super.getLazyBlock(getPos(x, y, z))).toImmutableState();
} }
@Override @Override
public BlockState getLazyBlock(BlockVector3 position) { public BlockState getLazyBlock(BlockVector3 position) {
return transformFast(super.getLazyBlock(getPos(position))); return transformFast(super.getLazyBlock(getPos(position))).toImmutableState();
} }
@Override @Override
public BlockState getBlock(BlockVector3 position) { public BlockState getBlock(BlockVector3 position) {
return transformFast(super.getBlock(getPos(position))); return transformFast(super.getBlock(getPos(position))).toImmutableState();
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return transformFast(super.getFullBlock(getPos(position)).toImmutableState());
} }
@Override @Override
@ -102,14 +108,14 @@ public class TransformExtent extends BlockTransformExtent {
} }
@Override @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 {
return super.setBlock(getPos(x, y, z), transformFastInverse((BlockState) block)); return super.setBlock(getPos(x, y, z), transformFastInverse((BlockState)block));
} }
@Override @Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
return super.setBlock(getPos(location), transformFastInverse((BlockState) block)); return super.setBlock(getPos(location), transformFastInverse((BlockState)block));
} }
@Override @Override

View File

@ -1,7 +1,7 @@
package com.boydti.fawe.object.pattern; package com.boydti.fawe.object.pattern;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -97,8 +97,8 @@ public class PatternExtent extends AbstractPattern implements Extent {
} }
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return getBlock(position); return getBlock(position).toBaseBlock();
} }
@Override @Override

View File

@ -62,7 +62,7 @@ public class PropertyPattern extends AbstractExtentPattern {
} }
} }
private void add(BlockTypes type, PropertyKey key, Operator operator, MutableCharSequence value, boolean wrap) { private void add(BlockType type, PropertyKey key, Operator operator, MutableCharSequence value, boolean wrap) {
if (!type.hasProperty(key)) return; if (!type.hasProperty(key)) return;
AbstractProperty property = (AbstractProperty) type.getProperty(key); AbstractProperty property = (AbstractProperty) type.getProperty(key);
BlockState defaultState = type.getDefaultState(); BlockState defaultState = type.getDefaultState();
@ -129,14 +129,14 @@ public class PropertyPattern extends AbstractExtentPattern {
charSequence.setString(input); charSequence.setString(input);
charSequence.setSubstring(0, propStart); charSequence.setSubstring(0, propStart);
BlockTypes type = null; BlockType type = null;
List<BlockTypes> blockTypeList = null; List<BlockType> blockTypeList = null;
if (StringMan.isAlphanumericUnd(charSequence)) { if (StringMan.isAlphanumericUnd(charSequence)) {
type = BlockTypes.get(charSequence); type = BlockTypes.get(charSequence);
} else { } else {
String regex = charSequence.toString(); String regex = charSequence.toString();
blockTypeList = new ArrayList<>(); blockTypeList = new ArrayList<>();
for (BlockTypes myType : BlockTypes.values) { for (BlockType myType : BlockTypes.values) {
if (myType.getId().matches(regex)) { if (myType.getId().matches(regex)) {
blockTypeList.add(myType); blockTypeList.add(myType);
} }
@ -164,7 +164,7 @@ public class PropertyPattern extends AbstractExtentPattern {
char firstChar = input.charAt(last + 1); char firstChar = input.charAt(last + 1);
if (type != null) add(type, key, operator, charSequence, wrap); if (type != null) add(type, key, operator, charSequence, wrap);
else { else {
for (BlockTypes myType : blockTypeList) { for (BlockType myType : blockTypeList) {
add(myType, key, operator, charSequence, wrap); add(myType, key, operator, charSequence, wrap);
} }
} }
@ -203,7 +203,7 @@ public class PropertyPattern extends AbstractExtentPattern {
if (newOrdinal != ordinal) { if (newOrdinal != ordinal) {
CompoundTag nbt = block.getNbtData(); CompoundTag nbt = block.getNbtData();
BlockState newState = BlockState.getFromOrdinal(newOrdinal); BlockState newState = BlockState.getFromOrdinal(newOrdinal);
return nbt != null ? new BaseBlock(newState, nbt) : newState; return nbt != null ? new BaseBlock(newState, nbt).toImmutableState() : newState;
} }
return orDefault; return orDefault;
} }

View File

@ -4,7 +4,6 @@ import com.boydti.fawe.FaweCache;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.AbstractPattern;

View File

@ -178,14 +178,9 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
for (BlockVector3 point : region) { for (BlockVector3 point : region) {
BlockStateHolder block = clipboard.getBlock(point); BlockStateHolder block = clipboard.getBlock(point);
int combined = block.getInternalId(); int combined = block.getInternalId();
BlockTypes type = block.getBlockType(); BlockType type = block.getBlockType();
switch (type) { if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(combined)) {
case STRUCTURE_VOID:
continue;
default:
}
if (indexes.containsKey(combined)) {
continue; continue;
} }
@ -194,7 +189,7 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
paletteEntry.put("Name", type.getId()); paletteEntry.put("Name", type.getId());
if (block.getInternalId() != type.getInternalId()) { if (block.getInternalId() != type.getInternalId()) {
Map<String, Object> properties = null; Map<String, Object> properties = null;
for (AbstractProperty property : (List<AbstractProperty>) type.getProperties()) { for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
int propIndex = property.getIndex(block.getInternalId()); int propIndex = property.getIndex(block.getInternalId());
if (propIndex != 0) { if (propIndex != 0) {
if (properties == null) properties = new HashMap<>(); if (properties == null) properties = new HashMap<>();
@ -218,8 +213,8 @@ public class StructureFormat implements ClipboardReader, ClipboardWriter {
BlockVector3 min = region.getMinimumPoint(); BlockVector3 min = region.getMinimumPoint();
for (BlockVector3 point : region) { for (BlockVector3 point : region) {
BlockStateHolder block = clipboard.getBlock(point); BlockStateHolder block = clipboard.getBlock(point);
switch (block.getBlockType()) { switch (block.getBlockType().getResource().toUpperCase()) {
case STRUCTURE_VOID: case "STRUCTURE_VOID":
continue; continue;
default: default:
int combined = block.getInternalId(); int combined = block.getInternalId();

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.event.platform.InputType;
import com.sk89q.worldedit.event.platform.PlayerInputEvent; import com.sk89q.worldedit.event.platform.PlayerInputEvent;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -128,7 +129,7 @@ public class SchemVis extends ImmutableVirtualWorld {
File file = new File(cachedFile.getParentFile(), filename.substring(1, filename.length() - 7)); File file = new File(cachedFile.getParentFile(), filename.substring(1, filename.length() - 7));
URI uri = file.toURI(); URI uri = file.toURI();
ClipboardFormat format = ClipboardFormat.findByFile(file); ClipboardFormat format = ClipboardFormats.findByFile(file);
format.hold(player, uri, new FileInputStream(file)); format.hold(player, uri, new FileInputStream(file));
BBC.SCHEMATIC_LOADED.send(player, filename); BBC.SCHEMATIC_LOADED.send(player, filename);
session.setVirtualWorld(null); session.setVirtualWorld(null);
@ -144,7 +145,7 @@ public class SchemVis extends ImmutableVirtualWorld {
File file = new File(clicked.getParentFile(), filename.substring(1, filename.length() - 7)); File file = new File(clicked.getParentFile(), filename.substring(1, filename.length() - 7));
URI uri = file.toURI(); URI uri = file.toURI();
ClipboardFormat format = ClipboardFormat.findByFile(file); ClipboardFormat format = ClipboardFormats.findByFile(file);
boolean contains = existing instanceof URIClipboardHolder && ((URIClipboardHolder) existing).contains(uri); boolean contains = existing instanceof URIClipboardHolder && ((URIClipboardHolder) existing).contains(uri);
if (contains) { if (contains) {
@ -386,7 +387,7 @@ public class SchemVis extends ImmutableVirtualWorld {
player.sendMessage(BBC.getPrefix() + "Converting: " + file); player.sendMessage(BBC.getPrefix() + "Converting: " + file);
cached.createNewFile(); cached.createNewFile();
try (FileInputStream in = new FileInputStream(file)) { try (FileInputStream in = new FileInputStream(file)) {
ClipboardFormat format = ClipboardFormat.findByFile(file); ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format != null) { if (format != null) {
ClipboardReader reader = format.getReader(in); ClipboardReader reader = format.getReader(in);
Clipboard clipboard = reader.read(); Clipboard clipboard = reader.read();

View File

@ -10,9 +10,9 @@ import java.io.FileNotFoundException;
public class CachedTextureUtil extends DelegateTextureUtil { public class CachedTextureUtil extends DelegateTextureUtil {
private final TextureUtil parent; private final TextureUtil parent;
private transient Int2ObjectOpenHashMap<BlockTypes> colorBlockMap; private transient Int2ObjectOpenHashMap<BlockType> colorBlockMap;
private transient Int2ObjectOpenHashMap<Integer> colorBiomeMap; private transient Int2ObjectOpenHashMap<Integer> colorBiomeMap;
private transient Int2ObjectOpenHashMap<BlockTypes[]> colorLayerMap; private transient Int2ObjectOpenHashMap<BlockType[]> colorLayerMap;
public CachedTextureUtil(TextureUtil parent) throws FileNotFoundException { public CachedTextureUtil(TextureUtil parent) throws FileNotFoundException {
super(parent); super(parent);
@ -23,8 +23,8 @@ public class CachedTextureUtil extends DelegateTextureUtil {
} }
@Override @Override
public BlockTypes[] getNearestLayer(int color) { public BlockType[] getNearestLayer(int color) {
BlockTypes[] closest = colorLayerMap.get(color); BlockType[] closest = colorLayerMap.get(color);
if (closest != null) { if (closest != null) {
return closest; return closest;
} }
@ -49,12 +49,12 @@ public class CachedTextureUtil extends DelegateTextureUtil {
} }
@Override @Override
public BlockTypes getNearestBlock(int color) { public BlockType getNearestBlock(int color) {
BlockTypes value = colorBlockMap.get(color); BlockType value = colorBlockMap.get(color);
if (value != null) { if (value != null) {
return value; return value;
} }
BlockTypes result = parent.getNearestBlock(color); BlockType result = parent.getNearestBlock(color);
if (result != null) { if (result != null) {
colorBlockMap.put((int) color, result); colorBlockMap.put((int) color, result);
} }

View File

@ -19,7 +19,7 @@ public class DelegateTextureUtil extends TextureUtil {
} }
@Override @Override
public BlockTypes getNearestBlock(int color) { public BlockType getNearestBlock(int color) {
return parent.getNearestBlock(color); return parent.getNearestBlock(color);
} }
@ -34,7 +34,7 @@ public class DelegateTextureUtil extends TextureUtil {
} }
@Override @Override
public BlockTypes[] getNearestLayer(int color) { public BlockType[] getNearestLayer(int color) {
return parent.getNearestLayer(color); return parent.getNearestLayer(color);
} }

View File

@ -26,14 +26,14 @@ public class FilteredTextureUtil extends TextureUtil {
this.validBlockIds = new int[distances.length]; this.validBlockIds = new int[distances.length];
int num = 0; int num = 0;
for (int i = 0; i < parent.validBlockIds.length; i++) { for (int i = 0; i < parent.validBlockIds.length; i++) {
BlockTypes block = BlockTypes.get(parent.validBlockIds[i]); BlockType block = BlockTypes.get(parent.validBlockIds[i]);
if (blocks.contains(block)) num++; if (blocks.contains(block)) num++;
} }
this.validBlockIds = new int[num]; this.validBlockIds = new int[num];
this.validColors = new int[num]; this.validColors = new int[num];
num = 0; num = 0;
for (int i = 0; i < parent.validBlockIds.length; i++) { for (int i = 0; i < parent.validBlockIds.length; i++) {
BlockTypes block = BlockTypes.get(parent.validBlockIds[i]); BlockType block = BlockTypes.get(parent.validBlockIds[i]);
if (blocks.contains(block)) { if (blocks.contains(block)) {
validBlockIds[num] = parent.validBlockIds[i]; validBlockIds[num] = parent.validBlockIds[i];
validColors[num++] = parent.validColors[i]; validColors[num++] = parent.validColors[i];

View File

@ -12,6 +12,7 @@ import com.github.luben.zstd.ZstdOutputStream;
import com.sk89q.jnbt.*; import com.sk89q.jnbt.*;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.history.changeset.ChangeSet; import com.sk89q.worldedit.history.changeset.ChangeSet;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import java.awt.Graphics2D; import java.awt.Graphics2D;
@ -889,7 +890,7 @@ public class MainUtil {
public static File resolve(File dir, String filename, @Nullable ClipboardFormat format, boolean allowDir) { public static File resolve(File dir, String filename, @Nullable ClipboardFormat format, boolean allowDir) {
if (format != null) { if (format != null) {
if (!filename.matches(".*\\.[\\w].*")) { if (!filename.matches(".*\\.[\\w].*")) {
filename = filename + "." + format.getExtension(); filename = filename + "." + format.getPrimaryFileExtension();
} }
return MainUtil.resolveRelative(new File(dir, filename)); return MainUtil.resolveRelative(new File(dir, filename));
} }
@ -897,8 +898,8 @@ public class MainUtil {
File file = MainUtil.resolveRelative(new File(dir, filename)); File file = MainUtil.resolveRelative(new File(dir, filename));
if (file.exists() && file.isDirectory()) return file; if (file.exists() && file.isDirectory()) return file;
} }
for (ClipboardFormat f : ClipboardFormat.values) { for (ClipboardFormat f : ClipboardFormats.getAll()) {
File file = MainUtil.resolveRelative(new File(dir, filename + "." + f.getExtension())); File file = MainUtil.resolveRelative(new File(dir, filename + "." + f.getPrimaryFileExtension()));
if (file.exists()) return file; if (file.exists()) return file;
} }
return null; return null;

View File

@ -79,14 +79,14 @@ public class RandomTextureUtil extends CachedTextureUtil {
} }
@Override @Override
public BlockTypes getNearestBlock(int color) { public BlockType getNearestBlock(int color) {
int offsetColor = offsets.getOrDefault(color, 0); int offsetColor = offsets.getOrDefault(color, 0);
if (offsetColor != 0) { if (offsetColor != 0) {
offsetColor = addRandomColor(color, offsetColor); offsetColor = addRandomColor(color, offsetColor);
} else { } else {
offsetColor = color; offsetColor = color;
} }
BlockTypes res = super.getNearestBlock(offsetColor); BlockType res = super.getNearestBlock(offsetColor);
if (res == null) return null; if (res == null) return null;
int newColor = getColor(res); int newColor = getColor(res);
{ {

View File

@ -372,7 +372,7 @@ public class TextureUtil implements TextureHolder{
} }
} }
public BlockTypes getNearestBlock(int color) { public BlockType getNearestBlock(int color) {
long min = Long.MAX_VALUE; long min = Long.MAX_VALUE;
int closest = 0; int closest = 0;
int red1 = (color >> 16) & 0xFF; int red1 = (color >> 16) & 0xFF;
@ -420,7 +420,7 @@ public class TextureUtil implements TextureHolder{
return BlockTypes.get(closest); return BlockTypes.get(closest);
} }
private BlockTypes[] layerBuffer = new BlockTypes[2]; private BlockType[] layerBuffer = new BlockType[2];
/** /**
* Returns the block combined ids as an array * Returns the block combined ids as an array
@ -428,7 +428,7 @@ public class TextureUtil implements TextureHolder{
* @param color * @param color
* @return * @return
*/ */
public BlockTypes[] getNearestLayer(int color) { public BlockType[] getNearestLayer(int color) {
int[] closest = null; int[] closest = null;
long min = Long.MAX_VALUE; long min = Long.MAX_VALUE;
int red1 = (color >> 16) & 0xFF; int red1 = (color >> 16) & 0xFF;

View File

@ -6,9 +6,9 @@ import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor;
@ -51,7 +51,7 @@ public class PlayerWrapper extends AbstractPlayerActor {
} }
@Override @Override
public BlockState getBlockInHand(HandSide handSide) throws WorldEditException { public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
return parent.getBlockInHand(handSide); return parent.getBlockInHand(handSide);
} }

View File

@ -20,6 +20,7 @@ import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome; 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.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
@ -240,7 +241,7 @@ public class WorldWrapper extends AbstractWorld {
} }
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return parent.getFullBlock(position); return parent.getFullBlock(position);
} }

View File

@ -28,6 +28,7 @@ import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
@ -149,7 +150,7 @@ public class CuboidClipboard {
} }
private BaseBlock adapt(BlockState state) { private BaseBlock adapt(BlockState state) {
if (state instanceof BaseBlock) return (BaseBlock) state; // if (state instanceof BaseBlock) return (BaseBlock) state;
return new BaseBlock(state); return new BaseBlock(state);
} }
@ -173,7 +174,7 @@ public class CuboidClipboard {
} }
public boolean setBlock(int x, int y, int z, BaseBlock block) { public boolean setBlock(int x, int y, int z, BaseBlock block) {
return setBlock(x, y, z, (BlockState) block); return setBlock(x, y, z, block.toImmutableState());
} }
public boolean setBlock(int x, int y, int z, BlockState block) { public boolean setBlock(int x, int y, int z, BlockState block) {
@ -270,7 +271,7 @@ public class CuboidClipboard {
if (region.contains(pt)) { if (region.contains(pt)) {
setBlock(x, y, z, editSession.getBlock(pt)); setBlock(x, y, z, editSession.getBlock(pt));
} else { } else {
setBlock(x, y, z, null); setBlock(x, y, z, (BlockState)null);
} }
} }
} }
@ -435,7 +436,7 @@ public class CuboidClipboard {
Operations.completeLegacy(result.copyTo(target)); Operations.completeLegacy(result.copyTo(target));
this.clipboard = target; this.clipboard = target;
} }
new Schematic(clipboard).save(path, ClipboardFormat.SPONGE_SCHEMATIC); new Schematic(clipboard).save(path, BuiltInClipboardFormat.SPONGE_SCHEMATIC);
} }
/** /**
@ -450,7 +451,7 @@ public class CuboidClipboard {
@Deprecated @Deprecated
public static CuboidClipboard loadSchematic(File path) throws DataException, IOException { public static CuboidClipboard loadSchematic(File path) throws DataException, IOException {
checkNotNull(path); checkNotNull(path);
return new CuboidClipboard((BlockVector3) ClipboardFormat.SCHEMATIC.load(path).getClipboard()); return new CuboidClipboard((BlockVector3) BuiltInClipboardFormat.MCEDIT_SCHEMATIC.load(path).getClipboard());
} }
/** /**

View File

@ -981,7 +981,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
} }
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return world.getFullBlock(position); return world.getFullBlock(position);
} }
@ -1094,12 +1094,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
} }
@Deprecated @Deprecated
public boolean setBlock(int x, int y, int z, BaseBlock block) { public boolean setBlock(int x, int y, int z, BaseBlock block) {
return setBlock(x, y, z, (BlockState) block); return setBlock(x, y, z, block.toImmutableState());
} }
@Deprecated @Deprecated
public boolean setBlock(BlockVector3 position, BaseBlock block) throws MaxChangedBlocksException { public boolean setBlock(BlockVector3 position, BaseBlock block) throws MaxChangedBlocksException {
return setBlock(position, (BlockState) block); return setBlock(position, block.toImmutableState());
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -2502,16 +2502,16 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
} }
for (int y = maxY; y >= 1; --y) { for (int y = maxY; y >= 1; --y) {
final BlockType type = getBlockType(x, y, z); final BlockType type = getBlockType(x, y, z);
switch (type.getTypeEnum()) { switch (type.getResource().toUpperCase()) {
case ICE: case "ICE":
this.setBlock(x, y, z, BlockTypes.WATER.getDefaultState()); this.setBlock(x, y, z, BlockTypes.WATER.getDefaultState());
break; break;
case SNOW: case "SNOW":
this.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); this.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
break; break;
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
case AIR: case "AIR":
continue; continue;
default: default:
break; break;
@ -2574,20 +2574,20 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
outer: outer:
for (int y = maxY; y >= 1; --y) { for (int y = maxY; y >= 1; --y) {
BlockType type = getBlockType(x, y, z); BlockType type = getBlockType(x, y, z);
switch (type.getTypeEnum()) { switch (type.getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
continue; continue;
case WATER: case "WATER":
this.setBlock(x, y, z, BlockTypes.ICE.getDefaultState()); this.setBlock(x, y, z, BlockTypes.ICE.getDefaultState());
break outer; break outer;
case ACACIA_LEAVES: // TODO FIXME get leaves dynamically case "ACACIA_LEAVES": // TODO FIXME get leaves dynamically
case BIRCH_LEAVES: case "BIRCH_LEAVES":
case DARK_OAK_LEAVES: case "DARK_OAK_LEAVES":
case JUNGLE_LEAVES: case "JUNGLE_LEAVES":
case OAK_LEAVES: case "OAK_LEAVES":
case SPRUCE_LEAVES: case "SPRUCE_LEAVES":
// int ceilRadius = (int) Math.ceil(radius); // int ceilRadius = (int) Math.ceil(radius);
// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { // for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) { // for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
@ -2670,12 +2670,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
loop: loop:
for (int y = maxY; y >= 1; --y) { for (int y = maxY; y >= 1; --y) {
BlockType block = getBlockType(x, y, z); BlockType block = getBlockType(x, y, z);
switch (block.getTypeEnum()) { switch (block.getResource().toUpperCase()) {
case DIRT: case "DIRT":
this.setBlock(x, y, z, BlockTypes.GRASS_BLOCK.getDefaultState()); this.setBlock(x, y, z, BlockTypes.GRASS_BLOCK.getDefaultState());
break loop; break loop;
case WATER: case "WATER":
case LAVA: case "LAVA":
break loop; break loop;
default: default:
if (block.getMaterial().isMovementBlocker()) { if (block.getMaterial().isMovementBlocker()) {
@ -2770,18 +2770,18 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
this.changes++; this.changes++;
for (int y = basePosition.getBlockY(); y >= (basePosition.getBlockY() - 10); --y) { for (int y = basePosition.getBlockY(); y >= (basePosition.getBlockY() - 10); --y) {
BlockType type = getBlockType(x, y, z); BlockType type = getBlockType(x, y, z);
switch (type.getTypeEnum()) { switch (type.getResource().toUpperCase()) {
case GRASS: case "GRASS":
case DIRT: case "DIRT":
treeType.generate(this, BlockVector3.at(x, y + 1, z)); treeType.generate(this, BlockVector3.at(x, y + 1, z));
this.changes++; this.changes++;
break; break;
case SNOW: case "SNOW":
setBlock(BlockVector3.at(x, y, z), BlockTypes.AIR.getDefaultState()); setBlock(BlockVector3.at(x, y, z), BlockTypes.AIR.getDefaultState());
break; break;
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
continue; continue;
default: default:
break; break;

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository; import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
@ -53,7 +54,7 @@ public abstract class LocalConfiguration {
public String logFile = ""; public String logFile = "";
public String logFormat = LogFormat.DEFAULT_FORMAT; public String logFormat = LogFormat.DEFAULT_FORMAT;
public boolean registerHelp = true; // what is the point of this, it's not even used public boolean registerHelp = true; // what is the point of this, it's not even used
public ItemTypes wandItem = ItemTypes.WOODEN_AXE; public String wandItem = ItemTypes.WOODEN_AXE.getId();
public boolean superPickaxeDrop = true; public boolean superPickaxeDrop = true;
public boolean superPickaxeManyDrop = true; public boolean superPickaxeManyDrop = true;
public boolean noDoubleSlash = false; public boolean noDoubleSlash = false;
@ -61,7 +62,7 @@ public abstract class LocalConfiguration {
public boolean useInventoryOverride = false; public boolean useInventoryOverride = false;
public boolean useInventoryCreativeOverride = false; public boolean useInventoryCreativeOverride = false;
public boolean navigationUseGlass = true; public boolean navigationUseGlass = true;
public ItemTypes navigationWand = ItemTypes.COMPASS; public String navigationWand = ItemTypes.COMPASS.getId();
public int navigationWandMaxDistance = 50; public int navigationWandMaxDistance = 50;
public int scriptTimeout = 3000; public int scriptTimeout = 3000;
public Set<BlockType> allowedDataCycleBlocks = new HashSet<>(); public Set<BlockType> allowedDataCycleBlocks = new HashSet<>();

View File

@ -1030,12 +1030,12 @@ public class LocalSession implements TextureHolder {
} }
public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException { public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException {
ItemTypes type = item.getType(); ItemType type = item.getType();
if (type.hasBlockType() && type.getBlockType().getMaterial().isAir()) { if (type.hasBlockType() && type.getBlockType().getMaterial().isAir()) {
throw new InvalidToolBindException(type, "Blocks can't be used"); throw new InvalidToolBindException(type, "Blocks can't be used");
} else if (type == config.wandItem) { } else if (type.getId().equalsIgnoreCase(config.wandItem)) {
throw new InvalidToolBindException(type, "Already used for the wand"); throw new InvalidToolBindException(type, "Already used for the wand");
} else if (type == config.navigationWand) { } else if (type.getId().equalsIgnoreCase(config.navigationWand)) {
throw new InvalidToolBindException(type, "Already used for the navigation wand"); throw new InvalidToolBindException(type, "Already used for the navigation wand");
} }
Tool previous; Tool previous;

View File

@ -69,8 +69,8 @@ public class BaseItem implements NbtValued {
* *
* @return the type * @return the type
*/ */
public ItemTypes getType() { public ItemType getType() {
return (ItemTypes) this.itemType; return this.itemType;
} }
/** /**

View File

@ -1,220 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.blocks;
import com.sk89q.worldedit.registry.state.PropertyGroup;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Block types.
*
* {@deprecated Please use {@link com.sk89q.worldedit.world.block.BlockType }}
*/
@Deprecated
public class BlockType {
public static double centralTopLimit(com.sk89q.worldedit.world.block.BlockType type) {
checkNotNull(type);
return centralTopLimit(type.getDefaultState());
}
public static double centralBottomLimit(BlockStateHolder block) {
checkNotNull(block);
BlockTypes type = block.getBlockType();
switch (type) {
case CREEPER_WALL_HEAD:
case DRAGON_WALL_HEAD:
case PLAYER_WALL_HEAD:
case ZOMBIE_WALL_HEAD: return 0.25;
case ACACIA_SLAB:
case BIRCH_SLAB:
case BRICK_SLAB:
case COBBLESTONE_SLAB:
case DARK_OAK_SLAB:
case DARK_PRISMARINE_SLAB:
case JUNGLE_SLAB:
case NETHER_BRICK_SLAB:
case OAK_SLAB:
case PETRIFIED_OAK_SLAB:
case PRISMARINE_BRICK_SLAB:
case PRISMARINE_SLAB:
case PURPUR_SLAB:
case QUARTZ_SLAB:
case RED_SANDSTONE_SLAB:
case SANDSTONE_SLAB:
case SPRUCE_SLAB:
case STONE_BRICK_SLAB:
case STONE_SLAB: {
String state = (String) block.getState(PropertyKey.TYPE);
if (state == null) return 0;
switch (state) {
case "double":
case "bottom":
return 0;
case "top":
return 0.5;
}
}
case ACACIA_TRAPDOOR:
case BIRCH_TRAPDOOR:
case DARK_OAK_TRAPDOOR:
case IRON_TRAPDOOR:
case JUNGLE_TRAPDOOR:
case OAK_TRAPDOOR:
case SPRUCE_TRAPDOOR:
if (block.getState(PropertyKey.OPEN) == Boolean.TRUE) {
return 1;
} else if ("bottom".equals(block.getState(PropertyKey.HALF))) {
return 0.8125;
} else {
return 0;
}
case ACACIA_FENCE_GATE:
case BIRCH_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case JUNGLE_FENCE_GATE:
case OAK_FENCE_GATE:
case SPRUCE_FENCE_GATE: return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 1 : 0;
default:
if (type.getMaterial().isMovementBlocker()) return 0;
return 1;
}
}
/**
* Returns the y offset a player falls to when falling onto the top of a block at xp+0.5/zp+0.5.
*
* @param block the block
* @return the y offset
*/
public static double centralTopLimit(BlockStateHolder block) {
checkNotNull(block);
BlockTypes type = block.getBlockType();
switch (type) {
case BLACK_BED:
case BLUE_BED:
case BROWN_BED:
case CYAN_BED:
case GRAY_BED:
case GREEN_BED:
case LIGHT_BLUE_BED:
case LIGHT_GRAY_BED:
case LIME_BED:
case MAGENTA_BED:
case ORANGE_BED:
case PINK_BED:
case PURPLE_BED:
case RED_BED:
case WHITE_BED:
case YELLOW_BED: return 0.5625;
case BREWING_STAND: return 0.875;
case CAKE: return (block.getState(PropertyKey.BITES) == (Integer) 6) ? 0 : 0.4375;
case CAULDRON: return 0.3125;
case COCOA: return 0.750;
case ENCHANTING_TABLE: return 0.75;
case END_PORTAL_FRAME: return block.getState(PropertyKey.EYE) == Boolean.TRUE ? 1 : 0.8125;
case CREEPER_HEAD:
case DRAGON_HEAD:
case PISTON_HEAD:
case PLAYER_HEAD:
case ZOMBIE_HEAD: return 0.5;
case CREEPER_WALL_HEAD:
case DRAGON_WALL_HEAD:
case PLAYER_WALL_HEAD:
case ZOMBIE_WALL_HEAD: return 0.75;
case ACACIA_FENCE:
case BIRCH_FENCE:
case DARK_OAK_FENCE:
case JUNGLE_FENCE:
case NETHER_BRICK_FENCE:
case OAK_FENCE:
case SPRUCE_FENCE: return 1.5;
case ACACIA_SLAB:
case BIRCH_SLAB:
case BRICK_SLAB:
case COBBLESTONE_SLAB:
case DARK_OAK_SLAB:
case DARK_PRISMARINE_SLAB:
case JUNGLE_SLAB:
case NETHER_BRICK_SLAB:
case OAK_SLAB:
case PETRIFIED_OAK_SLAB:
case PRISMARINE_BRICK_SLAB:
case PRISMARINE_SLAB:
case PURPUR_SLAB:
case QUARTZ_SLAB:
case RED_SANDSTONE_SLAB:
case SANDSTONE_SLAB:
case SPRUCE_SLAB:
case STONE_BRICK_SLAB:
case STONE_SLAB: {
String state = (String) block.getState(PropertyKey.TYPE);
if (state == null) return 0.5;
switch (state) {
case "bottom":
return 0.5;
case "top":
case "double":
return 1;
}
}
case LILY_PAD: return 0.015625;
case REPEATER: return 0.125;
case SOUL_SAND: return 0.875;
case COBBLESTONE_WALL:
case MOSSY_COBBLESTONE_WALL: return 1.5;
case FLOWER_POT: return 0.375;
case COMPARATOR: return 0.125;
case DAYLIGHT_DETECTOR: return 0.375;
case HOPPER: return 0.625;
case ACACIA_TRAPDOOR:
case BIRCH_TRAPDOOR:
case DARK_OAK_TRAPDOOR:
case IRON_TRAPDOOR:
case JUNGLE_TRAPDOOR:
case OAK_TRAPDOOR:
case SPRUCE_TRAPDOOR:
if (block.getState(PropertyKey.OPEN) == Boolean.TRUE) {
return 0;
} else if ("top".equals(block.getState(PropertyKey.HALF))) {
return 1;
} else {
return 0.1875;
}
case ACACIA_FENCE_GATE:
case BIRCH_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case JUNGLE_FENCE_GATE:
case OAK_FENCE_GATE:
case SPRUCE_FENCE_GATE: return block.getState(PropertyKey.OPEN) == Boolean.TRUE ? 0 : 1.5;
default:
if (type.hasProperty(PropertyKey.LAYERS)) {
return PropertyGroup.LEVEL.get(block) * 0.0625;
}
if (!type.getMaterial().isMovementBlocker()) return 0;
return 1;
}
}
}

View File

@ -57,6 +57,7 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask; import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
@ -469,7 +470,7 @@ public class BrushCommands extends BrushProcessor {
try { try {
MultiClipboardHolder clipboards = ClipboardFormat.SCHEMATIC.loadAllFromInput(player, clipboard, null, true); MultiClipboardHolder clipboards = ClipboardFormats.loadAllFromInput(player, clipboard, null, true);
if (clipboards == null) { if (clipboards == null) {
BBC.SCHEMATIC_NOT_FOUND.send(player, clipboard); BBC.SCHEMATIC_NOT_FOUND.send(player, clipboard);
return null; return null;

View File

@ -55,7 +55,9 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.PasteEvent; import com.sk89q.worldedit.event.extent.PasteEvent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.block.BlockReplace;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
@ -296,7 +298,7 @@ public class ClipboardCommands extends MethodCommands {
@Deprecated @Deprecated
@CommandPermissions({"worldedit.clipboard.download"}) @CommandPermissions({"worldedit.clipboard.download"})
public void download(final Player player, final LocalSession session, @Optional("schematic") final String formatName) throws CommandException, WorldEditException { public void download(final Player player, final LocalSession session, @Optional("schematic") final String formatName) throws CommandException, WorldEditException {
final ClipboardFormat format = ClipboardFormat.findByAlias(formatName); final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) { if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName); BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
return; return;
@ -356,8 +358,8 @@ public class ClipboardCommands extends MethodCommands {
} else { } else {
target = clipboard; target = clipboard;
} }
switch (format) { switch (format.getName()) {
case PNG: case "PNG":
try { try {
FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE); FastByteArrayOutputStream baos = new FastByteArrayOutputStream(Short.MAX_VALUE);
ClipboardWriter writer = format.getWriter(baos); ClipboardWriter writer = format.getWriter(baos);
@ -369,7 +371,7 @@ public class ClipboardCommands extends MethodCommands {
url = null; url = null;
} }
break; break;
case SCHEMATIC: case "SCHEMATIC":
if (Settings.IMP.WEB.URL.isEmpty()) { if (Settings.IMP.WEB.URL.isEmpty()) {
BBC.SETTING_DISABLE.send(player, "web.url"); BBC.SETTING_DISABLE.send(player, "web.url");
return; return;
@ -380,30 +382,30 @@ public class ClipboardCommands extends MethodCommands {
url = null; url = null;
break; break;
} }
} if (url == null) {
if (url == null) { BBC.GENERATING_LINK_FAILED.send(player);
BBC.GENERATING_LINK_FAILED.send(player); } else {
} else { String urlText = url.toString();
String urlText = url.toString(); if (Settings.IMP.WEB.SHORTEN_URLS) {
if (Settings.IMP.WEB.SHORTEN_URLS) { try {
try { urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8"));
urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8")); } catch (IOException e) {
} catch (IOException e) { e.printStackTrace();
e.printStackTrace(); }
} }
} if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) {
if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) { FormBuilder form = Fawe.imp().getFormBuilder();
FormBuilder form = Fawe.imp().getFormBuilder(); FawePlayer<Object> fp = FawePlayer.wrap(player);
FawePlayer<Object> fp = FawePlayer.wrap(player); if (form != null && fp != FakePlayer.getConsole().toFawePlayer()) {
if (form != null && fp != FakePlayer.getConsole().toFawePlayer()) { form.setTitle("Download Clipboard");
form.setTitle("Download Clipboard"); form.addInput("url:", urlText, urlText);
form.addInput("url:", urlText, urlText); form.display(fp);
form.display(fp); return;
return; }
} }
} BBC.DOWNLOAD_LINK.send(player, urlText);
BBC.DOWNLOAD_LINK.send(player, urlText); }
} }
} }
@Command( @Command(
@ -416,7 +418,7 @@ public class ClipboardCommands extends MethodCommands {
) )
@CommandPermissions({"worldedit.clipboard.asset"}) @CommandPermissions({"worldedit.clipboard.asset"})
public void asset(final Player player, final LocalSession session, String category) throws CommandException, WorldEditException { public void asset(final Player player, final LocalSession session, String category) throws CommandException, WorldEditException {
final ClipboardFormat format = ClipboardFormat.SCHEMATIC; final ClipboardFormat format = BuiltInClipboardFormat.MCEDIT_SCHEMATIC;
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard(); Clipboard clipboard = holder.getClipboard();
final Transform transform = holder.getTransform(); final Transform transform = holder.getTransform();
@ -430,7 +432,7 @@ public class ClipboardCommands extends MethodCommands {
} else { } else {
target = clipboard; target = clipboard;
} }
BBC.GENERATING_LINK.send(player, format.name()); BBC.GENERATING_LINK.send(player, format.getName());
if (Settings.IMP.WEB.ASSETS.isEmpty()) { if (Settings.IMP.WEB.ASSETS.isEmpty()) {
BBC.SETTING_DISABLE.send(player, "web.assets"); BBC.SETTING_DISABLE.send(player, "web.assets");
return; return;
@ -478,7 +480,7 @@ public class ClipboardCommands extends MethodCommands {
} }
Clipboard clipboard = holder.getClipboard(); Clipboard clipboard = holder.getClipboard();
Region region = clipboard.getRegion(); Region region = clipboard.getRegion();
BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player); BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player);
checkPaste(player, editSession, to, holder, clipboard); checkPaste(player, editSession, to, holder, clipboard);
Operation operation = holder Operation operation = holder
.createPaste(editSession) .createPaste(editSession)

View File

@ -187,7 +187,7 @@ public class GeneralCommands {
int found = 0; int found = 0;
for (ItemType searchType : ItemTypes.values) { for (ItemType searchType : ItemTypes.values()) {
if (found >= 15) { if (found >= 15) {
actor.print(BBC.getPrefix() + "Too many results!"); actor.print(BBC.getPrefix() + "Too many results!");
break; break;

View File

@ -284,7 +284,7 @@ public class OptionsCommands {
int found = 0; int found = 0;
for (ItemType searchType : ItemTypes.values) { for (ItemType searchType : ItemTypes.values()) {
if (found >= 15) { if (found >= 15) {
actor.print(BBC.getPrefix() + "Too many results!"); actor.print(BBC.getPrefix() + "Too many results!");
break; break;

View File

@ -16,6 +16,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.ClipboardPattern; import com.sk89q.worldedit.function.pattern.ClipboardPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
@ -191,7 +192,7 @@ public class PatternCommands extends MethodCommands {
clipboards = Collections.singletonList(clipboard); clipboards = Collections.singletonList(clipboard);
break; break;
default: default:
MultiClipboardHolder multi = ClipboardFormat.SCHEMATIC.loadAllFromInput(player, location, null, true); MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, location, null, true);
clipboards = multi != null ? multi.getHolders() : null; clipboards = multi != null ? multi.getHolders() : null;
break; break;
} }

View File

@ -45,6 +45,7 @@ import com.sk89q.worldedit.event.extent.PlayerSaveClipboardEvent;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
@ -99,13 +100,13 @@ public class SchematicCommands extends MethodCommands {
@Deprecated @Deprecated
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.load.web", "worldedit.schematic.load.asset"}) @CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.load.web", "worldedit.schematic.load.asset"})
public void loadall(final Player player, final LocalSession session, @Optional("schematic") final String formatName, final String filename, @Switch('r') boolean randomRotate) throws FilenameException { public void loadall(final Player player, final LocalSession session, @Optional("schematic") final String formatName, final String filename, @Switch('r') boolean randomRotate) throws FilenameException {
final ClipboardFormat format = ClipboardFormat.findByAlias(formatName); final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) { if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName); BBC.CLIPBOARD_INVALID_FORMAT.send(player, formatName);
return; return;
} }
try { try {
MultiClipboardHolder all = format.loadAllFromInput(player, filename, null, true); MultiClipboardHolder all = ClipboardFormats.loadAllFromInput(player, filename, null, true);
if (all != null) { if (all != null) {
session.addClipboard(all); session.addClipboard(all);
BBC.SCHEMATIC_LOADED.send(player, filename); BBC.SCHEMATIC_LOADED.send(player, filename);
@ -192,7 +193,7 @@ public class SchematicCommands extends MethodCommands {
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.load.asset", "worldedit.schematic.load.web", "worldedit.schematic.load.other"}) @CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.load.asset", "worldedit.schematic.load.web", "worldedit.schematic.load.other"})
public void load(final Player player, final LocalSession session, @Optional() final String formatName, String filename) throws FilenameException { public void load(final Player player, final LocalSession session, @Optional() final String formatName, String filename) throws FilenameException {
final LocalConfiguration config = this.worldEdit.getConfiguration(); final LocalConfiguration config = this.worldEdit.getConfiguration();
ClipboardFormat format = formatName == null ? null : ClipboardFormat.findByAlias(formatName); ClipboardFormat format = formatName == null ? null : ClipboardFormats.findByAlias(formatName);
InputStream in = null; InputStream in = null;
try { try {
URI uri; URI uri;
@ -207,7 +208,7 @@ public class SchematicCommands extends MethodCommands {
ReadableByteChannel rbc = Channels.newChannel(url.openStream()); ReadableByteChannel rbc = Channels.newChannel(url.openStream());
in = Channels.newInputStream(rbc); in = Channels.newInputStream(rbc);
uri = url.toURI(); uri = url.toURI();
if (format == null) format = ClipboardFormat.SCHEMATIC; if (format == null) format = BuiltInClipboardFormat.MCEDIT_SCHEMATIC;
} else { } else {
if (!player.hasPermission("worldedit.schematic.load") && !player.hasPermission("worldedit.clipboard.load")) { if (!player.hasPermission("worldedit.schematic.load") && !player.hasPermission("worldedit.clipboard.load")) {
BBC.NO_PERM.send(player, "worldedit.clipboard.load"); BBC.NO_PERM.send(player, "worldedit.clipboard.load");
@ -235,7 +236,7 @@ public class SchematicCommands extends MethodCommands {
} }
if (format == null && filename.matches(".*\\.[\\w].*")) { if (format == null && filename.matches(".*\\.[\\w].*")) {
String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length()); String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
format = ClipboardFormat.findByExtension(extension); format = ClipboardFormats.findByExtension(extension);
} }
f = MainUtil.resolve(dir, filename, format, false); f = MainUtil.resolve(dir, filename, format, false);
} }
@ -250,7 +251,7 @@ public class SchematicCommands extends MethodCommands {
return; return;
} }
if (format == null) { if (format == null) {
format = ClipboardFormat.findByFile(f); format = ClipboardFormats.findByFile(f);
if (format == null) { if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName()); BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName());
return; return;
@ -281,7 +282,7 @@ public class SchematicCommands extends MethodCommands {
@CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save", "worldedit.schematic.save.other"}) @CommandPermissions({"worldedit.clipboard.save", "worldedit.schematic.save", "worldedit.schematic.save.other"})
public void save(final Player player, final LocalSession session, @Optional("schem") final String formatName, String filename, @Switch('g') boolean global) throws CommandException, WorldEditException { public void save(final Player player, final LocalSession session, @Optional("schem") final String formatName, String filename, @Switch('g') boolean global) throws CommandException, WorldEditException {
final LocalConfiguration config = this.worldEdit.getConfiguration(); final LocalConfiguration config = this.worldEdit.getConfiguration();
final ClipboardFormat format = ClipboardFormat.findByAlias(formatName); final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) { if (format == null) {
player.printError("Unknown schematic format: " + formatName); player.printError("Unknown schematic format: " + formatName);
return; return;
@ -298,14 +299,14 @@ public class SchematicCommands extends MethodCommands {
filename = filename.substring(3); filename = filename.substring(3);
} }
} }
File f = this.worldEdit.getSafeSaveFile(player, dir, filename, format.getExtension(), format.getExtension()); File f = this.worldEdit.getSafeSaveFile(player, dir, filename, format.getPrimaryFileExtension(), format.getPrimaryFileExtension());
if (f.getName().replaceAll("." + format.getExtension(), "").isEmpty()) { if (f.getName().replaceAll("." + format.getPrimaryFileExtension(), "").isEmpty()) {
File directory = f.getParentFile(); File directory = f.getParentFile();
if (directory.exists()) { if (directory.exists()) {
int max = MainUtil.getMaxFileId(directory); int max = MainUtil.getMaxFileId(directory);
f = new File(directory, max + "." + format.getExtension()); f = new File(directory, max + "." + format.getPrimaryFileExtension());
} else { } else {
f = new File(directory, "1." + format.getExtension()); f = new File(directory, "1." + format.getPrimaryFileExtension());
} }
} }
final File parent = f.getParentFile(); final File parent = f.getParentFile();
@ -477,9 +478,9 @@ public class SchematicCommands extends MethodCommands {
Message m = new Message(BBC.SCHEMATIC_FORMAT).newline(); Message m = new Message(BBC.SCHEMATIC_FORMAT).newline();
String baseCmd = Commands.getAlias(SchematicCommands.class, "schematic") + " " + Commands.getAlias(SchematicCommands.class, "save"); String baseCmd = Commands.getAlias(SchematicCommands.class, "schematic") + " " + Commands.getAlias(SchematicCommands.class, "save");
boolean first = true; boolean first = true;
for (final ClipboardFormat format : ClipboardFormat.values) { for (final ClipboardFormat format : ClipboardFormats.getAll()) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(format.name()).append(": "); builder.append(format.getName()).append(": ");
for (final String lookupName : format.getAliases()) { for (final String lookupName : format.getAliases()) {
if (!first) { if (!first) {
builder.append(", "); builder.append(", ");
@ -487,7 +488,7 @@ public class SchematicCommands extends MethodCommands {
builder.append(lookupName); builder.append(lookupName);
first = false; first = false;
} }
String cmd = baseCmd + " " + format.name() + " <filename>"; String cmd = baseCmd + " " + format.getName() + " <filename>";
m.text(builder).suggestTip(cmd).newline(); m.text(builder).suggestTip(cmd).newline();
first = true; first = true;
} }

View File

@ -37,7 +37,6 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
@ -287,7 +286,7 @@ public class SelectionCommands {
) )
@CommandPermissions("worldedit.wand") @CommandPermissions("worldedit.wand")
public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
player.giveItem(new BaseItemStack(we.getConfiguration().wandItem, 1)); player.giveItem(new BaseItemStack(ItemTypes.parse(we.getConfiguration().wandItem), 1));
BBC.SELECTION_WAND.send(player); BBC.SELECTION_WAND.send(player);
if (!FawePlayer.wrap(player).hasPermission("fawe.tips")) if (!FawePlayer.wrap(player).hasPermission("fawe.tips"))
BBC.TIP_SEL_LIST.or(BBC.TIP_SELECT_CONNECTED, BBC.TIP_SET_POS1, BBC.TIP_FARWAND, BBC.TIP_DISCORD).send(player); BBC.TIP_SEL_LIST.or(BBC.TIP_SELECT_CONNECTED, BBC.TIP_SET_POS1, BBC.TIP_FARWAND, BBC.TIP_DISCORD).send(player);

View File

@ -67,6 +67,7 @@ import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
@ -903,7 +904,7 @@ public class UtilityCommands extends MethodCommands {
} }
if (formatName != null) { if (formatName != null) {
final ClipboardFormat cf = ClipboardFormat.findByAlias(formatName); final ClipboardFormat cf = ClipboardFormats.findByAlias(formatName);
forEachFile = new DelegateConsumer<File>(forEachFile) { forEachFile = new DelegateConsumer<File>(forEachFile) {
@Override @Override
public void accept(File file) { public void accept(File file) {
@ -1013,7 +1014,7 @@ public class UtilityCommands extends MethodCommands {
dir = root; dir = root;
} }
ClipboardFormat format = ClipboardFormat.findByFile(file); ClipboardFormat format = ClipboardFormats.findByFile(file);
URI relative = dir.toURI().relativize(file.toURI()); URI relative = dir.toURI().relativize(file.toURI());
StringBuilder name = new StringBuilder(); StringBuilder name = new StringBuilder();
if (relative.isAbsolute()) { if (relative.isAbsolute()) {

View File

@ -132,12 +132,12 @@ public class FloatingTreeRemover implements BlockTool {
if (visited.add(next)) { if (visited.add(next)) {
BlockState state = world.getBlock(next); BlockState state = world.getBlock(next);
BlockTypes type = state.getBlockType(); BlockType type = state.getBlockType();
switch (type) { switch (type.getResource().toUpperCase()) {
case AIR: case "AIR":
case CAVE_AIR: case "CAVE_AIR":
case VOID_AIR: case "VOID_AIR":
case SNOW: case "SNOW":
continue; continue;
} }
if (isTreeBlock(state.getBlockType())) { if (isTreeBlock(state.getBlockType())) {

View File

@ -75,7 +75,7 @@ public interface Player extends Entity, Actor {
* *
* @return the item id of the item the player is holding * @return the item id of the item the player is holding
*/ */
BlockState getBlockInHand(HandSide handSide) throws WorldEditException; BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException;
/** /**
* Gives the player an item. * Gives the player an item.

View File

@ -55,6 +55,7 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
@ -77,7 +78,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
private static BlockState getBlockInHand(Actor actor, HandSide handSide) throws InputParseException { private static BlockState getBlockInHand(Actor actor, HandSide handSide) throws InputParseException {
if (actor instanceof Player) { if (actor instanceof Player) {
try { try {
return ((Player) actor).getBlockInHand(handSide); return ((Player) actor).getBlockInHand(handSide).toImmutableState();
} catch (NotABlockException e) { } catch (NotABlockException e) {
throw new InputParseException("You're not holding a block!"); throw new InputParseException("You're not holding a block!");
} catch (WorldEditException e) { } catch (WorldEditException e) {
@ -179,7 +180,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
} else if (MathMan.isInteger(split[0])) { } else if (MathMan.isInteger(split[0])) {
state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1])); state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} else { } else {
BlockTypes type = BlockTypes.get(split[0].toLowerCase()); BlockType type = BlockTypes.get(split[0].toLowerCase());
if (type != null) { if (type != null) {
state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, Integer.parseInt(split[1])); state = LegacyMapper.getInstance().getBlockFromLegacy(type.getLegacyCombinedId() >> 4, Integer.parseInt(split[1]));
} }
@ -238,7 +239,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
state = item.getType().getBlockType().getDefaultState(); state = item.getType().getBlockType().getDefaultState();
nbt = item.getNbtData(); nbt = item.getNbtData();
} else { } else {
BlockTypes type = BlockTypes.parse(typeString.toLowerCase()); BlockType type = BlockTypes.parse(typeString.toLowerCase());
if (type != null) state = type.getDefaultState(); if (type != null) state = type.getDefaultState();
if (state == null) { if (state == null) {
throw new NoMatchException("Does not match a valid block type: '" + input + "'"); throw new NoMatchException("Does not match a valid block type: '" + input + "'");
@ -261,7 +262,7 @@ public class DefaultBlockParser extends InputParser<BlockStateHolder> {
} }
// Check if the item is allowed // Check if the item is allowed
BlockTypes blockType = state.getBlockType(); BlockType blockType = state.getBlockType();
if (context.isRestricted()) { if (context.isRestricted()) {
Actor actor = context.requireActor(); Actor actor = context.requireActor();

View File

@ -53,7 +53,7 @@ public class DefaultItemParser extends InputParser<BaseItem> {
if (type != null) { if (type != null) {
Integer legacy = LegacyMapper.getInstance().getLegacyCombined(type); Integer legacy = LegacyMapper.getInstance().getLegacyCombined(type);
if (legacy != null) { if (legacy != null) {
ItemTypes newType = LegacyMapper.getInstance().getItemFromLegacy(legacy >> 4, Integer.parseInt(split[1])); ItemType newType = LegacyMapper.getInstance().getItemFromLegacy(legacy >> 4, Integer.parseInt(split[1]));
if (newType != null) type = newType; if (newType != null) type = newType;
} }
} }

View File

@ -33,8 +33,9 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TargetBlock; import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypeUtil;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameMode;
@ -125,7 +126,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (y - 1 != origY) { if (y - 1 != origY) {
final BlockVector3 pos = BlockVector3.at(x, y - 2, z); final BlockVector3 pos = BlockVector3.at(x, y - 2, z);
final BlockStateHolder state = world.getBlock(pos); final BlockStateHolder state = world.getBlock(pos);
setPosition(Vector3.at(x + 0.5, y - 2 + BlockType.centralTopLimit(state), z + 0.5)); setPosition(Vector3.at(x + 0.5, y - 2 + BlockTypeUtil.centralTopLimit(state), z + 0.5));
// setPosition(Vector3.at(x + 0.5, y - 2 + 1, z + 0.5)); // setPosition(Vector3.at(x + 0.5, y - 2 + 1, z + 0.5));
} }
@ -147,7 +148,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final BlockVector3 pos = BlockVector3.at(x, y, z); final BlockVector3 pos = BlockVector3.at(x, y, z);
final BlockState id = world.getBlock(pos); final BlockState id = world.getBlock(pos);
if (id.getBlockType().getMaterial().isMovementBlocker()) { if (id.getBlockType().getMaterial().isMovementBlocker()) {
setPosition(Vector3.at(x + 0.5, y + + BlockType.centralTopLimit(id), z + 0.5)); setPosition(Vector3.at(x + 0.5, y + + BlockTypeUtil.centralTopLimit(id), z + 0.5));
return; return;
} }
@ -182,18 +183,18 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
BlockState state; BlockState state;
if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState(); if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState();
else state = world.getBlock(BlockVector3.at(x, level, z)); else state = world.getBlock(BlockVector3.at(x, level, z));
BlockTypes type = state.getBlockType(); BlockType type = state.getBlockType();
BlockMaterial material = type.getMaterial(); BlockMaterial material = type.getMaterial();
if (!material.isFullCube() || !material.isMovementBlocker()) { if (!material.isFullCube() || !material.isMovementBlocker()) {
if (!lastState) { if (!lastState) {
lastState = BlockType.centralBottomLimit(state) != 1; lastState = BlockTypeUtil.centralBottomLimit(state) != 1;
continue; continue;
} }
if (freeStart == -1) { if (freeStart == -1) {
freeStart = level + BlockType.centralTopLimit(state); freeStart = level + BlockTypeUtil.centralTopLimit(state);
} else { } else {
double bottomLimit = BlockType.centralBottomLimit(state); double bottomLimit = BlockTypeUtil.centralBottomLimit(state);
double space = level + bottomLimit - freeStart; double space = level + bottomLimit - freeStart;
if (space >= height) { if (space >= height) {
setPosition(Vector3.at(x + 0.5, freeStart, z + 0.5)); setPosition(Vector3.at(x + 0.5, freeStart, z + 0.5));
@ -234,18 +235,18 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
BlockState state; BlockState state;
if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState(); if (level >= maxY) state = BlockTypes.VOID_AIR.getDefaultState();
else state = world.getBlock(BlockVector3.at(x, level, z)); else state = world.getBlock(BlockVector3.at(x, level, z));
BlockTypes type = state.getBlockType(); BlockType type = state.getBlockType();
BlockMaterial material = type.getMaterial(); BlockMaterial material = type.getMaterial();
if (!material.isFullCube() || !material.isMovementBlocker()) { if (!material.isFullCube() || !material.isMovementBlocker()) {
if (!lastState) { if (!lastState) {
lastState = BlockType.centralTopLimit(state) != 0; lastState = BlockTypeUtil.centralTopLimit(state) != 0;
continue; continue;
} }
if (freeEnd == -1) { if (freeEnd == -1) {
freeEnd = level + BlockType.centralBottomLimit(state); freeEnd = level + BlockTypeUtil.centralBottomLimit(state);
} else { } else {
double topLimit = BlockType.centralTopLimit(state); double topLimit = BlockTypeUtil.centralTopLimit(state);
double freeStart = level + topLimit; double freeStart = level + topLimit;
double space = freeEnd - freeStart; double space = freeEnd - freeStart;
if (space >= height) { if (space >= height) {
@ -398,7 +399,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
} }
@Override @Override
public BlockState getBlockInHand(HandSide handSide) throws WorldEditException { public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
final ItemType typeId = getItemInHand(handSide).getType(); final ItemType typeId = getItemInHand(handSide).getType();
if (typeId.hasBlockType()) { if (typeId.hasBlockType()) {
return typeId.getBlockType().getDefaultState().toBaseBlock(); return typeId.getBlockType().getDefaultState().toBaseBlock();

View File

@ -319,7 +319,7 @@ public class PlatformManager {
} }
if (event.getType() == Interaction.HIT) { if (event.getType() == Interaction.HIT) {
if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().equals(getConfiguration().wandItem)) { if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
FawePlayer<?> fp = FawePlayer.wrap(playerActor); FawePlayer<?> fp = FawePlayer.wrap(playerActor);
if (!actor.hasPermission("worldedit.selection.pos")) { if (!actor.hasPermission("worldedit.selection.pos")) {
return; return;
@ -378,7 +378,7 @@ public class PlatformManager {
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner //>>>>>>> 399e0ad5... Refactor vector system to be cleaner
} }
} else if (event.getType() == Interaction.OPEN) { } else if (event.getType() == Interaction.OPEN) {
if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().equals(getConfiguration().wandItem)) { if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().wandItem)) {
FawePlayer<?> fp = FawePlayer.wrap(playerActor); FawePlayer<?> fp = FawePlayer.wrap(playerActor);
if (!actor.hasPermission("worldedit.selection.pos")) { if (!actor.hasPermission("worldedit.selection.pos")) {
return; return;

View File

@ -20,7 +20,7 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -70,7 +70,7 @@ public class PlayerProxy extends AbstractPlayerActor {
@Override @Override
public BlockState getBlockInHand(HandSide handSide) throws WorldEditException { public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
return basePlayer.getBlockInHand(handSide); return basePlayer.getBlockInHand(handSide);
} }

View File

@ -81,7 +81,7 @@ public class AbstractDelegateExtent implements LightingExtent {
} }
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return extent.getFullBlock(position); return extent.getFullBlock(position);
} }
@ -138,7 +138,7 @@ public class AbstractDelegateExtent implements LightingExtent {
} }
@Override @Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
// mutable.mutX(x); // mutable.mutX(x);
// mutable.mutY(y); // mutable.mutY(y);
// mutable.mutZ(z); // mutable.mutZ(z);
@ -150,7 +150,7 @@ public class AbstractDelegateExtent implements LightingExtent {
} }
@Override @Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
return extent.setBlock(location, block); return extent.setBlock(location, block);
} }

View File

@ -118,19 +118,19 @@ public interface Extent extends InputExtent, OutputExtent {
@Override @Override
default BlockState getBlock(BlockVector3 position) { default BlockState getBlock(BlockVector3 position) {
return getFullBlock(position); return getFullBlock(position).toImmutableState();
} }
@Override @Override
default BlockState getLazyBlock(BlockVector3 position) { default BlockState getLazyBlock(BlockVector3 position) {
return getFullBlock(position); return getFullBlock(position).toImmutableState();
} }
default BlockState getLazyBlock(int x, int y, int z) { default BlockState getLazyBlock(int x, int y, int z) {
return getLazyBlock(BlockVector3.at(x, y, z)); return getLazyBlock(BlockVector3.at(x, y, z));
} }
default boolean setBlock(int x, int y, int z, BlockStateHolder state) throws WorldEditException { default <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T state) throws WorldEditException {
return setBlock(BlockVector3.at(x, y, z), state); return setBlock(BlockVector3.at(x, y, z), state);
} }

View File

@ -80,7 +80,7 @@ public interface InputExtent {
* @param position position of the block * @param position position of the block
* @return the block * @return the block
*/ */
BlockState getFullBlock(BlockVector3 position); BaseBlock getFullBlock(BlockVector3 position);
/** /**
* Get the biome at the given location. * Get the biome at the given location.

View File

@ -50,7 +50,7 @@ public interface OutputExtent {
* @return true if the block was successfully set (return value may not be accurate) * @return true if the block was successfully set (return value may not be accurate)
* @throws WorldEditException thrown on an error * @throws WorldEditException thrown on an error
*/ */
boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException; <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException;
/** /**
* Set the biome. * Set the biome.

View File

@ -234,8 +234,8 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner //>>>>>>> 399e0ad5... Refactor vector system to be cleaner
@Override @Override
public BlockState getFullBlock(BlockVector3 position) { public BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position); return getLazyBlock(position).toBaseBlock();
} }
@Override @Override

View File

@ -19,28 +19,220 @@
package com.sk89q.worldedit.extent.clipboard.io; package com.sk89q.worldedit.extent.clipboard.io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import com.boydti.fawe.object.clipboard.AbstractClipboardFormat;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.object.io.ResettableFileInputStream;
import com.boydti.fawe.object.schematic.PNGWriter;
import com.boydti.fawe.object.schematic.StructureFormat;
import com.google.common.collect.ImmutableSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTConstants;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.NamedTag;
import com.sk89q.jnbt.Tag;
/** /**
* A collection of supported clipboard formats. * A collection of supported clipboard formats.
*/ */
@Deprecated public enum BuiltInClipboardFormat implements ClipboardFormat{
public class BuiltInClipboardFormat { /**
public static final ClipboardFormat MCEDIT_SCHEMATIC = ClipboardFormat.SCHEMATIC; * The Schematic format used by many software.
public static final ClipboardFormat SPONGE_SCHEMATIC = ClipboardFormat.SPONGE_SCHEMATIC; */
public static final ClipboardFormat STRUCTURE = ClipboardFormat.STRUCTURE;
public static final ClipboardFormat PNG = ClipboardFormat.PNG;
@Deprecated @Deprecated
public static final ClipboardFormat[] values() { MCEDIT_SCHEMATIC("mcedit", "mce", "schematic") {
return ClipboardFormat.values; @Override
} public ClipboardReader getReader(InputStream inputStream) throws IOException {
if (inputStream instanceof FileInputStream) {
@Deprecated inputStream = new ResettableFileInputStream((FileInputStream) inputStream);
public static ClipboardFormat valueOf(String value) { }
switch (value) { BufferedInputStream buffered = new BufferedInputStream(inputStream);
case "MCEDIT_SCHEMATIC": NBTInputStream nbtStream = new NBTInputStream(new BufferedInputStream(new GZIPInputStream(buffered)));
value = "SCHEMATIC"; SchematicReader input = new SchematicReader(nbtStream);
break; input.setUnderlyingStream(inputStream);
return input;
} }
return ClipboardFormat.valueOf(value);
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
throw new UnsupportedOperationException("No longer supported.");
}
@Override
public boolean isFormat(File file) {
try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) {
NamedTag rootTag = str.readNamedTag();
if (!rootTag.getName().equals("Schematic")) {
return false;
}
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Materials")) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
@Override
public String getPrimaryFileExtension() {
return "schematic";
}
},
@Deprecated
SPONGE_SCHEMATIC("sponge", "schem") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
if (inputStream instanceof FileInputStream) {
inputStream = new ResettableFileInputStream((FileInputStream) inputStream);
}
BufferedInputStream buffered = new BufferedInputStream(inputStream);
NBTInputStream nbtStream = new NBTInputStream(new BufferedInputStream(new GZIPInputStream(buffered)));
SpongeSchematicReader input = new SpongeSchematicReader(nbtStream);
return input;
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
OutputStream gzip;
if (outputStream instanceof PGZIPOutputStream || outputStream instanceof GZIPOutputStream) {
gzip = outputStream;
} else {
outputStream = new BufferedOutputStream(outputStream);
PGZIPOutputStream pigz = new PGZIPOutputStream(outputStream);
gzip = pigz;
}
NBTOutputStream nbtStream = new NBTOutputStream(new BufferedOutputStream(gzip));
return new SpongeSchematicWriter(nbtStream);
}
@Override
public boolean isFormat(File file) {
try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) {
NamedTag rootTag = str.readNamedTag();
if (!rootTag.getName().equals("Schematic")) {
return false;
}
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
// Check
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Version")) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
@Override
public String getPrimaryFileExtension() {
return "schem";
}
},
/**
* The structure block format:
* http://minecraft.gamepedia.com/Structure_block_file_format
*/
STRUCTURE("structure", "nbt") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
inputStream = new BufferedInputStream(inputStream);
NBTInputStream nbtStream = new NBTInputStream(new BufferedInputStream(new GZIPInputStream(inputStream)));
return new StructureFormat(nbtStream);
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
outputStream = new BufferedOutputStream(outputStream);
OutputStream gzip;
if (outputStream instanceof PGZIPOutputStream || outputStream instanceof GZIPOutputStream) {
gzip = outputStream;
} else {
PGZIPOutputStream pigz = new PGZIPOutputStream(outputStream);
gzip = pigz;
}
NBTOutputStream nbtStream = new NBTOutputStream(new BufferedOutputStream(gzip));
return new StructureFormat(nbtStream);
}
@Override
public boolean isFormat(File file) {
return file.getName().endsWith(".nbt");
}
@Override
public String getPrimaryFileExtension() {
return "nbt";
}
},
/**
* Isometric PNG writer
*/
PNG("png", "image") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
return null;
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
return new PNGWriter(new BufferedOutputStream(outputStream));
}
@Override
public boolean isFormat(File file) {
return file.getName().endsWith(".png");
}
@Override
public String getPrimaryFileExtension() {
return "png";
}
};
private final ImmutableSet<String> aliases;
BuiltInClipboardFormat(String... aliases) {
this.aliases = ImmutableSet.copyOf(aliases);
} }
@Override
public String getName() {
return name();
}
@Override
public Set<String> getAliases() {
return this.aliases;
}
@Override
public Set<String> getFileExtensions() {
return ImmutableSet.of(getPrimaryFileExtension());
}
} }

View File

@ -19,275 +19,84 @@
package com.sk89q.worldedit.extent.clipboard.io; package com.sk89q.worldedit.extent.clipboard.io;
import com.boydti.fawe.config.BBC; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.jnbt.NBTStreamer;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.clipboard.*; import com.boydti.fawe.object.clipboard.URIClipboardHolder;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.object.io.PGZIPOutputStream; import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.boydti.fawe.object.io.ResettableFileInputStream;
import com.boydti.fawe.object.schematic.PNGWriter;
import com.boydti.fawe.object.schematic.Schematic; import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.object.schematic.StructureFormat;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.ReflectionUtils;
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.io.*;
import java.lang.reflect.Array;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* A collection of supported clipboard formats. * A collection of supported clipboard formats.
*/ */
public enum ClipboardFormat { public interface ClipboardFormat {
/**
* The Schematic format used by many software.
*/
@Deprecated
SCHEMATIC(new AbstractClipboardFormat("SCHEMATIC", "mcedit", "mce", "schematic") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
if (inputStream instanceof FileInputStream) {
inputStream = new ResettableFileInputStream((FileInputStream) inputStream);
}
BufferedInputStream buffered = new BufferedInputStream(inputStream);
NBTInputStream nbtStream = new NBTInputStream(new BufferedInputStream(new GZIPInputStream(buffered)));
SchematicReader input = new SchematicReader(nbtStream);
input.setUnderlyingStream(inputStream);
return input;
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
throw new UnsupportedOperationException("No longer supported.");
}
@Override
public boolean isFormat(File file) {
if (!file.getName().toLowerCase().endsWith(".schematic")) return false;
DataInputStream str = null;
try {
str = new DataInputStream(new GZIPInputStream(new FileInputStream(file)));
if ((str.readByte() & 0xFF) != NBTConstants.TYPE_COMPOUND) {
return false;
}
byte[] nameBytes = new byte[str.readShort() & 0xFFFF];
str.readFully(nameBytes);
String name = new String(nameBytes, NBTConstants.CHARSET);
return name.equals("Schematic");
} catch (IOException e) {
return false;
} finally {
if (str != null) {
try {
str.close();
} catch (IOException ignored) {
}
}
}
}
@Override
public String getExtension() {
return "schematic";
}
}),
@Deprecated
SPONGE_SCHEMATIC(new AbstractClipboardFormat("SPONGE", "sponge", "schem") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
if (inputStream instanceof FileInputStream) {
inputStream = new ResettableFileInputStream((FileInputStream) inputStream);
}
BufferedInputStream buffered = new BufferedInputStream(inputStream);
NBTInputStream nbtStream = new NBTInputStream(new BufferedInputStream(new GZIPInputStream(buffered)));
SpongeSchematicReader input = new SpongeSchematicReader(nbtStream);
return input;
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
OutputStream gzip;
if (outputStream instanceof PGZIPOutputStream || outputStream instanceof GZIPOutputStream) {
gzip = outputStream;
} else {
outputStream = new BufferedOutputStream(outputStream);
PGZIPOutputStream pigz = new PGZIPOutputStream(outputStream);
gzip = pigz;
}
NBTOutputStream nbtStream = new NBTOutputStream(new BufferedOutputStream(gzip));
return new SpongeSchematicWriter(nbtStream);
}
@Override
public boolean isFormat(File file) {
if (!file.getName().toLowerCase().endsWith(".schem")) return false;
DataInputStream str = null;
try {
str = new DataInputStream(new GZIPInputStream(new FileInputStream(file)));
if ((str.readByte() & 0xFF) != NBTConstants.TYPE_COMPOUND) {
return false;
}
byte[] nameBytes = new byte[str.readShort() & 0xFFFF];
str.readFully(nameBytes);
String name = new String(nameBytes, NBTConstants.CHARSET);
return name.equals("Schematic");
} catch (IOException e) {
return false;
} finally {
if (str != null) {
try {
str.close();
} catch (IOException ignored) {
}
}
}
}
@Override
public String getExtension() {
return "schem";
}
}),
/**
* The structure block format:
* http://minecraft.gamepedia.com/Structure_block_file_format
*/
STRUCTURE(new AbstractClipboardFormat("STRUCTURE", "structure", "nbt") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
inputStream = new BufferedInputStream(inputStream);
NBTInputStream nbtStream = new NBTInputStream(new BufferedInputStream(new GZIPInputStream(inputStream)));
return new StructureFormat(nbtStream);
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
outputStream = new BufferedOutputStream(outputStream);
OutputStream gzip;
if (outputStream instanceof PGZIPOutputStream || outputStream instanceof GZIPOutputStream) {
gzip = outputStream;
} else {
PGZIPOutputStream pigz = new PGZIPOutputStream(outputStream);
gzip = pigz;
}
NBTOutputStream nbtStream = new NBTOutputStream(new BufferedOutputStream(gzip));
return new StructureFormat(nbtStream);
}
@Override
public boolean isFormat(File file) {
return file.getName().endsWith(".nbt");
}
@Override
public String getExtension() {
return "nbt";
}
}),
/**
* Isometric PNG writer
*/
PNG(new AbstractClipboardFormat("PNG", "png", "image") {
@Override
public ClipboardReader getReader(InputStream inputStream) throws IOException {
return null;
}
@Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
return new PNGWriter(new BufferedOutputStream(outputStream));
}
@Override
public boolean isFormat(File file) {
return file.getName().endsWith(".png");
}
@Override
public String getExtension() {
return "png";
}
}),
;
public static final ClipboardFormat[] values;
private static final Map<String, ClipboardFormat> aliasMap;
static {
aliasMap = new ConcurrentHashMap<>(8, 0.9f, 1);
for (ClipboardFormat emum : ClipboardFormat.values()) {
for (String alias : emum.getAliases()) {
aliasMap.put(alias, emum);
}
}
values = values();
}
private IClipboardFormat format;
ClipboardFormat() {
}
ClipboardFormat(IClipboardFormat format) {
this.format = format;
}
/** /**
* Returns the name of this format. * Returns the name of this format.
* *
* @return The name of the format * @return The name of the format
*/ */
public String getName() { String getName();
return name();
} /**
* Get a set of aliases.
*
* @return a set of aliases
*/
Set<String> getAliases();
/**
* Create a reader.
*
* @param inputStream the input stream
* @return a reader
* @throws IOException thrown on I/O error
*/
ClipboardReader getReader(InputStream inputStream) throws IOException;
/**
* Create a writer.
*
* @param outputStream the output stream
* @return a writer
* @throws IOException thrown on I/O error
*/
ClipboardWriter getWriter(OutputStream outputStream) throws IOException;
/**
* Return whether the given file is of this format.
*
* @param file the file
* @return true if the given file is of this format
*/
boolean isFormat(File file);
/** /**
* Get the file extension this format primarily uses. * Get the file extension this format primarily uses.
* *
* @return The primary file extension * @return The primary file extension
*/ */
public String getPrimaryFileExtension() { String getPrimaryFileExtension();
return getExtension();
}
/** /**
* Get the file extensions this format is commonly known to use. This should * Get the file extensions this format is commonly known to use. This should
@ -295,12 +104,43 @@ public enum ClipboardFormat {
* *
* @return The file extensions this format might be known by * @return The file extensions this format might be known by
*/ */
public Set<String> getFileExtensions() { Set<String> getFileExtensions();
return Collections.singleton(getPrimaryFileExtension());
/**
* Set the player's clipboard
* @param player
* @param uri
* @param in
* @return the held clipboard
* @throws IOException
*/
default ClipboardHolder hold(Player player, URI uri, InputStream in) throws IOException {
checkNotNull(player);
checkNotNull(uri);
checkNotNull(in);
final ClipboardReader reader = getReader(in);
final Clipboard clipboard;
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
session.setClipboard(null);
clipboard = reader.read(player.getUniqueId());
URIClipboardHolder holder = new URIClipboardHolder(uri, clipboard);
session.setClipboard(holder);
return holder;
}
default Schematic load(File file) throws IOException {
return load(new FileInputStream(file));
}
default Schematic load(InputStream stream) throws IOException {
return new Schematic(getReader(stream).read());
} }
public URL uploadPublic(final Clipboard clipboard, String category, String user) { default URL uploadPublic(final Clipboard clipboard, String category, String user) {
// summary // summary
// blocks // blocks
HashMap<String, Object> map = new HashMap<String, Object>(); HashMap<String, Object> map = new HashMap<String, Object>();
@ -319,167 +159,8 @@ public enum ClipboardFormat {
}); });
} }
public static MultiClipboardHolder loadAllFromInput(Actor player, String input, ClipboardFormat format, boolean message) throws IOException { default URL uploadAnonymous(final Clipboard clipboard) {
checkNotNull(player); return MainUtil.upload(null, null, getPrimaryFileExtension(), new RunnableVal<OutputStream>() {
checkNotNull(input);
WorldEdit worldEdit = WorldEdit.getInstance();
LocalConfiguration config = worldEdit.getConfiguration();
if (input.startsWith("url:")) {
if (!player.hasPermission("worldedit.schematic.load.web")) {
if (message) BBC.NO_PERM.send(player, "worldedit.schematic.load.web");
return null;
}
URL base = new URL(Settings.IMP.WEB.URL);
input = new URL(base, "uploads/" + input.substring(4) + ".schematic").toString();
}
if (input.startsWith("http")) {
if (!player.hasPermission("worldedit.schematic.load.asset")) {
if (message) BBC.NO_PERM.send(player, "worldedit.schematic.load.asset");
return null;
}
URL url = new URL(input);
URL webInterface = new URL(Settings.IMP.WEB.ASSETS);
if (!url.getHost().equalsIgnoreCase(webInterface.getHost())) {
if (message) BBC.WEB_UNAUTHORIZED.send(player, url);
return null;
}
MultiClipboardHolder clipboards = loadAllFromUrl(url);
return clipboards;
} else {
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(input).find() && !player.hasPermission("worldedit.schematic.load.other")) {
BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
return null;
}
File working = worldEdit.getWorkingDirectoryFile(config.saveDir);
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
File f;
if (input.startsWith("#")) {
String[] extensions;
if (format != null) {
extensions = format.getFileExtensions().toArray(new String[0]);
} else {
extensions = ClipboardFormats.getFileExtensionArray();
}
f = player.openFileOpenDialog(extensions);
if (f == null || !f.exists()) {
if (message) player.printError("Schematic " + input + " does not exist! (" + f + ")");
return null;
}
} else {
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(input).find() && !player.hasPermission("worldedit.schematic.load.other")) {
if (message) BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
return null;
}
if (format == null && input.matches(".*\\.[\\w].*")) {
String extension = input.substring(input.lastIndexOf('.') + 1, input.length());
format = ClipboardFormat.findByExtension(extension);
}
f = MainUtil.resolve(dir, input, format, true);
}
if (f == null || !f.exists()) {
if (!input.contains("../")) {
dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
f = MainUtil.resolve(dir, input, format, true);
}
}
if (f == null || !f.exists() || !MainUtil.isInSubDirectory(working, f)) {
if (message) player.printError("Schematic " + input + " does not exist! (" + ((f == null) ? false : f.exists()) + "|" + f + "|" + (f == null ? false : !MainUtil.isInSubDirectory(working, f)) + ")");
return null;
}
if (format == null && f.isFile()) {
format = ClipboardFormat.findByFile(f);
if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName());
return null;
}
}
if (!f.exists()) {
if (message) BBC.SCHEMATIC_NOT_FOUND.send(player, input);
return null;
}
if (!f.isDirectory()) {
ByteSource source = Files.asByteSource(f);
URI uri = f.toURI();
return new MultiClipboardHolder(uri, new LazyClipboardHolder(f.toURI(), source, format, null));
}
URIClipboardHolder[] clipboards = loadAllFromDirectory(f);
if (clipboards.length < 1) {
if (message) BBC.SCHEMATIC_NOT_FOUND.send(player, input);
return null;
}
return new MultiClipboardHolder(f.toURI(), clipboards);
}
}
public static URIClipboardHolder[] loadAllFromDirectory(File dir) {
HashSet<String> extensions = new HashSet<>(Arrays.asList(ClipboardFormats.getFileExtensionArray()));
File[] files = dir.listFiles(pathname -> {
String input = pathname.getName();
String extension = input.substring(input.lastIndexOf('.') + 1, input.length());
return (extensions.contains(extension.toLowerCase()));
});
LazyClipboardHolder[] clipboards = new LazyClipboardHolder[files.length];
for (int i = 0; i < files.length; i++) {
File file = files[i];
ByteSource source = Files.asByteSource(file);
ClipboardFormat format = ClipboardFormat.findByFile(file);
clipboards[i] = new LazyClipboardHolder(file.toURI(), source, format, null);
}
return clipboards;
}
public static MultiClipboardHolder loadAllFromUrl(URL url) throws IOException {
List<LazyClipboardHolder> clipboards = new ArrayList<>();
try (ReadableByteChannel rbc = Channels.newChannel(url.openStream())) {
try (InputStream in = Channels.newInputStream(rbc)) {
try (ZipInputStream zip = new ZipInputStream(in)) {
ZipEntry entry;
byte[] buffer = new byte[8192];
while ((entry = zip.getNextEntry()) != null) {
String filename = entry.getName();
String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
ClipboardFormat format = findByExtension(filename);
if (format != null) {
FastByteArrayOutputStream out = new FastByteArrayOutputStream();
int len = 0;
while ((len = zip.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
byte[] array = out.toByteArray();
ByteSource source = ByteSource.wrap(array);
LazyClipboardHolder clipboard = new LazyClipboardHolder(url.toURI(), source, format, null);
clipboards.add(clipboard);
}
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
LazyClipboardHolder[] arr = clipboards.toArray(new LazyClipboardHolder[clipboards.size()]);
try {
MultiClipboardHolder multi = new MultiClipboardHolder(url.toURI());
for (LazyClipboardHolder h : arr) multi.add(h);
return multi;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
private void write(OutputStream value, Clipboard clipboard) {
try {
try (PGZIPOutputStream gzip = new PGZIPOutputStream(value)) {
try (ClipboardWriter writer = format.getWriter(gzip)) {
writer.write(clipboard);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public URL uploadAnonymous(final Clipboard clipboard) {
return MainUtil.upload(null, null, format.getExtension(), new RunnableVal<OutputStream>() {
@Override @Override
public void run(OutputStream value) { public void run(OutputStream value) {
write(value, clipboard); write(value, clipboard);
@ -487,154 +168,15 @@ public enum ClipboardFormat {
}); });
} }
public IClipboardFormat getFormat() { default void write(OutputStream value, Clipboard clipboard) {
return format;
}
/**
* Get a set of aliases.
*
* @return a set of aliases
*/
public Set<String> getAliases() {
return format.getAliases();
}
/**
* Create a reader.
*
* @param inputStream the input stream
* @return a reader
* @throws IOException thrown on I/O error
*/
public ClipboardReader getReader(InputStream inputStream) throws IOException {
return format.getReader(inputStream);
}
/**
* Create a writer.
*
* @param outputStream the output stream
* @return a writer
* @throws IOException thrown on I/O error
*/
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
return format.getWriter(outputStream);
}
/**
* Set the player's clipboard
* @param player
* @param uri
* @param in
* @return the held clipboard
* @throws IOException
*/
public ClipboardHolder hold(Player player, URI uri, InputStream in) throws IOException {
checkNotNull(player);
checkNotNull(uri);
checkNotNull(in);
final ClipboardReader reader = getReader(in);
final Clipboard clipboard;
LocalSession session = WorldEdit.getInstance().getSessionManager().get(player);
session.setClipboard(null);
clipboard = reader.read(player.getUniqueId());
URIClipboardHolder holder = new URIClipboardHolder(uri, clipboard);
session.setClipboard(holder);
return holder;
}
public Schematic load(File file) throws IOException {
return load(new FileInputStream(file));
}
public Schematic load(InputStream stream) throws IOException {
return new Schematic(this.getReader(stream).read());
}
/**
* Get the file extension used
*
* @return file extension string
*/
public String getExtension() {
return format.getExtension();
}
/**
* Return whether the given file is of this format.
*
* @param file the file
* @return true if the given file is of this format
*/
public boolean isFormat(File file) {
return format.isFormat(file);
}
/**
* Find the clipboard format named by the given alias.
*
* @param alias the alias
* @return the format, otherwise null if none is matched
*/
@Nullable
public static ClipboardFormat findByAlias(String alias) {
checkNotNull(alias);
return aliasMap.get(alias.toLowerCase(Locale.ENGLISH).trim());
}
@Nullable
public static ClipboardFormat findByExtension(String extension) {
checkNotNull(extension);
extension = extension.toLowerCase();
for (ClipboardFormat format : values) {
if (format.getFileExtensions().contains(extension)) {
return format;
}
}
return null;
}
/**
* Detect the format given a file.
*
* @param file the file
* @return the format, otherwise null if one cannot be detected
*/
@Nullable
public static ClipboardFormat findByFile(File file) {
checkNotNull(file);
for (ClipboardFormat format : EnumSet.allOf(ClipboardFormat.class)) {
if (format.isFormat(file)) {
return format;
}
}
return null;
}
public static ClipboardFormat addFormat(IClipboardFormat instance) {
ClipboardFormat newEnum = ReflectionUtils.addEnum(ClipboardFormat.class, instance.getName());
newEnum.format = instance;
for (String alias : newEnum.getAliases()) {
aliasMap.put(alias, newEnum);
}
ArrayList<ClipboardFormat> newValues = new ArrayList<>(Arrays.asList(values));
newValues.add(newEnum);
ClipboardFormat[] newValuesArray = newValues.toArray(new ClipboardFormat[newValues.size()]);
try { try {
ReflectionUtils.setFailsafeFieldValue(ClipboardFormat.class.getDeclaredField("values"), null, newValuesArray); try (PGZIPOutputStream gzip = new PGZIPOutputStream(value)) {
} catch (NoSuchFieldException e) { try (ClipboardWriter writer = getWriter(gzip)) {
e.printStackTrace(); writer.write(clipboard);
} catch (IllegalAccessException e) { }
}
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return newEnum;
} }
} }

View File

@ -19,17 +19,77 @@
package com.sk89q.worldedit.extent.clipboard.io; package com.sk89q.worldedit.extent.clipboard.io;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.clipboard.LazyClipboardHolder;
import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
import com.boydti.fawe.object.clipboard.URIClipboardHolder;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.util.MainUtil;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import com.google.common.io.ByteSource;
import com.google.common.io.Files;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File;
import java.util.*;
import static com.google.common.base.Preconditions.checkNotNull;
public class ClipboardFormats { public class ClipboardFormats {
private static final Map<String, ClipboardFormat> aliasMap = new HashMap<>();
private static final Multimap<String, ClipboardFormat> fileExtensionMap = HashMultimap.create();
private static final List<ClipboardFormat> registeredFormats = new ArrayList<>();
public static void registerClipboardFormat(ClipboardFormat format) {
checkNotNull(format);
for (String key : format.getAliases()) {
String lowKey = key.toLowerCase(Locale.ENGLISH);
ClipboardFormat old = aliasMap.put(lowKey, format);
if (old != null) {
aliasMap.put(lowKey, old);
WorldEdit.logger.warning(format.getClass().getName() + " cannot override existing alias '" + lowKey + "' used by " + old.getClass().getName());
}
}
for (String ext : format.getFileExtensions()) {
String lowExt = ext.toLowerCase(Locale.ENGLISH);
fileExtensionMap.put(lowExt, format);
}
registeredFormats.add(format);
}
static {
for (BuiltInClipboardFormat format : BuiltInClipboardFormat.values()) {
registerClipboardFormat(format);
}
}
/** /**
* Find the clipboard format named by the given alias. * Find the clipboard format named by the given alias.
* *
@ -39,7 +99,8 @@ public class ClipboardFormats {
*/ */
@Nullable @Nullable
public static ClipboardFormat findByAlias(String alias) { public static ClipboardFormat findByAlias(String alias) {
return ClipboardFormat.findByAlias(alias); checkNotNull(alias);
return aliasMap.get(alias.toLowerCase(Locale.ENGLISH).trim());
} }
/** /**
@ -53,7 +114,7 @@ public class ClipboardFormats {
public static ClipboardFormat findByFile(File file) { public static ClipboardFormat findByFile(File file) {
checkNotNull(file); checkNotNull(file);
for (ClipboardFormat format : ClipboardFormat.values) { for (ClipboardFormat format : registeredFormats) {
if (format.isFormat(file)) { if (format.isFormat(file)) {
return format; return format;
} }
@ -62,21 +123,35 @@ public class ClipboardFormats {
return null; return null;
} }
/**
* Detect the format using the given extension
* @param string
* the extension
* @return the format, otherwise null if one cannot be detected
*/
@Nullable
public static ClipboardFormat findByExtension(String extension) {
checkNotNull(extension);
Collection<Entry<String, ClipboardFormat>> entries = getFileExtensionMap().entries();
for(Map.Entry<String, ClipboardFormat> entry : entries) {
if(entry.getKey().equalsIgnoreCase(extension)) {
return entry.getValue();
}
}
return null;
}
/** /**
* @return a multimap from a file extension to the potential matching formats. * @return a multimap from a file extension to the potential matching formats.
*/ */
public static Multimap<String, ClipboardFormat> getFileExtensionMap() { public static Multimap<String, ClipboardFormat> getFileExtensionMap() {
HashMultimap<String, ClipboardFormat> map = HashMultimap.create(); return Multimaps.unmodifiableMultimap(fileExtensionMap);
for (ClipboardFormat format : ClipboardFormat.values) {
for (String ext : format.getFileExtensions()) {
map.put(ext, format);
}
}
return map;
} }
public static Collection<ClipboardFormat> getAll() { public static Collection<ClipboardFormat> getAll() {
return Arrays.asList(ClipboardFormat.values); return Collections.unmodifiableCollection(registeredFormats);
} }
/** /**
@ -84,13 +159,156 @@ public class ClipboardFormats {
* It is not in SchematicCommands because it may rely on internal register calls. * It is not in SchematicCommands because it may rely on internal register calls.
*/ */
public static String[] getFileExtensionArray() { public static String[] getFileExtensionArray() {
List<String> exts = new ArrayList<>(); return fileExtensionMap.keySet().toArray(new String[fileExtensionMap.keySet().size()]);
HashMultimap<String, ClipboardFormat> map = HashMultimap.create();
for (ClipboardFormat format : ClipboardFormat.values) {
exts.addAll(format.getFileExtensions());
}
return exts.toArray(new String[exts.size()]);
} }
private ClipboardFormats() {} private ClipboardFormats() {
}
public static MultiClipboardHolder loadAllFromInput(Actor player, String input, ClipboardFormat format, boolean message) throws IOException {
checkNotNull(player);
checkNotNull(input);
WorldEdit worldEdit = WorldEdit.getInstance();
LocalConfiguration config = worldEdit.getConfiguration();
if (input.startsWith("url:")) {
if (!player.hasPermission("worldedit.schematic.load.web")) {
if (message) BBC.NO_PERM.send(player, "worldedit.schematic.load.web");
return null;
}
URL base = new URL(Settings.IMP.WEB.URL);
input = new URL(base, "uploads/" + input.substring(4) + ".schematic").toString();
}
if (input.startsWith("http")) {
if (!player.hasPermission("worldedit.schematic.load.asset")) {
if (message) BBC.NO_PERM.send(player, "worldedit.schematic.load.asset");
return null;
}
URL url = new URL(input);
URL webInterface = new URL(Settings.IMP.WEB.ASSETS);
if (!url.getHost().equalsIgnoreCase(webInterface.getHost())) {
if (message) BBC.WEB_UNAUTHORIZED.send(player, url);
return null;
}
MultiClipboardHolder clipboards = loadAllFromUrl(url);
return clipboards;
} else {
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(input).find() && !player.hasPermission("worldedit.schematic.load.other")) {
BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
return null;
}
File working = worldEdit.getWorkingDirectoryFile(config.saveDir);
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
File f;
if (input.startsWith("#")) {
String[] extensions;
if (format != null) {
extensions = format.getFileExtensions().toArray(new String[0]);
} else {
extensions = ClipboardFormats.getFileExtensionArray();
}
f = player.openFileOpenDialog(extensions);
if (f == null || !f.exists()) {
if (message) player.printError("Schematic " + input + " does not exist! (" + f + ")");
return null;
}
} else {
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(input).find() && !player.hasPermission("worldedit.schematic.load.other")) {
if (message) BBC.NO_PERM.send(player, "worldedit.schematic.load.other");
return null;
}
if (format == null && input.matches(".*\\.[\\w].*")) {
String extension = input.substring(input.lastIndexOf('.') + 1, input.length());
format = findByExtension(extension);
}
f = MainUtil.resolve(dir, input, format, true);
}
if (f == null || !f.exists()) {
if (!input.contains("../")) {
dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
f = MainUtil.resolve(dir, input, format, true);
}
}
if (f == null || !f.exists() || !MainUtil.isInSubDirectory(working, f)) {
if (message) player.printError("Schematic " + input + " does not exist! (" + ((f == null) ? false : f.exists()) + "|" + f + "|" + (f == null ? false : !MainUtil.isInSubDirectory(working, f)) + ")");
return null;
}
if (format == null && f.isFile()) {
format = findByFile(f);
if (format == null) {
BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName());
return null;
}
}
if (!f.exists()) {
if (message) BBC.SCHEMATIC_NOT_FOUND.send(player, input);
return null;
}
if (!f.isDirectory()) {
ByteSource source = Files.asByteSource(f);
URI uri = f.toURI();
return new MultiClipboardHolder(uri, new LazyClipboardHolder(f.toURI(), source, format, null));
}
URIClipboardHolder[] clipboards = loadAllFromDirectory(f);
if (clipboards.length < 1) {
if (message) BBC.SCHEMATIC_NOT_FOUND.send(player, input);
return null;
}
return new MultiClipboardHolder(f.toURI(), clipboards);
}
}
public static URIClipboardHolder[] loadAllFromDirectory(File dir) {
HashSet<String> extensions = new HashSet<>(Arrays.asList(ClipboardFormats.getFileExtensionArray()));
File[] files = dir.listFiles(pathname -> {
String input = pathname.getName();
String extension = input.substring(input.lastIndexOf('.') + 1, input.length());
return (extensions.contains(extension.toLowerCase()));
});
LazyClipboardHolder[] clipboards = new LazyClipboardHolder[files.length];
for (int i = 0; i < files.length; i++) {
File file = files[i];
ByteSource source = Files.asByteSource(file);
ClipboardFormat format = findByFile(file);
clipboards[i] = new LazyClipboardHolder(file.toURI(), source, format, null);
}
return clipboards;
}
public static MultiClipboardHolder loadAllFromUrl(URL url) throws IOException {
List<LazyClipboardHolder> clipboards = new ArrayList<>();
try (ReadableByteChannel rbc = Channels.newChannel(url.openStream())) {
try (InputStream in = Channels.newInputStream(rbc)) {
try (ZipInputStream zip = new ZipInputStream(in)) {
ZipEntry entry;
byte[] buffer = new byte[8192];
while ((entry = zip.getNextEntry()) != null) {
String filename = entry.getName();
String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
ClipboardFormat format = findByExtension(filename);
if (format != null) {
FastByteArrayOutputStream out = new FastByteArrayOutputStream();
int len = 0;
while ((len = zip.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
byte[] array = out.toByteArray();
ByteSource source = ByteSource.wrap(array);
LazyClipboardHolder clipboard = new LazyClipboardHolder(url.toURI(), source, format, null);
clipboards.add(clipboard);
}
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
LazyClipboardHolder[] arr = clipboards.toArray(new LazyClipboardHolder[clipboards.size()]);
try {
MultiClipboardHolder multi = new MultiClipboardHolder(url.toURI());
for (LazyClipboardHolder h : arr) multi.add(h);
return multi;
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
} }

View File

@ -1,335 +1,330 @@
/*
* 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.extent.transform; package com.sk89q.worldedit.extent.transform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.object.extent.ResettableExtent;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.google.common.collect.Sets;
import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.helper.MCDirections;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.registry.state.AbstractProperty;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.BooleanProperty;
import com.sk89q.worldedit.registry.state.DirectionalProperty; 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;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.biome.BaseBiome; 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.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
/** /**
* Transforms blocks themselves (but not their position) according to a * Transforms blocks themselves (but not their position) according to a
* given transform. * given transform.
*/ */
public class BlockTransformExtent extends ResettableExtent { public class BlockTransformExtent extends ResettableExtent {
private Transform transform; private Transform transform;
private Transform transformInverse;
private int[] BLOCK_ROTATION_BITMASK;
private int[][] BLOCK_TRANSFORM;
private int[][] BLOCK_TRANSFORM_INVERSE;
private int[] ALL = new int[0];
public BlockTransformExtent(Extent parent) { public BlockTransformExtent(Extent parent) {
this(parent, new AffineTransform()); this(parent, new AffineTransform());
} }
public BlockTransformExtent(Extent parent, Transform transform) { /**
super(parent); * Create a new instance.
*
* @param extent the extent
*/
public BlockTransformExtent(Extent extent, Transform transform) {
super(extent);
checkNotNull(transform);
this.transform = transform; this.transform = transform;
this.transformInverse = this.transform.inverse();
cache();
} }
private List<Direction> getDirections(AbstractProperty property) { /**
if (property instanceof DirectionalProperty) { * Get the transform.
DirectionalProperty directional = (DirectionalProperty) property; *
directional.getValues(); * @return the transform
} else { */
switch (property.getKey()) { public Transform getTransform() {
case HALF: return transform;
case ROTATION:
case AXIS:
case FACING:
case SHAPE:
case NORTH:
case EAST:
case SOUTH:
case WEST:
}
}
return null;
} }
// @Override
// public BlockState getBlock(BlockVector3 position) {
// return transformBlock(super.getBlock(position), false);
// }
//
// @Override
// public BaseBlock getFullBlock(BlockVector3 position) {
// return transformBlock(super.getFullBlock(position), false);
// }
// @Override /**
// public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { * Set the transform
// return super.setBlock(location, transformBlock(block, true)); * @param affine
// } */
public void setTransform(Transform affine) {
this.transform = affine;
}
// /** /**
// * Transform the given block using the given transform. * Transform a block without making a copy.
// * *
// * <p>The provided block is modified.</p> * @param block the block
// * * @param reverse true to transform in the opposite direction
// * @param block the block * @return the same block
// * @param transform the transform */
// * @return the same block private <T extends BlockStateHolder<T>> T transformBlock(T block, boolean reverse) {
// */ return transform(block, reverse ? transform.inverse() : transform);
// public static <T extends BlockStateHolder> T transform(T block, Transform transform) { }
// return transform(block, transform, block);
// } @Override
public BlockState getLazyBlock(BlockVector3 position) {
return transformFast(super.getLazyBlock(position)).toImmutableState();
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return transformFast(super.getLazyBlock(x, y, z)).toImmutableState();
}
@Override
public BlockState getBlock(BlockVector3 position) {
return transformFast(super.getBlock(position)).toImmutableState();
}
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
return transformFast(super.getFullBlock(position).toImmutableState());
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return super.setBlock(x, y, z, transformFastInverse((BlockState)block));
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
return super.setBlock(location, transformFastInverse((BlockState)block));
}
private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west"); private static final Set<String> directionNames = Sets.newHashSet("north", "south", "east", "west");
// /** /**
// * Transform the given block using the given transform. * Transform the given block using the given transform.
// * *
// * @param block the block * <p>The provided block is <em>not</em> modified.</p>
// * @param transform the transform *
// * @param changedBlock the block to change * @param block the block
// * @return the changed block * @param transform the transform
// */ * @return the same block
// private static <T extends BlockStateHolder> T transform(T block, Transform transform, T changedBlock) { */
// checkNotNull(block); public static <B extends BlockStateHolder<B>> B transform(B block, Transform transform) {
// checkNotNull(transform); checkNotNull(block);
// checkNotNull(transform);
// List<? extends Property> properties = block.getBlockType().getProperties(); B result = block;
// List<? extends Property<?>> properties = block.getBlockType().getProperties();
// for (Property property : properties) {
// if (property instanceof DirectionalProperty) {
// Direction value = (Direction) block.getState(property);
// if (value != null) {
// Vector3 newValue = getNewStateValue((DirectionalProperty) property, transform, value.toVector());
// if (newValue != null) {
// changedBlock = (T) changedBlock.with(property, Direction.findClosest(newValue, Direction.Flag.ALL));
// }
// }
// }
// }
for (Property<?> property : properties) {
if (property instanceof DirectionalProperty) {
DirectionalProperty dirProp = (DirectionalProperty) property;
Direction value = (Direction) block.getState(property);
if (value != null) {
Vector3 newValue = getNewStateValue(dirProp.getValues(), transform, value.toVector());
if (newValue != null) {
result = result.with(dirProp, Direction.findClosest(newValue, Direction.Flag.ALL));
}
}
} else if (property instanceof EnumProperty) {
EnumProperty enumProp = (EnumProperty) property;
if (property.getName().equals("axis")) {
// We have an axis - this is something we can do the rotations to :sunglasses:
Direction value = null;
switch ((String) block.getState(property)) {
case "x":
value = Direction.EAST;
break;
case "y":
value = Direction.UP;
break;
case "z":
value = Direction.NORTH;
break;
}
if (value != null) {
Vector3 newValue = getNewStateValue(Direction.valuesOf(Direction.Flag.UPRIGHT | Direction.Flag.CARDINAL), transform, value.toVector());
if (newValue != null) {
String axis = null;
Direction newDir = Direction.findClosest(newValue, Direction.Flag.UPRIGHT | Direction.Flag.CARDINAL);
if (newDir == Direction.NORTH || newDir == Direction.SOUTH) {
axis = "z";
} else if (newDir == Direction.EAST || newDir == Direction.WEST) {
axis = "x";
} else if (newDir == Direction.UP || newDir == Direction.DOWN) {
axis = "y";
}
if (axis != null) {
result = result.with(enumProp, axis);
}
}
}
}
} else if (property instanceof IntegerProperty) {
IntegerProperty intProp = (IntegerProperty) property;
if (property.getName().equals("rotation")) {
if (intProp.getValues().size() == 16) {
Optional<Direction> direction = Direction.fromRotationIndex(block.getState(intProp));
int horizontalFlags = Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL;
if (direction.isPresent()) {
Vector3 vec = getNewStateValue(Direction.valuesOf(horizontalFlags), transform, direction.get().toVector());
if (vec != null) {
OptionalInt newRotation = Direction.findClosest(vec, horizontalFlags).toRotationIndex();
if (newRotation.isPresent()) {
result = result.with(intProp, newRotation.getAsInt());
}
}
}
}
}
}
}
List<String> directionalProperties = properties.stream()
.filter(prop -> prop instanceof BooleanProperty)
.filter(prop -> directionNames.contains(prop.getName()))
.filter(property -> (Boolean) block.getState(property))
.map(Property::getName)
.map(String::toUpperCase)
.map(Direction::valueOf)
.map(dir -> Direction.findClosest(transform.apply(dir.toVector()), Direction.Flag.CARDINAL))
.filter(Objects::nonNull)
.map(Direction::name)
.map(String::toLowerCase)
.collect(Collectors.toList());
if (directionalProperties.size() > 0) {
for (String directionName : directionNames) {
result = result.with(block.getBlockType().getProperty(directionName), directionalProperties.contains(directionName));
}
}
return result;
}
public final BaseBlock transformFast(BlockState block) {
BaseBlock transformed = transformBlock(block, false).toBaseBlock();
if (block.hasNbtData()) {
CompoundTag tag = block.getNbtData();
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
Direction direction = Direction.fromRotationIndex(rot).get();
if (direction != null) {
Vector3 applyAbsolute = transform.apply(direction.toVector());
Vector3 applyOrigin = transform.apply(Vector3.ZERO);
Vector3 newAbsolute = Vector3.at(applyAbsolute.getX() - applyOrigin.getX(), applyAbsolute.getY() - applyOrigin.getY(), applyAbsolute.getZ() - applyOrigin.getZ());
Direction newDirection = Direction.findClosest(newAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) newDirection.toRotationIndex().getAsInt()));
}
}
transformed.setNbtData(tag);
}
}
return transformed;
}
public final BaseBlock transformFastInverse(BlockState block) {
BaseBlock transformed = transformBlock(block, true).toBaseBlock();
if (block.hasNbtData()) {
CompoundTag tag = block.getNbtData();
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
Direction direction = Direction.fromRotationIndex(rot).get();
if (direction != null) {
Vector3 applyAbsolute = getTransform().inverse().apply(direction.toVector());
Vector3 applyOrigin = getTransform().inverse().apply(Vector3.ZERO);
Vector3 newAbsolute = Vector3.at(applyAbsolute.getX() - applyOrigin.getX(), applyAbsolute.getY() - applyOrigin.getY(), applyAbsolute.getZ() - applyOrigin.getZ());
Direction newDirection = Direction.findClosest(newAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) newDirection.toRotationIndex().getAsInt()));
}
}
}
transformed.setNbtData(tag);
}
return transformed;
}
/**
* Get the new value with the transformed direction.
*
* @param allowedStates the allowed states
* @param transform the transform
* @param oldDirection the old direction to transform
* @return a new state or null if none could be found
*/
@Nullable @Nullable
//<<<<<<< HEAD private static Vector3 getNewStateValue(List<Direction> allowedStates, Transform transform, Vector3 oldDirection) {
private static Integer getNewStateIndex(Transform transform, List<Direction> directions, int oldIndex) { Vector3 newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector3.ZERO)).normalize();
Direction oldDirection = directions.get(oldIndex); Vector3 newValue = null;
Vector3 oldVector = oldDirection.toVector(); double closest = -2;
Vector3 newVector = transform.apply(oldVector).subtract(transform.apply(Vector3.ZERO)).normalize();
int newIndex = oldIndex;
double closest = oldVector.normalize().dot(newVector);
//=======
// private static Vector3 getNewStateValue(DirectionalProperty state, Transform transform, Vector3 oldDirection) {
// Vector3 newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector3.ZERO)).normalize();
// Vector3 newValue = null;
// double closest = -2;
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
boolean found = false; boolean found = false;
for (int i = 0; i < directions.size(); i++) { for (Direction v : allowedStates) {
Direction v = directions.get(i); double dot = v.toVector().normalize().dot(newDirection);
double dot = v.toVector().normalize().dot(newVector); if (dot >= closest) {
if (dot > closest) {
closest = dot; closest = dot;
newIndex = i; newValue = v.toVector();
found = true; found = true;
} }
} }
if (found) { if (found) {
return newIndex; return newValue;
} else { } else {
return null; return null;
} }
} }
private void cache() {
BLOCK_ROTATION_BITMASK = new int[BlockTypes.size()];
BLOCK_TRANSFORM = new int[BlockTypes.size()][];
BLOCK_TRANSFORM_INVERSE = new int[BlockTypes.size()][];
outer:
for (int i = 0; i < BLOCK_TRANSFORM.length; i++) {
BLOCK_TRANSFORM[i] = ALL;
BLOCK_TRANSFORM_INVERSE[i] = ALL;
BlockTypes type = BlockTypes.get(i);
int bitMask = 0;
for (AbstractProperty property : (Collection<AbstractProperty>) type.getProperties()) {
Collection<Direction> directions = getDirections(property);
if (directions != null) {
BLOCK_TRANSFORM[i] = null;
BLOCK_TRANSFORM_INVERSE[i] = null;
bitMask |= property.getBitMask();
}
}
if (bitMask != 0) {
BLOCK_ROTATION_BITMASK[i] = bitMask;
}
}
}
@Override
public ResettableExtent setExtent(Extent extent) {
return super.setExtent(extent);
}
public Transform getTransform() {
return transform;
}
public void setTransform(Transform affine) {
this.transform = affine;
this.transformInverse = this.transform.inverse();
cache();
}
private final BlockState transform(BlockState state, int[][] transformArray, Transform transform) {
int typeId = state.getInternalBlockTypeId();
int[] arr = transformArray[typeId];
if (arr == ALL) return state;
if (arr == null) {
arr = transformArray[typeId] = new int[state.getBlockType().getMaxStateId() + 1];
Arrays.fill(arr, -1);
}
int mask = BLOCK_ROTATION_BITMASK[typeId];
int internalId = state.getInternalId();
int maskedId = internalId & mask;
int newMaskedId = arr[maskedId];
if (newMaskedId != -1) {
return BlockState.getFromInternalId(newMaskedId | (internalId & (~mask)));
}
newMaskedId = state.getInternalId();
BlockTypes type = state.getBlockType();
for (AbstractProperty property : (Collection<AbstractProperty>) type.getProperties()) {
List<Direction> directions = getDirections(property);
if (directions != null) {
Integer newIndex = getNewStateIndex(transform, directions, property.getIndex(state.getInternalId()));
if (newIndex != null) {
newMaskedId = property.modifyIndex(newMaskedId, newIndex);
}
}
}
arr[maskedId] = newMaskedId & mask;
return BlockState.getFromInternalId(newMaskedId);
}
public final BlockState transformFast(BlockState block) {
BlockState transformed = transform(block, BLOCK_TRANSFORM, transform);
if (block.hasNbtData()) {
CompoundTag tag = block.getNbtData();
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
Direction direction = MCDirections.fromRotation(rot);
if (direction != null) {
Vector3 applyAbsolute = transform.apply(direction.toVector());
Vector3 applyOrigin = transform.apply(Vector3.ZERO);
Direction newDirection = Direction.findClosest(applyAbsolute.subtract(applyOrigin), Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
}
}
transformed = new BaseBlock(transformed, tag);
}
}
return transformed;
}
public final BlockState transformFastInverse(BlockState block) {
BlockState transformed = transform(block, BLOCK_TRANSFORM_INVERSE, transformInverse);
if (block.hasNbtData()) {
CompoundTag tag = block.getNbtData();
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
Direction direction = MCDirections.fromRotation(rot);
if (direction != null) {
Vector3 applyAbsolute = transformInverse.apply(direction.toVector());
Vector3 applyOrigin = transformInverse.apply(Vector3.ZERO);
Direction newDirection = Direction.findClosest(applyAbsolute.subtract(applyOrigin), Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
if (newDirection != null) {
Map<String, Tag> values = ReflectionUtils.getMap(tag.getValue());
values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
}
}
}
transformed = new BaseBlock(transformed, tag);
}
return transformed;
}
@Override
public BlockState getLazyBlock(int x, int y, int z) {
return transformFast(super.getLazyBlock(x, y, z));
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return transformFast(super.getLazyBlock(position));
}
@Override
public BlockState getBlock(BlockVector3 position) {
return transformFast(super.getBlock(position));
}
@Override
public BaseBiome getBiome(BlockVector2 position) {
return super.getBiome(position);
}
@Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
return super.setBlock(x, y, z, transformFastInverse((BlockState) block));
}
@Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
return super.setBlock(location, transformFastInverse((BlockState) block));
}
} }

View File

@ -62,7 +62,7 @@ public class BlockMask extends AbstractExtentMask {
for (int i = 0; i < bitSets.length; i++) { for (int i = 0; i < bitSets.length; i++) {
if (bitSets[i] != null) { if (bitSets[i] != null) {
long[] set = bitSets[i]; long[] set = bitSets[i];
BlockTypes type = BlockTypes.get(i); BlockType type = BlockTypes.get(i);
if (set == ALL) { if (set == ALL) {
strings.add(type.getId()); strings.add(type.getId());
} else { } else {
@ -137,7 +137,7 @@ public class BlockMask extends AbstractExtentMask {
boolean single = true; boolean single = true;
int and = type.getInternalId(); int and = type.getInternalId();
List<? extends Property> properties = type.getProperties(); List<? extends Property> properties = type.getProperties();
for (AbstractProperty prop : (List<AbstractProperty>) type.getProperties()) { for (AbstractProperty prop : (List<AbstractProperty<?>>) type.getProperties()) {
List values = prop.getValues(); List values = prop.getValues();
int numSet = 0; int numSet = 0;
for (int i = 0; i < values.size(); i++) { for (int i = 0; i < values.size(); i++) {

View File

@ -90,15 +90,15 @@ public class BlockMaskBuilder {
charSequence.setString(input); charSequence.setString(input);
charSequence.setSubstring(0, propStart); charSequence.setSubstring(0, propStart);
BlockTypes type = null; BlockType type = null;
List<BlockTypes> blockTypeList = null; List<BlockType> blockTypeList = null;
if (StringMan.isAlphanumericUnd(charSequence)) { if (StringMan.isAlphanumericUnd(charSequence)) {
type = BlockTypes.parse(charSequence.toString()); type = BlockTypes.parse(charSequence.toString());
add(type); add(type);
} else { } else {
String regex = charSequence.toString(); String regex = charSequence.toString();
blockTypeList = new ArrayList<>(); blockTypeList = new ArrayList<>();
for (BlockTypes myType : BlockTypes.values) { for (BlockType myType : BlockTypes.values) {
if (myType.getId().matches(regex)) { if (myType.getId().matches(regex)) {
blockTypeList.add(myType); blockTypeList.add(myType);
add(myType); add(myType);
@ -135,14 +135,14 @@ public class BlockMaskBuilder {
filtered = filterRegexOrOperator(type, key, operator, charSequence); filtered = filterRegexOrOperator(type, key, operator, charSequence);
} }
else { else {
for (BlockTypes myType : blockTypeList) { for (BlockType myType : blockTypeList) {
filtered |= filterRegexOrOperator(myType, key, operator, charSequence); filtered |= filterRegexOrOperator(myType, key, operator, charSequence);
} }
} }
if (!filtered) { if (!filtered) {
String value = charSequence.toString(); String value = charSequence.toString();
final PropertyKey fKey = key; final PropertyKey fKey = key;
Collection<BlockTypes> types = type != null ? Collections.singleton(type) : blockTypeList; Collection<BlockType> types = type != null ? Collections.singleton(type) : blockTypeList;
throw new SuggestInputParseException("No value for " + input, input, () -> { throw new SuggestInputParseException("No value for " + input, input, () -> {
HashSet<String> values = new HashSet<>(); HashSet<String> values = new HashSet<>();
types.forEach(t -> { types.forEach(t -> {
@ -206,7 +206,7 @@ public class BlockMaskBuilder {
if (StringMan.isAlphanumericUnd(input)) { if (StringMan.isAlphanumericUnd(input)) {
add(BlockTypes.parse(input)); add(BlockTypes.parse(input));
} else { } else {
for (BlockTypes myType : BlockTypes.values) { for (BlockType myType : BlockTypes.values) {
if (myType.getId().matches(input)) { if (myType.getId().matches(input)) {
add(myType); add(myType);
} }
@ -225,7 +225,7 @@ public class BlockMaskBuilder {
return (states == BlockMask.ALL || FastBitSet.get(states, localI)); return (states == BlockMask.ALL || FastBitSet.get(states, localI));
} }
private void suggest(String input, String property, Collection<BlockTypes> finalTypes) throws InputParseException { private void suggest(String input, String property, Collection<BlockType> finalTypes) throws InputParseException {
throw new SuggestInputParseException(input + " does not have: " + property, input, () -> { throw new SuggestInputParseException(input + " does not have: " + property, input, () -> {
Set<PropertyKey> keys = new HashSet<>(); Set<PropertyKey> keys = new HashSet<>();
finalTypes.forEach(t -> t.getProperties().stream().forEach(p -> keys.add(p.getKey()))); finalTypes.forEach(t -> t.getProperties().stream().forEach(p -> keys.add(p.getKey())));
@ -346,7 +346,7 @@ public class BlockMaskBuilder {
bitSets[i] = null; bitSets[i] = null;
continue; continue;
} }
List<AbstractProperty> properties = (List<AbstractProperty>) type.getProperties(); List<AbstractProperty<?>> properties = (List<AbstractProperty<?>>) type.getProperties();
for (AbstractProperty prop : properties) { for (AbstractProperty prop : properties) {
List values = prop.getValues(); List values = prop.getValues();
for (int j = 0; j < values.size(); j++) { for (int j = 0; j < values.size(); j++) {
@ -425,7 +425,7 @@ public class BlockMaskBuilder {
if (!typePredicate.test(type)) { if (!typePredicate.test(type)) {
continue; continue;
} }
for (AbstractProperty prop : (List<AbstractProperty>) type.getProperties()) { for (AbstractProperty prop : (List<AbstractProperty<?>>) type.getProperties()) {
List values = prop.getValues(); List values = prop.getValues();
for (int j = 0; j < values.size(); j++) { for (int j = 0; j < values.size(); j++) {
int localI = j << prop.getBitOffset() >> BlockTypes.BIT_OFFSET; int localI = j << prop.getBitOffset() >> BlockTypes.BIT_OFFSET;
@ -533,7 +533,7 @@ public class BlockMaskBuilder {
} }
int set = 0; int set = 0;
int clear = 0; int clear = 0;
for (AbstractProperty prop : (List<AbstractProperty>) type.getProperties()) { for (AbstractProperty prop : (List<AbstractProperty<?>>) type.getProperties()) {
List values = prop.getValues(); List values = prop.getValues();
for (int j = 0; j < values.size(); j++) { for (int j = 0; j < values.size(); j++) {
int localI = j << prop.getBitOffset() >> BlockTypes.BIT_OFFSET; int localI = j << prop.getBitOffset() >> BlockTypes.BIT_OFFSET;

View File

@ -4,7 +4,7 @@ package com.sk89q.worldedit.function.mask;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -14,7 +14,7 @@ public class SolidBlockMask extends BlockTypeMask {
public static boolean[] getTypes() { public static boolean[] getTypes() {
boolean[] types = new boolean[BlockTypes.size()]; boolean[] types = new boolean[BlockTypes.size()];
for (BlockTypes type : BlockTypes.values) { for (BlockType type : BlockTypes.values) {
types[type.getInternalId()] = type.getMaterial().isSolid(); types[type.getInternalId()] = type.getMaterial().isSolid();
} }
return types; return types;

View File

@ -90,13 +90,8 @@ public class ForwardExtentCopy implements Operation {
* @param source the source extent * @param source the source extent
* @param region the region to copy * @param region the region to copy
* @param destination the destination extent * @param destination the destination extent
<<<<<<< HEAD
* @param to the destination position
* @see #ForwardExtentCopy(Extent, Region, Vector, Extent, Vector) the main constructor
=======
* @param to the destination position * @param to the destination position
* @see #ForwardExtentCopy(Extent, Region, BlockVector3, Extent, BlockVector3) the main constructor * @see #ForwardExtentCopy(Extent, Region, BlockVector3, Extent, BlockVector3) the main constructor
>>>>>>> 399e0ad5... Refactor vector system to be cleaner
*/ */
public ForwardExtentCopy(Extent source, Region region, Extent destination, BlockVector3 to) { public ForwardExtentCopy(Extent source, Region region, Extent destination, BlockVector3 to) {
this(source, region, region.getMinimumPoint(), destination, to); this(source, region, region.getMinimumPoint(), destination, to);

View File

@ -131,6 +131,7 @@ public class PasteBuilder {
if (ignoreAirBlocks) { if (ignoreAirBlocks) {
copy.setSourceMask(new ExistingBlockMask(clipboard)); copy.setSourceMask(new ExistingBlockMask(clipboard));
} }
System.out.println("PasteBuilder info: extent: " + extent.toString() + "; copy: " + copy + "; transform: " + transform);
return copy; return copy;
} }

View File

@ -22,8 +22,13 @@ package com.sk89q.worldedit.util;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import javax.annotation.Nullable; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import javax.annotation.Nullable;
/** /**
* A collection of cardinal, ordinal, and secondary-ordinal directions. * A collection of cardinal, ordinal, and secondary-ordinal directions.
@ -56,10 +61,7 @@ public enum Direction {
private final BlockVector3 blockVector; private final BlockVector3 blockVector;
private final int flags, left, right; private final int flags, left, right;
private static HashMap<String, Direction> map = new HashMap<>(); private static HashMap<String, Direction> map = new HashMap<>();
public static final Direction[] values = values();
public static final Direction[] cardinal = new Direction[]{ NORTH, EAST, SOUTH, WEST };
static { static {
for (Direction dir : Direction.values()) { for (Direction dir : Direction.values()) {
@ -68,7 +70,7 @@ public enum Direction {
} }
} }
private Direction(Vector3 vector, int flags, int left, int right) { Direction(Vector3 vector, int flags, int left, int right) {
this.direction = vector.normalize(); this.direction = vector.normalize();
this.blockVector = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ())); this.blockVector = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.flags = flags; this.flags = flags;
@ -81,11 +83,11 @@ public enum Direction {
} }
public Direction getLeft() { public Direction getLeft() {
return left != -1 ? values[left] : null; return left != -1 ? values()[left] : null;
} }
public Direction getRight() { public Direction getRight() {
return right != -1 ? values[right] : null; return right != -1 ? values()[right] : null;
} }
public double getX() { public double getX() {
@ -163,11 +165,6 @@ public enum Direction {
return direction; return direction;
} }
@Override
public String toString() {
return name().toLowerCase();
}
/** /**
* Get the vector. * Get the vector.
* *
@ -208,6 +205,110 @@ public enum Direction {
return closest; return closest;
} }
/**
* Gets all directions with the given flags.
*
* @param flags The flags
* @return The directions that fit the flags
*/
public static List<Direction> valuesOf(int flags) {
List<Direction> directions = new ArrayList<>();
for (Direction direction : values()) {
if ((~flags & direction.flags) == 0) {
directions.add(direction);
}
}
return directions;
}
/**
* Converts a rotation index into a Direction.
*
* <p>
* Rotation indexes are used in BlockStates, such as sign posts.
* </p>
*
* @param rotation The rotation index
* @return The direction, if applicable
*/
public static Optional<Direction> fromRotationIndex(int rotation) {
switch (rotation) {
case 0:
return Optional.of(SOUTH);
case 1:
return Optional.of(SOUTH_SOUTHWEST);
case 2:
return Optional.of(SOUTHWEST);
case 3:
return Optional.of(WEST_SOUTHWEST);
case 4:
return Optional.of(WEST);
case 5:
return Optional.of(WEST_NORTHWEST);
case 6:
return Optional.of(NORTHWEST);
case 7:
return Optional.of(NORTH_NORTHWEST);
case 8:
return Optional.of(NORTH);
case 9:
return Optional.of(NORTH_NORTHEAST);
case 10:
return Optional.of(NORTHEAST);
case 11:
return Optional.of(EAST_NORTHEAST);
case 12:
return Optional.of(EAST);
case 13:
return Optional.of(EAST_SOUTHEAST);
case 14:
return Optional.of(SOUTHEAST);
case 15:
return Optional.of(SOUTH_SOUTHEAST);
}
return Optional.empty();
}
public OptionalInt toRotationIndex() {
switch (this) {
case SOUTH:
return OptionalInt.of(0);
case SOUTH_SOUTHWEST:
return OptionalInt.of(1);
case SOUTHWEST:
return OptionalInt.of(2);
case WEST_SOUTHWEST:
return OptionalInt.of(3);
case WEST:
return OptionalInt.of(4);
case WEST_NORTHWEST:
return OptionalInt.of(5);
case NORTHWEST:
return OptionalInt.of(6);
case NORTH_NORTHWEST:
return OptionalInt.of(7);
case NORTH:
return OptionalInt.of(8);
case NORTH_NORTHEAST:
return OptionalInt.of(9);
case NORTHEAST:
return OptionalInt.of(10);
case EAST_NORTHEAST:
return OptionalInt.of(11);
case EAST:
return OptionalInt.of(12);
case EAST_SOUTHEAST:
return OptionalInt.of(13);
case SOUTHEAST:
return OptionalInt.of(14);
case SOUTH_SOUTHEAST:
return OptionalInt.of(15);
}
return OptionalInt.empty();
}
/** /**
* Flags to use with {@link #findClosest(Vector3, int)}. * Flags to use with {@link #findClosest(Vector3, int)}.
*/ */
@ -224,4 +325,3 @@ public enum Direction {
} }
} }

View File

@ -100,14 +100,20 @@ public class PropertiesConfiguration extends LocalConfiguration {
logFile = getString("log-file", logFile); logFile = getString("log-file", logFile);
logFormat = getString("log-format", logFormat); logFormat = getString("log-format", logFormat);
registerHelp = getBool("register-help", registerHelp); registerHelp = getBool("register-help", registerHelp);
wandItem = ItemTypes.parse(getString("wand-item", wandItem.getId())); wandItem = getString("wand-item", wandItem);
try {
wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId();
} catch (Throwable e) {}
superPickaxeDrop = getBool("super-pickaxe-drop-items", superPickaxeDrop); superPickaxeDrop = getBool("super-pickaxe-drop-items", superPickaxeDrop);
superPickaxeManyDrop = getBool("super-pickaxe-many-drop-items", superPickaxeManyDrop); superPickaxeManyDrop = getBool("super-pickaxe-many-drop-items", superPickaxeManyDrop);
noDoubleSlash = getBool("no-double-slash", noDoubleSlash); noDoubleSlash = getBool("no-double-slash", noDoubleSlash);
useInventory = getBool("use-inventory", useInventory); useInventory = getBool("use-inventory", useInventory);
useInventoryOverride = getBool("use-inventory-override", useInventoryOverride); useInventoryOverride = getBool("use-inventory-override", useInventoryOverride);
useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride); useInventoryCreativeOverride = getBool("use-inventory-creative-override", useInventoryCreativeOverride);
navigationWand = ItemTypes.parse(getString("navigation-wand.item", navigationWand.getId())); navigationWand = getString("nav-wand-item", navigationWand);
try {
navigationWand = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(navigationWand)).getId();
} catch (Throwable e) {}
navigationWandMaxDistance = getInt("nav-wand-distance", navigationWandMaxDistance); navigationWandMaxDistance = getInt("nav-wand-distance", navigationWandMaxDistance);
navigationUseGlass = getBool("nav-use-glass", navigationUseGlass); navigationUseGlass = getBool("nav-use-glass", navigationUseGlass);
scriptTimeout = getInt("scripting-timeout", scriptTimeout); scriptTimeout = getInt("scripting-timeout", scriptTimeout);

View File

@ -57,7 +57,7 @@ public class YAMLConfiguration extends LocalConfiguration {
} }
profile = config.getBoolean("debug", profile); profile = config.getBoolean("debug", profile);
wandItem = ItemTypes.parse(config.getString("wand-item", wandItem.getId())); wandItem = ItemTypes.parse(config.getString("wand-item", wandItem)).getId();
defaultChangeLimit = Math.max(-1, config.getInt( defaultChangeLimit = Math.max(-1, config.getInt(
"limits.max-blocks-changed.default", defaultChangeLimit)); "limits.max-blocks-changed.default", defaultChangeLimit));
@ -105,7 +105,7 @@ public class YAMLConfiguration extends LocalConfiguration {
useInventoryCreativeOverride = config.getBoolean("use-inventory.creative-mode-overrides", useInventoryCreativeOverride = config.getBoolean("use-inventory.creative-mode-overrides",
useInventoryCreativeOverride); useInventoryCreativeOverride);
navigationWand = ItemTypes.parse(config.getString("navigation-wand.item", navigationWand.getId())); navigationWand = ItemTypes.parse(config.getString("navigation-wand.item", navigationWand)).getId();
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance); navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
navigationUseGlass = config.getBoolean("navigation.use-glass", navigationUseGlass); navigationUseGlass = config.getBoolean("navigation.use-glass", navigationUseGlass);

View File

@ -93,7 +93,7 @@ public abstract class AbstractWorld implements World {
@Override @Override
public BlockState getLazyBlock(BlockVector3 position) { public BlockState getLazyBlock(BlockVector3 position) {
return new BaseBlock(getBlock(position)); return new BaseBlock(getBlock(position)).toImmutableState();
} }
@Override @Override

View File

@ -59,8 +59,8 @@ public interface SimpleWorld extends World {
} }
@Override @Override
default BlockState getFullBlock(BlockVector3 position) { default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position); return getLazyBlock(position).toBaseBlock();
} }
@Override @Override

View File

@ -34,9 +34,15 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
@ -48,7 +54,7 @@ import java.util.Objects;
* snapshot of blocks correctly, so, for example, the NBT data for a block * snapshot of blocks correctly, so, for example, the NBT data for a block
* may be missing.</p> * may be missing.</p>
*/ */
public class BaseBlock extends BlockState { public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
private final BlockState blockState; private final BlockState blockState;
@Nullable @Nullable
@ -69,11 +75,6 @@ public class BaseBlock extends BlockState {
// this(blockState, blockState.getNbtData()); // this(blockState, blockState.getNbtData());
// } // }
@Deprecated
public BaseBlock(BlockTypes id) {
this(id.getDefaultState());
}
/** /**
* Construct a block with the given type and default data. * Construct a block with the given type and default data.
* @deprecated Just use the BlockType.getDefaultState() * @deprecated Just use the BlockType.getDefaultState()
@ -101,7 +102,6 @@ public class BaseBlock extends BlockState {
* @param nbtData NBT data, which must be provided * @param nbtData NBT data, which must be provided
*/ */
public BaseBlock(BlockState state, CompoundTag nbtData) { public BaseBlock(BlockState state, CompoundTag nbtData) {
// super(state.getBlockType());
checkNotNull(nbtData); checkNotNull(nbtData);
this.blockState = state; this.blockState = state;
this.nbtData = nbtData; this.nbtData = nbtData;
@ -145,11 +145,6 @@ public class BaseBlock extends BlockState {
this(other.toImmutableState(), other.getNbtData()); this(other.toImmutableState(), other.getNbtData());
} }
@Override
public BlockState toFuzzy() {
return blockState;
}
@Override @Override
public String getNbtId() { public String getNbtId() {
CompoundTag nbtData = getNbtData(); CompoundTag nbtData = getNbtData();
@ -181,12 +176,15 @@ public class BaseBlock extends BlockState {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof BaseBlock)) { if (!(o instanceof BaseBlock)) {
if (!hasNbtData() && o instanceof BlockStateHolder) {
return Objects.equals(toImmutableState(), ((BlockStateHolder<?>) o).toImmutableState());
}
return false; return false;
} }
final BaseBlock otherBlock = (BaseBlock) o; final BaseBlock otherBlock = (BaseBlock) o;
return this.equals(otherBlock) && Objects.equals(getNbtData(), otherBlock.getNbtData()); return this.blockState.equalsFuzzy(otherBlock.blockState) && Objects.equals(getNbtData(), otherBlock.getNbtData());
} }
@Override @Override
@ -205,7 +203,7 @@ public class BaseBlock extends BlockState {
} }
@Override @Override
public BlockTypes getBlockType() { public BlockType getBlockType() {
return blockState.getBlockType(); return blockState.getBlockType();
} }
@ -244,4 +242,65 @@ public class BaseBlock extends BlockState {
} }
} }
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean hasNbtData() {
return this.nbtData != null;
}
@Override
public BlockStateHolder withPropertyId(int propertyId) {
return getBlockType().withPropertyId(propertyId);
}
@Override
public int getInternalBlockTypeId() {
return toImmutableState().getInternalBlockTypeId();
}
@Override
public int getInternalPropertiesId() {
return toImmutableState().getInternalPropertiesId();
}
@Override
public Mask toMask(Extent extent) {
return new SingleBlockStateMask(extent, toImmutableState());
}
@Override
public <V> BaseBlock with(Property<V> property, V value) {
return toImmutableState().with(property, value).toBaseBlock();
}
@Override
public <V> BlockStateHolder with(PropertyKey property, V value) {
return toImmutableState().with(property, value);
}
@Override
public <V> V getState(Property<V> property) {
return toImmutableState().getState(property);
}
@Override
public <V> V getState(PropertyKey property) {
return toImmutableState().getState(property);
}
@Override
public Map<Property<?>, Object> getStates() {
return toImmutableState().getStates();
}
@Override
public boolean equalsFuzzy(BlockStateHolder o) {
return toImmutableState().equalsFuzzy(o);
}
} }

View File

@ -39,6 +39,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*; import java.util.*;
@ -49,13 +50,26 @@ import java.util.stream.Stream;
* An immutable class that represents the state a block can be in. * An immutable class that represents the state a block can be in.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public abstract class BlockState implements BlockStateHolder<BlockState> { public class BlockState implements BlockStateHolder<BlockState> {
private final BlockType blockType;
private BaseBlock emptyBaseBlock;
BlockState(BlockType blockType) {
this.blockType = blockType;
this.emptyBaseBlock = new BaseBlock(this);
}
BlockState(BlockType blockType, BaseBlock baseBlock){
this.blockType = blockType;
this.emptyBaseBlock = baseBlock;
}
/** /**
* Returns a temporary BlockState for a given internal id * Returns a temporary BlockState for a given internal id
* @param combinedId * @param combinedId
* @deprecated magic number * @deprecated magic number
* @return BlockState * @return BlockState
*/ */
@Deprecated @Deprecated
public static BlockState getFromInternalId(int combinedId) throws InputParseException { public static BlockState getFromInternalId(int combinedId) throws InputParseException {
return BlockTypes.getFromStateId(combinedId).withStateId(combinedId); return BlockTypes.getFromStateId(combinedId).withStateId(combinedId);
@ -85,17 +99,6 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
public static BlockState get(@Nullable BlockType type, String state) throws InputParseException { public static BlockState get(@Nullable BlockType type, String state) throws InputParseException {
return get(type, state, null); return get(type, state, null);
} }
// private BlockTypes blockType;
// private BaseBlock emptyBaseBlock;
// Neighbouring state table.
private Table<Property<?>, Object, BlockState> states;
// protected BlockState(BlockTypes blockType) {
//// protected BlockState() {
// this.blockType = blockType;
// this.emptyBaseBlock = new BaseBlock(this);
// }
/** /**
* Returns a temporary BlockState for a given type and string * Returns a temporary BlockState for a given type and string
@ -265,7 +268,7 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
@Override @Override
public <V> BlockState with(final Property<V> property, final V value) { public <V> BlockState with(final Property<V> property, final V value) {
try { try {
BlockTypes type = getBlockType(); BlockType type = getBlockType();
int newState = ((AbstractProperty) property).modify(this.getInternalId(), value); int newState = ((AbstractProperty) property).modify(this.getInternalId(), value);
return newState != this.getInternalId() ? type.withStateId(newState) : this; return newState != this.getInternalId() ? type.withStateId(newState) : this;
} catch (ClassCastException e) { } catch (ClassCastException e) {
@ -276,7 +279,7 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
@Override @Override
public <V> BlockState with(final PropertyKey property, final V value) { public <V> BlockState with(final PropertyKey property, final V value) {
try { try {
BlockTypes type = getBlockType(); BlockType type = getBlockType();
int newState = ((AbstractProperty) type.getProperty(property)).modify(this.getInternalId(), value); int newState = ((AbstractProperty) type.getProperty(property)).modify(this.getInternalId(), value);
return newState != this.getInternalId() ? type.withStateId(newState) : this; return newState != this.getInternalId() ? type.withStateId(newState) : this;
} catch (ClassCastException e) { } catch (ClassCastException e) {
@ -309,13 +312,10 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
return (Map<Property<?>, Object>) map; return (Map<Property<?>, Object>) map;
} }
// @Override @Override
// public BaseBlock toBaseBlock() { public BaseBlock toBaseBlock() {
//// if (this.fuzzy) { return this.emptyBaseBlock;
//// throw new IllegalArgumentException("Can't create a BaseBlock from a fuzzy BlockState!"); }
//// }
// return this.emptyBaseBlock;
// }
@Override @Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) { public BaseBlock toBaseBlock(CompoundTag compoundTag) {
@ -325,10 +325,10 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
return new BaseBlock(this, compoundTag); return new BaseBlock(this, compoundTag);
} }
// @Override @Override
// public BlockTypes getBlockType() { public BlockType getBlockType() {
// return this.blockType; return this.blockType;
// } }
/** /**
* Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense * Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense
@ -364,4 +364,20 @@ public abstract class BlockState implements BlockStateHolder<BlockState> {
public String toString() { public String toString() {
return getAsString(); return getAsString();
} }
@Override
public int getInternalId() {
return blockType.getInternalId();
}
@Override
public BlockMaterial getMaterial() {
return blockType.getMaterial();
}
@Override
public int getOrdinal() {
//?
return 0;
}
} }

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