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

@ -23,6 +23,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.LazyBlock;
import com.sk89q.worldedit.blocks.type.BlockCategories;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockTypes;
@ -1445,7 +1446,7 @@ public class EditSession implements Extent {
for (int y = world.getMaxY(); y >= 1; --y) {
Vector pt = new Vector(x, y, z);
com.sk89q.worldedit.blocks.type.BlockType id = getLazyBlock(pt).getBlockType();
com.sk89q.worldedit.blocks.type.BlockType id = getBlock(pt).getBlockType();
if (id == BlockTypes.ICE) {
if (setBlock(pt, water)) {
@ -1495,14 +1496,14 @@ public class EditSession implements Extent {
for (int y = world.getMaxY(); y >= 1; --y) {
Vector pt = new Vector(x, y, z);
int id = getLazyBlock(pt).getId();
com.sk89q.worldedit.blocks.type.BlockType id = getBlock(pt).getBlockType();
if (id == BlockID.AIR) {
if (id == BlockTypes.AIR) {
continue;
}
// Ice!
if (id == BlockID.WATER || id == BlockID.STATIONARY_WATER) {
if (id == BlockTypes.WATER) {
if (setBlock(pt, ice)) {
++affected;
}
@ -1510,9 +1511,9 @@ public class EditSession implements Extent {
}
// Snow should not cover these blocks
if (BlockType.isTranslucent(id)) {
if (BlockType.isTranslucent(id.getLegacyId())) {
// Add snow on leaves
if (id != BlockID.LEAVES && id != BlockID.LEAVES2) {
if (BlockCategories.LEAVES.contains(id)) {
break;
}
}

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;

View File

@ -175,8 +175,9 @@ public class UtilityCommands {
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
// TODO Investigate with a real build of 1.13
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, BlockTypes.FLOWING_LAVA, BlockTypes.LAVA);
session.getPlacementPosition(player), radius, BlockTypes.LAVA, BlockTypes.LAVA);
player.print(affected + " block(s) have been changed.");
}
@ -193,8 +194,9 @@ public class UtilityCommands {
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
// TODO Investigate with a real build of 1.13
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, BlockTypes.FLOWING_WATER, BlockTypes.WATER);
session.getPlacementPosition(player), radius, BlockTypes.WATER, BlockTypes.WATER);
player.print(affected + " block(s) have been changed.");
}

View File

@ -22,6 +22,8 @@ package com.sk89q.worldedit.event.extent;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.event.Event;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
@ -53,7 +55,7 @@ import static com.sk89q.worldedit.EditSession.Stage;
* is set to {@link Stage#BEFORE_HISTORY}, then you can drop (or log) changes
* before the change has reached the history, reordering, and actual change
* extents, <em>but</em> that means that any changes made with
* {@link EditSession#rawSetBlock(Vector, BaseBlock)} will skip your
* {@link EditSession#rawSetBlock(Vector, BlockStateHolder)} will skip your
* custom {@link Extent} because that method bypasses history (and reorder).
* It is thus recommended that loggers intercept at {@link Stage#BEFORE_CHANGE}
* and block interceptors intercept at BOTH {@link Stage#BEFORE_CHANGE} and

View File

@ -172,7 +172,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final com.sk89q.worldedit.blocks.type.BlockType type = block.getBlockType();
// Don't get put in lava!
if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA) {
if (type == BlockTypes.LAVA) {
return false;
}
@ -214,7 +214,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
final com.sk89q.worldedit.blocks.type.BlockType type = block.getBlockType();
// Don't want to end up in lava
if (type != BlockTypes.AIR && type != BlockTypes.LAVA && type != BlockTypes.FLOWING_LAVA) {
if (type != BlockTypes.AIR && type != BlockTypes.LAVA) {
// Found a block!
setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5));
return true;

View File

@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.type.BlockState;
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
import com.sk89q.worldedit.blocks.type.BlockTypes;
@ -214,6 +213,6 @@ public class GardenPatchGenerator implements RegionFunction {
* @return a melon pattern
*/
public static Pattern getMelonPattern() {
return new BlockPattern(BlockTypes.MELON_BLOCK.getDefaultState());
return new BlockPattern(BlockTypes.MELON.getDefaultState());
}
}

View File

@ -148,8 +148,7 @@ public class HeightMap {
BlockState existing = session.getBlock(new Vector(xr, curHeight, zr));
// Skip water/lava
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.FLOWING_WATER
&& existing.getBlockType() != BlockTypes.LAVA && existing.getBlockType() != BlockTypes.FLOWING_LAVA) {
if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) {
session.setBlock(new Vector(xr, newHeight, zr), existing);
++blocksChanged;

View File

@ -67,9 +67,7 @@ public abstract class AbstractWorld implements World {
public Mask createLiquidMask() {
return new BlockMask(this,
new BlockState(BlockTypes.LAVA, new HashMap<>()),
new BlockState(BlockTypes.FLOWING_LAVA, new HashMap<>()),
new BlockState(BlockTypes.WATER, new HashMap<>()),
new BlockState(BlockTypes.FLOWING_WATER, new HashMap<>()));
new BlockState(BlockTypes.WATER, new HashMap<>()));
}
@Override

View File

@ -1,131 +0,0 @@
/*
* 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.world.storage;
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
/**
* Block data related classes.
*
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData}
*/
@Deprecated
public final class BlockData {
private BlockData() {
}
/**
* Rotate a block's data value 90 degrees (north->east->south->west->north);
*
* @param type type ID of the block
* @param data data value of the block
* @return a new data value
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData#rotate90(int, int)}
*/
@Deprecated
public static int rotate90(int type, int data) {
return com.sk89q.worldedit.blocks.BlockData.rotate90(type, data);
}
/**
* Rotate a block's data value -90 degrees (north<-east<-south<-west<-north);
*
* @param type type ID of the block
* @param data data value of the block
* @return a new data value
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData#rotate90Reverse(int, int)}
*/
@Deprecated
public static int rotate90Reverse(int type, int data) {
return com.sk89q.worldedit.blocks.BlockData.rotate90Reverse(type, data);
}
/**
* Flip a block's data value.
*
* @param type type ID of the block
* @param data data value of the block
* @return a new data value
* @deprecated use return {@link com.sk89q.worldedit.blocks.BlockData#flip(int, int)}
*/
@Deprecated
public static int flip(int type, int data) {
return rotate90(type, rotate90(type, data));
}
/**
* Flip a block's data value.
*
* @param type type ID of the block
* @param data data value of the block
* @param direction the direction to flip
* @return a new data value
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData#flip(int, int, FlipDirection)}
*/
@Deprecated
public static int flip(int type, int data, FlipDirection direction) {
return com.sk89q.worldedit.blocks.BlockData.flip(type, data, direction);
}
/**
* Cycle a block's data value. This usually goes through some rotational pattern
* depending on the block. If it returns -1, it means the id and data specified
* do not have anything to cycle to.
*
* @param type block id to be cycled
* @param data block data value that it starts at
* @param increment whether to go forward (1) or backward (-1) in the cycle
* @return the new data value for the block
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData#cycle(int, int, int)}
*/
@Deprecated
public static int cycle(int type, int data, int increment) {
return com.sk89q.worldedit.blocks.BlockData.cycle(type, data, increment);
}
/**
* Returns the data value for the next color of cloth in the rainbow. This
* should not be used if you want to just increment the data value.
*
* @param data the data value
* @return a new data value
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData#nextClothColor(int)}
*/
@Deprecated
public static int nextClothColor(int data) {
return com.sk89q.worldedit.blocks.BlockData.nextClothColor(data);
}
/**
* Returns the data value for the previous ext color of cloth in the rainbow.
* This should not be used if you want to just increment the data value.
*
* @param data the data value
* @return a new data value
* @deprecated use {@link com.sk89q.worldedit.blocks.BlockData#prevClothColor(int)}
*/
@Deprecated
public static int prevClothColor(int data) {
return com.sk89q.worldedit.blocks.BlockData.prevClothColor(data);
}
}