Separated out fluids and blocks - they're different now

This commit is contained in:
Matthew Miller
2018-06-19 15:50:31 +10:00
parent 70aceb3837
commit 416480c16d
15 changed files with 836 additions and 665 deletions

View File

@ -67,10 +67,6 @@ public class BlockCategories {
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 {
@ -94,7 +90,7 @@ public class BlockCategories {
}
@Nullable
public static BlockCategory getBlockType(String id) {
public static BlockCategory getBlockCategory(String id) {
// If it has no namespace, assume minecraft.
if (id != null && !id.contains(":")) {
id = "minecraft:" + id;

View File

@ -0,0 +1,74 @@
/*
* 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 FluidCategories {
private FluidCategories() {
}
public static final FluidCategory LAVA = new FluidCategory("minecraft:lava");
public static final FluidCategory WATER = new FluidCategory("minecraft:water");
private static final Map<String, FluidCategory> categoryMapping = new HashMap<>();
static {
for (Field field : FluidCategories.class.getFields()) {
if (field.getType() == FluidCategory.class) {
try {
registerCategory((FluidCategory) field.get(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
public static void registerCategory(FluidCategory fluidCategory) {
if (categoryMapping.containsKey(fluidCategory.getId()) && !fluidCategory.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Existing category with this ID already registered");
}
categoryMapping.put(fluidCategory.getId(), fluidCategory);
}
@Nullable
public static FluidCategory getFluidCategory(String id) {
// If it has no namespace, assume minecraft.
if (id != null && !id.contains(":")) {
id = "minecraft:" + id;
}
return categoryMapping.get(id);
}
public static Collection<FluidCategory> values() {
return categoryMapping.values();
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.util.Collections;
import java.util.Set;
/**
* A category of fluids. This is due to the splitting up of
* blocks such as wool into separate ids.
*/
public class FluidCategory {
private final String id;
public FluidCategory(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
public Set<FluidType> getFluidTypes() {
return Collections.emptySet(); // TODO Make this work.
// return WorldEdit.getInstance().getPlatformManager()
// .queryCapability(Capability.GAME_HOOKS).getRegistries()
// .getBlockCategoryRegistry().getCategorisedByName(this.id);
}
/**
* Checks whether the FluidType is contained within
* this category.
*
* @param fluidType The fluidType
* @return If it's a part of this category
*/
public boolean contains(FluidType fluidType) {
return getFluidTypes().contains(fluidType);
}
}

View File

@ -0,0 +1,52 @@
/*
* 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;
/**
* Minecraft now has a 'fluid' system. This is a
* stub class to represent what it may be in the future.
*/
public class FluidType {
private String id;
public FluidType(String id) {
this.id = id;
}
/**
* Gets the ID of this block.
*
* @return The id
*/
public String getId() {
return this.id;
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof FluidType && this.id.equals(((FluidType) obj).id);
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 common Fluid String IDs.
*/
public class FluidTypes {
private FluidTypes() {
}
public static final FluidType EMPTY = new FluidType("minecraft:empty");
public static final FluidType FLOWING_LAVA = new FluidType("minecraft:flowing_lava");
public static final FluidType FLOWING_WATER = new FluidType("minecraft:flowing_water");
public static final FluidType LAVA = new FluidType("minecraft:lava");
public static final FluidType WATER = new FluidType("minecraft:water");
private static final Map<String, FluidType> fluidMapping = new HashMap<>();
static {
for (Field field : FluidTypes.class.getFields()) {
if (field.getType() == FluidType.class) {
try {
registerFluid((FluidType) field.get(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}
public static void registerFluid(FluidType fluidType) {
if (fluidMapping.containsKey(fluidType.getId()) && !fluidType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Existing fluid with this ID already registered");
}
fluidMapping.put(fluidType.getId(), fluidType);
}
@Nullable
public static FluidType getFluidType(String id) {
// If it has no namespace, assume minecraft.
if (id != null && !id.contains(":")) {
id = "minecraft:" + id;
}
return fluidMapping.get(id);
}
public static Collection<FluidType> values() {
return fluidMapping.values();
}
}

View File

@ -88,7 +88,7 @@ public class ItemCategories {
}
@Nullable
public static ItemCategory getBlockType(String id) {
public static ItemCategory getItemCategory(String id) {
// If it has no namespace, assume minecraft.
if (id != null && !id.contains(":")) {
id = "minecraft:" + id;