Permalink
Browse files

Setup a legacy mapper system. The file does not exist yet.

  • Loading branch information...
me4502 committed Jul 1, 2018
1 parent 45f7b53 commit 43e8a99133ff502dbd355ef9c5753352a1194c4d
Showing with 497 additions and 659 deletions.
  1. +7 −8 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
  2. +5 −5 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
  3. +7 −6 worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
  4. +2 −0 worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java
  5. +15 −20 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseBlock.java
  6. +6 −2 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseItem.java
  7. +182 −240 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockData.java
  8. +0 −19 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BlockType.java
  9. +18 −82 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/ClothColor.java
  10. +5 −0 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockState.java
  11. +7 −0 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockStateHolder.java
  12. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockType.java
  13. +4 −4 worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/ItemType.java
  14. +6 −3 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java
  15. +38 −30 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java
  16. +1 −5 worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java
  17. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java
  18. +3 −3 worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java
  19. +3 −2 worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java
  20. +0 −10 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java
  21. +7 −46 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java
  22. +0 −11 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java
  23. +2 −50 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java
  24. +0 −11 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java
  25. +0 −9 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java
  26. +152 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java
  27. +13 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/state/SimpleState.java
  28. +7 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/state/State.java
  29. +0 −76 worldedit-core/src/test/java/com/sk89q/worldedit/blocks/BlockDataTest.java
  30. +0 −10 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java
  31. +3 −4 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java
@@ -31,16 +31,14 @@
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.AbstractWorld;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.bukkit.Effect;
import org.bukkit.TreeType;
import org.bukkit.World;
@@ -361,10 +359,7 @@ public void simulateBlockMine(Vector pt) {
@Override
public com.sk89q.worldedit.blocks.type.BlockState getBlock(Vector position) {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
BlockType blockType = BlockTypes.getBlockType(
BundledBlockData.getInstance().fromLegacyId(bukkitBlock.getTypeId())
);
return blockType.getDefaultState(); // TODO Data
return LegacyMapper.getInstance().getBlockFromLegacy(bukkitBlock.getTypeId(), bukkitBlock.getData());
}
@Override
@@ -374,7 +369,11 @@ public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyA
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
} else {
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
return bukkitBlock.setTypeIdAndData(block.getBlockType().getLegacyId(), (byte) 0, notifyAndLight); // TODO Data
int[] datas = LegacyMapper.getInstance().getLegacyFromBlock(block.toImmutableState());
if (datas == null) {
throw new WorldEditException("Unknown block"){}; // TODO Remove.
}
return bukkitBlock.setTypeIdAndData(datas[0], (byte) datas[1], notifyAndLight);
}
}
@@ -19,13 +19,12 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Proxy class to catch calls to set blocks.
@@ -41,7 +40,7 @@ public EditSessionBlockChangeDelegate(EditSession editSession) {
@Override
public boolean setRawTypeId(int x, int y, int z, int typeId) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
return editSession.setBlock(new Vector(x, y, z), LegacyMapper.getInstance().getBlockFromLegacy(typeId));
} catch (MaxChangedBlocksException ex) {
return false;
}
@@ -50,7 +49,7 @@ public boolean setRawTypeId(int x, int y, int z, int typeId) {
@Override
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
return editSession.setBlock(new Vector(x, y, z), LegacyMapper.getInstance().getBlockFromLegacy(typeId, data));
} catch (MaxChangedBlocksException ex) {
return false;
}
@@ -68,7 +67,8 @@ public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
@Override
public int getTypeId(int x, int y, int z) {
return editSession.getBlock(new Vector(x, y, z)).getBlockType().getLegacyId();
int[] datas = LegacyMapper.getInstance().getLegacyFromBlock(editSession.getBlock(new Vector(x, y, z)));
return datas[0];
}
@Override
@@ -108,6 +108,7 @@
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.ArrayList;
import java.util.Collections;
@@ -440,10 +441,9 @@ public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean naturalOnly) {
for (int y = maxY; y >= minY; --y) {
Vector pt = new Vector(x, y, z);
BaseBlock block = getLazyBlock(pt);
int id = block.getId();
int data = block.getData();
if (naturalOnly ? BlockType.isNaturalTerrainBlock(id, data) : !BlockType.canPassThrough(id, data)) {
BlockState block = getBlock(pt);
int[] datas = LegacyMapper.getInstance().getLegacyFromBlock(block);
if (naturalOnly ? BlockType.isNaturalTerrainBlock(datas[0], datas[1]) : !BlockType.canPassThrough(datas[0], datas[1])) {
return y;
}
}
@@ -2115,8 +2115,9 @@ private void recurseHollow(Region region, BlockVector origin, Set<BlockVector> o
while (!queue.isEmpty()) {
final BlockVector current = queue.removeFirst();
final BaseBlock block = getLazyBlock(current);
if (!BlockType.canPassThrough(block.getId(), block.getData())) {
final BlockState block = getBlock(current);
int[] datas = LegacyMapper.getInstance().getLegacyFromBlock(block);
if (!BlockType.canPassThrough(datas[0], datas[1])) {
continue;
}
@@ -53,6 +53,7 @@
import com.sk89q.worldedit.util.logging.WorldEditPrefixHandler;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.BundledItemData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.io.DataInputStream;
import java.io.File;
@@ -101,6 +102,7 @@
getVersion();
BundledBlockData.getInstance(); // Load block registry
BundledItemData.getInstance(); // Load item registry
LegacyMapper.getInstance(); // Load item registry
}
private WorldEdit() {
@@ -27,7 +27,7 @@
import com.sk89q.worldedit.blocks.type.BlockType;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.registry.state.State;
import com.sk89q.worldedit.world.registry.state.value.StateValue;
@@ -52,9 +52,6 @@
*/
public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
// Instances of this class should be _as small as possible_ because there will
// be millions of instances of this object.
private BlockState blockState;
@Nullable
private CompoundTag nbtData;
@@ -67,10 +64,12 @@
@Deprecated
public BaseBlock(int id) {
try {
this.blockState = BlockTypes.getBlockType(BundledBlockData.getInstance().fromLegacyId(id)).getDefaultState();
this.blockState = LegacyMapper.getInstance().getBlockFromLegacy(id);
if (this.blockState == null) {
this.blockState = BlockTypes.AIR.getDefaultState();
}
} catch (Exception e) {
System.out.println(id);
System.out.println(BundledBlockData.getInstance().fromLegacyId(id));
e.printStackTrace();
}
}
@@ -134,16 +133,7 @@ public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) {
* @param other the other block
*/
public BaseBlock(BaseBlock other) {
this(other.getState(), other.getNbtData());
}
/**
* Get the block state
*
* @return The block state
*/
public BlockState getState() {
return this.blockState;
this(other.toImmutableState(), other.getNbtData());
}
/**
@@ -240,7 +230,7 @@ public boolean equals(Object o) {
final BaseBlock otherBlock = (BaseBlock) o;
return this.getState().equals(otherBlock.getState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
return this.toImmutableState().equals(otherBlock.toImmutableState()) && Objects.equals(getNbtData(), otherBlock.getNbtData());
}
@@ -252,12 +242,17 @@ public boolean equals(Object o) {
*/
@Override
public boolean equalsFuzzy(BlockStateHolder o) {
return this.getState().equalsFuzzy(o);
return this.toImmutableState().equalsFuzzy(o);
}
@Override
public BlockState toImmutableState() {
return this.blockState;
}
@Override
public int hashCode() {
int ret = getState().hashCode() << 3;
int ret = toImmutableState().hashCode() << 3;
if (hasNbtData()) {
ret += getNbtData().hashCode();
}
@@ -266,7 +261,7 @@ public int hashCode() {
@Override
public String toString() {
return "Block{State: " + this.getState().toString() + ", NBT: " + String.valueOf(getNbtData()) + "}";
return "Block{State: " + this.toImmutableState().toString() + ", NBT: " + String.valueOf(getNbtData()) + "}";
}
}
@@ -23,7 +23,7 @@
import com.sk89q.worldedit.blocks.type.ItemType;
import com.sk89q.worldedit.blocks.type.ItemTypes;
import com.sk89q.worldedit.world.NbtValued;
import com.sk89q.worldedit.world.registry.BundledItemData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nullable;
@@ -46,7 +46,11 @@
*/
@Deprecated
public BaseItem(int id) {
this(ItemTypes.getItemType(BundledItemData.getInstance().fromLegacyId(id)));
ItemType type = LegacyMapper.getInstance().getItemFromLegacy(id);
if (type == null) {
type = ItemTypes.AIR;
}
this.itemType = type;
}
/**
Oops, something went wrong.

0 comments on commit 43e8a99

Please sign in to comment.