mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Added a category system and refactored registries
This commit is contained in:
@ -22,7 +22,6 @@ package com.sk89q.worldedit.blocks;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
@ -102,7 +101,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
*/
|
||||
public BaseBlock(BlockState state, @Nullable CompoundTag nbtData) {
|
||||
this.blockState = state;
|
||||
setNbtData(nbtData);
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +125,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
@Deprecated
|
||||
public BaseBlock(int id, int data, @Nullable CompoundTag nbtData) {
|
||||
this(id);
|
||||
setNbtData(nbtData);
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,6 +173,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
*
|
||||
* @return The state map
|
||||
*/
|
||||
@Override
|
||||
public Map<State, StateValue> getStates() {
|
||||
return this.blockState.getStates();
|
||||
}
|
||||
@ -194,19 +194,11 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
* @param state The state to get the value for
|
||||
* @return The state value
|
||||
*/
|
||||
@Override
|
||||
public StateValue getState(State state) {
|
||||
return this.blockState.getState(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block's data value.
|
||||
*
|
||||
* @param data block data value
|
||||
*/
|
||||
@Deprecated
|
||||
public void setData(int data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return getNbtData() != null;
|
||||
@ -237,80 +229,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
throw new UnsupportedOperationException("This class is immutable.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if it's air.
|
||||
*
|
||||
* @return if air
|
||||
*/
|
||||
public boolean isAir() {
|
||||
return getBlockType() == BlockTypes.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate this block 90 degrees.
|
||||
*
|
||||
* @return new data value
|
||||
* @deprecated Use {@link BlockData#rotate90(int, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public int rotate90() {
|
||||
int newData = BlockData.rotate90(getBlockType().getLegacyId(), getData());
|
||||
setData(newData);
|
||||
return newData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate this block -90 degrees.
|
||||
*
|
||||
* @return new data value
|
||||
* @deprecated Use {@link BlockData#rotate90Reverse(int, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public int rotate90Reverse() {
|
||||
int newData = BlockData.rotate90Reverse(getBlockType().getLegacyId(), getData());
|
||||
setData((short) newData);
|
||||
return newData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycle the damage value of the block forward or backward
|
||||
*
|
||||
* @param increment 1 for forward, -1 for backward
|
||||
* @return new data value
|
||||
* @deprecated Use {@link BlockData#cycle(int, int, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public int cycleData(int increment) {
|
||||
int newData = BlockData.cycle(getBlockType().getLegacyId(), getData(), increment);
|
||||
setData((short) newData);
|
||||
return newData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip this block.
|
||||
*
|
||||
* @return this block
|
||||
* @deprecated Use {@link BlockData#flip(int, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock flip() {
|
||||
setData((short) BlockData.flip(getBlockType().getLegacyId(), getData()));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip this block.
|
||||
*
|
||||
* @param direction direction to flip in
|
||||
* @return this block
|
||||
* @deprecated Use {@link BlockData#flip(int, int, FlipDirection)}
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock flip(FlipDirection direction) {
|
||||
setData((short) BlockData.flip(getBlockType().getLegacyId(), getData(), direction));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the type ID and data value are equal.
|
||||
*/
|
||||
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Stores a list of categories of Block Types.
|
||||
*/
|
||||
public class BlockCategories {
|
||||
|
||||
private BlockCategories() {
|
||||
}
|
||||
|
||||
public static final BlockCategory ACACIA_LOGS = new BlockCategory("minecraft:acacia_logs");
|
||||
public static final BlockCategory ANVIL = new BlockCategory("minecraft:anvil");
|
||||
public static final BlockCategory BANNERS = new BlockCategory("minecraft:banners");
|
||||
public static final BlockCategory BIRCH_LOGS = new BlockCategory("minecraft:birch_logs");
|
||||
public static final BlockCategory BUTTONS = new BlockCategory("minecraft:buttons");
|
||||
public static final BlockCategory CARPETS = new BlockCategory("minecraft:carpets");
|
||||
public static final BlockCategory CORAL = new BlockCategory("minecraft:coral");
|
||||
public static final BlockCategory CORAL_PLANTS = new BlockCategory("minecraft:coral_plants");
|
||||
public static final BlockCategory DARK_OAK_LOGS = new BlockCategory("minecraft:dark_oak_logs");
|
||||
public static final BlockCategory DOORS = new BlockCategory("minecraft:doors");
|
||||
public static final BlockCategory ENDERMAN_HOLDABLE = new BlockCategory("minecraft:enderman_holdable");
|
||||
public static final BlockCategory FLOWER_POTS = new BlockCategory("minecraft:flower_pots");
|
||||
public static final BlockCategory ICE = new BlockCategory("minecraft:ice");
|
||||
public static final BlockCategory JUNGLE_LOGS = new BlockCategory("minecraft:jungle_logs");
|
||||
public static final BlockCategory LEAVES = new BlockCategory("minecraft:leaves");
|
||||
public static final BlockCategory LOGS = new BlockCategory("minecraft:logs");
|
||||
public static final BlockCategory OAK_LOGS = new BlockCategory("minecraft:oak_logs");
|
||||
public static final BlockCategory PLANKS = new BlockCategory("minecraft:planks");
|
||||
public static final BlockCategory RAILS = new BlockCategory("minecraft:rails");
|
||||
public static final BlockCategory SAND = new BlockCategory("minecraft:sand");
|
||||
public static final BlockCategory SAPLINGS = new BlockCategory("minecraft:saplings");
|
||||
public static final BlockCategory SLABS = new BlockCategory("minecraft:slabs");
|
||||
public static final BlockCategory SPRUCE_LOGS = new BlockCategory("minecraft:spruce_logs");
|
||||
public static final BlockCategory STAIRS = new BlockCategory("minecraft:stairs");
|
||||
public static final BlockCategory STONE_BRICKS = new BlockCategory("minecraft:stone_bricks");
|
||||
public static final BlockCategory VALID_SPAWN = new BlockCategory("minecraft:valid_spawn");
|
||||
public static final BlockCategory WOODEN_BUTTONS = new BlockCategory("minecraft:wooden_buttons");
|
||||
public static final BlockCategory WOODEN_DOORS = new BlockCategory("minecraft:wooden_doors");
|
||||
public static final BlockCategory WOODEN_PRESSURE_PLATES = new BlockCategory("minecraft:wooden_pressure_plates");
|
||||
public static final BlockCategory WOODEN_SLABS = new BlockCategory("minecraft:wooden_slabs");
|
||||
public static final BlockCategory WOODEN_STAIRS = new BlockCategory("minecraft:wooden_stairs");
|
||||
public static final BlockCategory WOOL = new BlockCategory("minecraft:wool");
|
||||
|
||||
// Fluids
|
||||
public static final BlockCategory LAVA = new BlockCategory("minecraft:lava");
|
||||
public static final BlockCategory WATER = new BlockCategory("minecraft:water");
|
||||
|
||||
private static final Map<String, BlockCategory> categoryMapping = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Field field : BlockCategories.class.getFields()) {
|
||||
if (field.getType() == BlockCategory.class) {
|
||||
try {
|
||||
registerCategory((BlockCategory) field.get(null));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerCategory(BlockCategory blockCategory) {
|
||||
if (categoryMapping.containsKey(blockCategory.getId()) && !blockCategory.getId().startsWith("minecraft:")) {
|
||||
throw new IllegalArgumentException("Existing category with this ID already registered");
|
||||
}
|
||||
|
||||
categoryMapping.put(blockCategory.getId(), blockCategory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BlockCategory getBlockType(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (id != null && !id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
return categoryMapping.get(id);
|
||||
}
|
||||
|
||||
public static Collection<BlockCategory> values() {
|
||||
return categoryMapping.values();
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A category of blocks. This is due to the splitting up of
|
||||
* blocks such as wool into separate ids.
|
||||
*/
|
||||
public class BlockCategory {
|
||||
|
||||
private final String id;
|
||||
|
||||
public BlockCategory(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Set<BlockType> getBlockTypes() {
|
||||
return WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries()
|
||||
.getBlockCategoryRegistry().getCategorisedByName(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the BlocKType is contained within
|
||||
* this category.
|
||||
*
|
||||
* @param blockType The blocktype
|
||||
* @return If it's a part of this category
|
||||
*/
|
||||
public boolean contains(BlockType blockType) {
|
||||
return getBlockTypes().contains(blockType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the BlockStateHolder is contained within
|
||||
* this category.
|
||||
*
|
||||
* @param blockStateHolder The blockstateholder
|
||||
* @return If it's a part of this category
|
||||
*/
|
||||
public boolean contains(BlockStateHolder blockStateHolder) {
|
||||
return getBlockTypes().contains(blockStateHolder.getBlockType());
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Stores a list of categories of Item Types.
|
||||
*/
|
||||
public class ItemCategories {
|
||||
|
||||
private ItemCategories() {
|
||||
}
|
||||
|
||||
public static final ItemCategory ACACIA_LOGS = new ItemCategory("minecraft:acacia_logs");
|
||||
public static final ItemCategory ANVIL = new ItemCategory("minecraft:anvil");
|
||||
public static final ItemCategory BANNERS = new ItemCategory("minecraft:banners");
|
||||
public static final ItemCategory BIRCH_LOGS = new ItemCategory("minecraft:birch_logs");
|
||||
public static final ItemCategory BOATS = new ItemCategory("minecraft:boats");
|
||||
public static final ItemCategory BUTTONS = new ItemCategory("minecraft:buttons");
|
||||
public static final ItemCategory CARPETS = new ItemCategory("minecraft:carpets");
|
||||
public static final ItemCategory CORAL = new ItemCategory("minecraft:coral");
|
||||
public static final ItemCategory CORAL_PLANTS = new ItemCategory("minecraft:coral_plants");
|
||||
public static final ItemCategory DARK_OAK_LOGS = new ItemCategory("minecraft:dark_oak_logs");
|
||||
public static final ItemCategory DOORS = new ItemCategory("minecraft:doors");
|
||||
public static final ItemCategory FISHES = new ItemCategory("minecraft:fishes");
|
||||
public static final ItemCategory JUNGLE_LOGS = new ItemCategory("minecraft:jungle_logs");
|
||||
public static final ItemCategory LEAVES = new ItemCategory("minecraft:leaves");
|
||||
public static final ItemCategory LOGS = new ItemCategory("minecraft:logs");
|
||||
public static final ItemCategory OAK_LOGS = new ItemCategory("minecraft:oak_logs");
|
||||
public static final ItemCategory PLANKS = new ItemCategory("minecraft:planks");
|
||||
public static final ItemCategory RAILS = new ItemCategory("minecraft:rails");
|
||||
public static final ItemCategory SAND = new ItemCategory("minecraft:sand");
|
||||
public static final ItemCategory SAPLINGS = new ItemCategory("minecraft:saplings");
|
||||
public static final ItemCategory SLABS = new ItemCategory("minecraft:slabs");
|
||||
public static final ItemCategory SPRUCE_LOGS = new ItemCategory("minecraft:spruce_logs");
|
||||
public static final ItemCategory STAIRS = new ItemCategory("minecraft:stairs");
|
||||
public static final ItemCategory STONE_BRICKS = new ItemCategory("minecraft:stone_bricks");
|
||||
public static final ItemCategory WOODEN_BUTTONS = new ItemCategory("minecraft:wooden_buttons");
|
||||
public static final ItemCategory WOODEN_DOORS = new ItemCategory("minecraft:wooden_doors");
|
||||
public static final ItemCategory WOODEN_PRESSURE_PLATES = new ItemCategory("minecraft:wooden_pressure_plates");
|
||||
public static final ItemCategory WOODEN_SLABS = new ItemCategory("minecraft:wooden_slabs");
|
||||
public static final ItemCategory WOODEN_STAIRS = new ItemCategory("minecraft:wooden_stairs");
|
||||
public static final ItemCategory WOOL = new ItemCategory("minecraft:wool");
|
||||
|
||||
private static final Map<String, ItemCategory> categoryMapping = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Field field : ItemCategories.class.getFields()) {
|
||||
if (field.getType() == ItemCategory.class) {
|
||||
try {
|
||||
registerCategory((ItemCategory) field.get(null));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerCategory(ItemCategory itemCategory) {
|
||||
if (categoryMapping.containsKey(itemCategory.getId()) && !itemCategory.getId().startsWith("minecraft:")) {
|
||||
throw new IllegalArgumentException("Existing category with this ID already registered");
|
||||
}
|
||||
|
||||
categoryMapping.put(itemCategory.getId(), itemCategory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ItemCategory getBlockType(String id) {
|
||||
// If it has no namespace, assume minecraft.
|
||||
if (id != null && !id.contains(":")) {
|
||||
id = "minecraft:" + id;
|
||||
}
|
||||
return categoryMapping.get(id);
|
||||
}
|
||||
|
||||
public static Collection<ItemCategory> values() {
|
||||
return categoryMapping.values();
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks.type;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A category of items. This is due to the splitting up of
|
||||
* items such as wool into separate ids.
|
||||
*/
|
||||
public class ItemCategory {
|
||||
|
||||
private final String id;
|
||||
|
||||
public ItemCategory(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Set<ItemType> getItemTypes() {
|
||||
return WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries()
|
||||
.getItemCategoryRegistry().getCategorisedByName(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the ItemType is contained within
|
||||
* this category.
|
||||
*
|
||||
* @param itemType The itemType
|
||||
* @return If it's a part of this category
|
||||
*/
|
||||
public boolean contains(ItemType itemType) {
|
||||
return getItemTypes().contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the BaseItem is contained within
|
||||
* this category.
|
||||
*
|
||||
* @param baseItem The item
|
||||
* @return If it's a part of this category
|
||||
*/
|
||||
public boolean contains(BaseItem baseItem) {
|
||||
return getItemTypes().contains(baseItem.getType());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user