I guarantee this is broken. Start some form of string ID for blocks

This commit is contained in:
Matthew Miller
2018-01-03 15:35:51 +10:00
parent e6c6a2cfea
commit 41a80064f5
39 changed files with 349 additions and 118 deletions

View File

@ -46,6 +46,7 @@ public interface BlockRegistry {
* @return the block, which may be null if no block exists
*/
@Nullable
@Deprecated
BaseBlock createFromId(int id);
/**

View File

@ -128,6 +128,22 @@ public class BundledBlockData {
}
}
/**
* Convert the given legacy numeric ID to a string ID.
*
* @param id the legacy ID
* @return the ID, which may be null if the block does not have a ID
*/
@Nullable
public String fromLegacyId(Integer id) {
BlockEntry entry = findById(id);
if (entry != null) {
return entry.id;
} else {
return null;
}
}
/**
* Get the material properties for the given block.
*
@ -135,6 +151,7 @@ public class BundledBlockData {
* @return the material's properties, or null
*/
@Nullable
@Deprecated
public BlockMaterial getMaterialById(int id) {
BlockEntry entry = findById(id);
if (entry != null) {
@ -144,6 +161,22 @@ public class BundledBlockData {
}
}
/**
* Get the material properties for the given block.
*
* @param id the string ID
* @return the material's properties, or null
*/
@Nullable
public BlockMaterial getMaterialById(String id) {
BlockEntry entry = findById(id);
if (entry != null) {
return entry.material;
} else {
return null;
}
}
/**
* Get the states for the given block.
*
@ -151,6 +184,7 @@ public class BundledBlockData {
* @return the block's states, or null if no information is available
*/
@Nullable
@Deprecated
public Map<String, ? extends State> getStatesById(int id) {
BlockEntry entry = findById(id);
if (entry != null) {
@ -160,6 +194,22 @@ public class BundledBlockData {
}
}
/**
* Get the states for the given block.
*
* @param id the string ID
* @return the block's states, or null if no information is available
*/
@Nullable
public Map<String, ? extends State> getStatesById(String id) {
BlockEntry entry = findById(id);
if (entry != null) {
return entry.states;
} else {
return null;
}
}
/**
* Get a singleton instance of this object.
*

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.blocks.type.BlockTypes;
import javax.annotation.Nullable;
import java.util.Map;
@ -34,30 +35,30 @@ public class LegacyBlockRegistry implements BlockRegistry {
@Nullable
@Override
public BaseBlock createFromId(String id) {
Integer legacyId = BundledBlockData.getInstance().toLegacyId(id);
if (legacyId != null) {
return createFromId(legacyId);
return new BaseBlock(BlockTypes.getBlockType(id));
}
@Nullable
@Override
public BaseBlock createFromId(int legacyId) {
String id = BundledBlockData.getInstance().fromLegacyId(legacyId);
if (id != null) {
return createFromId(id);
} else {
return null;
}
}
@Nullable
@Override
public BaseBlock createFromId(int id) {
return new BaseBlock(id);
}
@Nullable
@Override
public BlockMaterial getMaterial(BaseBlock block) {
return BundledBlockData.getInstance().getMaterialById(block.getId());
return BundledBlockData.getInstance().getMaterialById(block.getType().getId());
}
@Nullable
@Override
public Map<String, ? extends State> getStates(BaseBlock block) {
return BundledBlockData.getInstance().getStatesById(block.getId());
return BundledBlockData.getInstance().getStatesById(block.getType().getId());
}
}