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

@ -19,29 +19,58 @@
package com.sk89q.worldedit.world.item;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nullable;
public interface ItemType {
public class ItemType {
default ItemTypes toEnum() {
return (ItemTypes) this;
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
private String id;
private BlockType blockType;
private int internalId;
private BaseItem defaultState;
public ItemType(String id) {
// If it has no namespace, assume minecraft.
if (!id.contains(":")) {
id = "minecraft:" + id;
}
this.id = id;
this.blockType = BlockTypes.get(this.id);
}
String getId();
int getInternalId();
public String getId() {
return this.id;
}
public int getInternalId() {
return this.internalId;
}
public void setInternalId(int internalId) {
this.internalId = internalId;
}
/**
* Gets the name of this item, or the ID if the name cannot be found.
*
* @return The name, or ID
*/
String getName();
public String getName() {
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getName(this);
if (name == null) {
return getId();
} else {
return name;
}
}
/**
@ -49,7 +78,7 @@ public interface ItemType {
*
* @return If it has a block
*/
default boolean hasBlockType() {
public boolean hasBlockType() {
return getBlockType() != null;
}
@ -59,11 +88,34 @@ public interface ItemType {
* @return The block representation
*/
@Nullable
default BlockTypes getBlockType() {
return BlockTypes.get(getId());
public BlockType getBlockType() {
return this.blockType;
}
public void setBlockType(BlockType blockType) {
this.blockType = blockType;
}
public BaseItem getDefaultState() {
return this.defaultState;
}
public void setDefaultState(BaseItem defaultState) {
this.defaultState = defaultState;
}
default BaseItem getDefaultState() {
return new BaseItem(this);
@Override
public String toString() {
return getId();
}
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof ItemType && this.id.equals(((ItemType) obj).id);
}
}