mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Make biome changes undoable
This commit is contained in:
parent
0b9607affd
commit
2bae161e5c
@ -28,15 +28,19 @@ import com.sk89q.worldedit.WorldEditException;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
import com.sk89q.worldedit.entity.Entity;
|
import com.sk89q.worldedit.entity.Entity;
|
||||||
|
import com.sk89q.worldedit.history.change.BiomeChange;
|
||||||
import com.sk89q.worldedit.history.change.BlockChange;
|
import com.sk89q.worldedit.history.change.BlockChange;
|
||||||
import com.sk89q.worldedit.history.change.EntityCreate;
|
import com.sk89q.worldedit.history.change.EntityCreate;
|
||||||
import com.sk89q.worldedit.history.change.EntityRemove;
|
import com.sk89q.worldedit.history.change.EntityRemove;
|
||||||
import com.sk89q.worldedit.history.changeset.ChangeSet;
|
import com.sk89q.worldedit.history.changeset.ChangeSet;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||||
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -70,6 +74,13 @@ public class ChangeSetExtent extends AbstractDelegateExtent {
|
|||||||
return super.setBlock(location, block);
|
return super.setBlock(location, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setBiome(BlockVector2 position, BaseBiome biome) {
|
||||||
|
BaseBiome previous = getBiome(position);
|
||||||
|
changeSet.add(new BiomeChange(position, previous, new BaseBiome(biome)));
|
||||||
|
return super.setBiome(position, biome);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Entity createEntity(Location location, BaseEntity state) {
|
public Entity createEntity(Location location, BaseEntity state) {
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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.history.change;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.extent.Extent;
|
||||||
|
import com.sk89q.worldedit.history.UndoContext;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
|
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a biome change that may be undone or replayed.
|
||||||
|
*
|
||||||
|
* <p>This biome change does not have an {@link Extent} assigned to it because
|
||||||
|
* one will be taken from the passed {@link UndoContext}. If the context
|
||||||
|
* does not have an extent (it is null), cryptic errors may occur.</p>
|
||||||
|
*/
|
||||||
|
public class BiomeChange implements Change {
|
||||||
|
|
||||||
|
private final BlockVector2 position;
|
||||||
|
private final BaseBiome previous;
|
||||||
|
private final BaseBiome current;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new biome change.
|
||||||
|
*
|
||||||
|
* @param position the position
|
||||||
|
* @param previous the previous biome
|
||||||
|
* @param current the current biome
|
||||||
|
*/
|
||||||
|
public BiomeChange(BlockVector2 position, BaseBiome previous, BaseBiome current) {
|
||||||
|
checkNotNull(position);
|
||||||
|
checkNotNull(previous);
|
||||||
|
checkNotNull(current);
|
||||||
|
this.position = position;
|
||||||
|
this.previous = previous;
|
||||||
|
this.current = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the position.
|
||||||
|
*
|
||||||
|
* @return the position
|
||||||
|
*/
|
||||||
|
public BlockVector2 getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the previous biome.
|
||||||
|
*
|
||||||
|
* @return the previous biome
|
||||||
|
*/
|
||||||
|
public BaseBiome getPrevious() {
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current biome.
|
||||||
|
*
|
||||||
|
* @return the current biome
|
||||||
|
*/
|
||||||
|
public BaseBiome getCurrent() {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void undo(UndoContext context) throws WorldEditException {
|
||||||
|
checkNotNull(context.getExtent()).setBiome(position, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void redo(UndoContext context) throws WorldEditException {
|
||||||
|
checkNotNull(context.getExtent()).setBiome(position, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user