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

@ -190,7 +190,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit
@Override
public BlockMaterial getMaterial(BlockState state) {
BlockTypes type = state.getBlockType();
BlockType type = state.getBlockType();
IBlockData bs = ((CraftBlockData) Bukkit.createBlockData(state.getAsString())).getState();
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) {
NBTTagCompound tag = new NBTTagCompound();
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;
int xx = bx + x;
BlockTypes type = BlockTypes.getFromStateId(combined);
BlockType type = BlockTypes.getFromStateId(combined);
if (type == BlockTypes.__RESERVED__) continue;
switch (type) {
case AIR:
case CAVE_AIR:
case VOID_AIR:
switch (type.getResource().toUpperCase()) {
case "AIR":
case "CAVE_AIR":
case "VOID_AIR":
if (!place) {
mutableLoc.setX(xx);
mutableLoc.setY(yy);
@ -277,12 +277,12 @@ public class BukkitChunk_All extends IntFaweChunk<Chunk, BukkitQueue_All> {
for (;index < 4096; index++) {
int j = place ? index : 4095 - index;
int combined = newArray[j];
BlockTypes type = BlockTypes.getFromStateId(combined);
BlockType type = BlockTypes.getFromStateId(combined);
if (type == BlockTypes.__RESERVED__) continue;
switch (type) {
case AIR:
case CAVE_AIR:
case VOID_AIR:
switch (type.getResource().toUpperCase()) {
case "AIR":
case "CAVE_AIR":
case "VOID_AIR":
if (!place) {
int x = cacheX[j];
int z = cacheZ[j];

View File

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

View File

@ -22,6 +22,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.function.Supplier;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.*;
import org.bukkit.block.Biome;
@ -272,7 +273,7 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue
public int getHighestBlockYAt(int x, int z) {
for (int y = getMaxHeight() - 1; y >= 0; y--) {
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;
}
return 0;

View File

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

View File

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

View File

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

View File

@ -478,10 +478,10 @@ public class BukkitWorld extends AbstractWorld {
}
@Override
public com.sk89q.worldedit.world.block.BlockState getFullBlock(BlockVector3 position) {
public BaseBlock getFullBlock(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position));
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)).toBaseBlock();
} else {
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.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
@ -52,17 +53,17 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
@Override
public ItemType asItemType(Material material) {
try {
return ItemTypes.values[itemTypes[material.ordinal()]];
return ItemTypes.get(itemTypes[material.ordinal()]);
} catch (NullPointerException e) {
if (init()) return asItemType(material);
return ItemTypes.values[itemTypes[material.ordinal()]];
return ItemTypes.get(itemTypes[material.ordinal()]);
}
}
@Override
public BlockTypes adapt(Material material) {
public BlockType adapt(Material material) {
try {
return BlockTypes.values[blockTypes[material.ordinal()]];
return BlockTypes.values[blockTypes[material.ordinal()]];
} catch (NullPointerException e) {
if (init()) return adapt(material);
throw e;
@ -80,7 +81,7 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
try {
checkNotNull(blockData);
Material material = blockData.getMaterial();
BlockTypes type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]);
BlockType type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]);
List<? extends Property> propList = type.getProperties();
if (propList.size() == 0) return type.getDefaultState();
String properties = blockData.getAsString();

View File

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

View File

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