Permalink
Browse files

Separated out fluids and blocks - they're different now

  • Loading branch information...
me4502 committed Jun 19, 2018
1 parent 63e20f8 commit c7b5b06290bc183fd39f012c20e5c2e06f3d66cd
@@ -23,6 +23,7 @@
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 int thaw(Vector position, double radius)
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,24 +1496,24 @@ public int simulateSnow(Vector position, double radius) throws MaxChangedBlocksE
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;
}
break;
}
// 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;
}
}
@@ -67,10 +67,6 @@ private 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 static void registerCategory(BlockCategory blockCategory) {
}
@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;

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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();
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -88,7 +88,7 @@ public static void registerCategory(ItemCategory itemCategory) {
}
@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;
@@ -175,8 +175,9 @@ public void fixLava(Player player, LocalSession session, EditSession editSession
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 void fixWater(Player player, LocalSession session, EditSession editSessio
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.");
}
@@ -22,6 +22,8 @@
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 @@
* 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
@@ -172,7 +172,7 @@ public boolean ascendLevel() {
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 boolean descendLevel() {
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;
Oops, something went wrong.

0 comments on commit c7b5b06

Please sign in to comment.