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

@ -55,7 +55,7 @@ public interface BlockRegistry {
* @param blockType the block
* @return a map of states where the key is the state's ID
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
/**

View File

@ -41,7 +41,7 @@ public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override
public Map<String, ? extends Property> getProperties(BlockType blockType) {
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
return Collections.emptyMap(); // Oof
}

View File

@ -44,4 +44,11 @@ public class BundledItemRegistry implements ItemRegistry {
public Collection<String> registerItems() {
return Collections.emptyList();
}
@Nullable
@Override
public String getName(ItemType itemType) {
BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId());
return itemEntry != null ? itemEntry.localizedName : null;
}
}

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
@ -43,7 +44,7 @@ public interface EntityRegistry {
*/
@Nullable
default BaseEntity createFromId(String id) {
EntityTypes entType = EntityTypes.get(id);
EntityType entType = EntityTypes.get(id);
return entType == null ? null : new BaseEntity(entType);
}

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
import java.util.Collection;
@ -42,5 +43,14 @@ public interface ItemRegistry {
default Collection<String> registerItems() {
return Collections.emptyList();
}
/**
* Gets the name for the given item.
*
* @param itemType the item
* @return The name, or null if it's unknown
*/
@Nullable
String getName(ItemType itemType);
}

View File

@ -57,7 +57,7 @@ public class LegacyMapper {
private final Int2ObjectArrayMap<Integer> blockStateToLegacyId4Data = new Int2ObjectArrayMap<>();
private final Int2ObjectArrayMap<Integer> extraId4DataToStateId = new Int2ObjectArrayMap<>();
private final int[] blockArr = new int[4096];
private final BiMap<Integer, ItemTypes> itemMap = HashBiMap.create();
private final BiMap<Integer, ItemType> itemMap = HashBiMap.create();
/**
* Create a new instance.
@ -96,7 +96,7 @@ public class LegacyMapper {
try {
BlockStateHolder blockState = BlockState.get(null, blockEntry.getValue());
// BlockState blockState = WorldEdit.getInstance().getBlockFactory().parseFromInput(blockEntry.getValue(), parserContext).toImmutableState();
BlockTypes type = blockState.getBlockType();
BlockType type = blockState.getBlockType();
if (type.hasProperty(PropertyKey.WATERLOGGED)) {
blockState = blockState.with(PropertyKey.WATERLOGGED, false);
}
@ -134,11 +134,11 @@ public class LegacyMapper {
}
@Nullable
public ItemTypes getItemFromLegacy(int legacyId) {
public ItemType getItemFromLegacy(int legacyId) {
return itemMap.get(legacyId << 4);
}
public ItemTypes getItemFromLegacy(String input) {
public ItemType getItemFromLegacy(String input) {
if (input.startsWith("minecraft:")) input = input.substring(10);
return itemMap.get(getCombinedId(input));
}
@ -149,7 +149,7 @@ public class LegacyMapper {
}
@Nullable
public ItemTypes getItemFromLegacy(int legacyId, int data) {
public ItemType getItemFromLegacy(int legacyId, int data) {
return itemMap.get((legacyId << 4) + data);
}