mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-08-06 23:59:30 +00:00
Added GardenPatchGenerator, GroundScatterFunction.
/pumpkins now uses the new classes.
This commit is contained in:
@@ -1,69 +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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.generator;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
/**
|
||||
* Generates flora over an applied area.
|
||||
*/
|
||||
public class FloraPlacer extends GroundGenerator {
|
||||
|
||||
private final EditSession editSession;
|
||||
private FloraGenerator floraGenerator;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param editSession the edit session
|
||||
*/
|
||||
public FloraPlacer(EditSession editSession) {
|
||||
super(editSession);
|
||||
this.editSession = editSession;
|
||||
this.floraGenerator = new FloraGenerator(editSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flora generator.
|
||||
*
|
||||
* @return the flora generator
|
||||
*/
|
||||
public FloraGenerator getFloraGenerator() {
|
||||
return floraGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flora generator.
|
||||
*
|
||||
* @param floraGenerator the flora generator
|
||||
*/
|
||||
public void setFloraGenerator(FloraGenerator floraGenerator) {
|
||||
this.floraGenerator = floraGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean apply(Vector pt, BaseBlock block) throws WorldEditException {
|
||||
return floraGenerator.apply(pt);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.generator;
|
||||
|
||||
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.BlockID;
|
||||
import com.sk89q.worldedit.operation.RegionFunction;
|
||||
import com.sk89q.worldedit.patterns.BlockChance;
|
||||
import com.sk89q.worldedit.patterns.Pattern;
|
||||
import com.sk89q.worldedit.patterns.RandomFillPattern;
|
||||
import com.sk89q.worldedit.patterns.SingleBlockPattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class GardenPatchGenerator implements RegionFunction {
|
||||
|
||||
private final Random random = new Random();
|
||||
private final EditSession editSession;
|
||||
private Pattern plant = getPumpkinPattern();
|
||||
private int affected;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param editSession the edit session
|
||||
*/
|
||||
public GardenPatchGenerator(EditSession editSession) {
|
||||
this.editSession = editSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plant pattern that is placed.
|
||||
*
|
||||
* @return the plant pattern
|
||||
*/
|
||||
public Pattern getPlant() {
|
||||
return plant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plant pattern that is placed.
|
||||
*
|
||||
* @param plant the plant pattern
|
||||
*/
|
||||
public void setPlant(Pattern plant) {
|
||||
this.plant = plant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of affected blocks.
|
||||
*
|
||||
* @return affected count
|
||||
*/
|
||||
public int getAffected() {
|
||||
return affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a patch vine.
|
||||
*
|
||||
* @param basePos the base position
|
||||
* @param pos the vine position
|
||||
*/
|
||||
private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException {
|
||||
if (pos.distance(basePos) > 4) return;
|
||||
if (editSession.getBlockType(pos) != 0) return;
|
||||
|
||||
for (int i = -1; i > -3; --i) {
|
||||
Vector testPos = pos.add(0, i, 0);
|
||||
if (editSession.getBlockType(testPos) == BlockID.AIR) {
|
||||
pos = testPos;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
editSession.setBlockIfAir(pos, new BaseBlock(BlockID.LEAVES));
|
||||
affected++;
|
||||
|
||||
int t = random.nextInt(4);
|
||||
int h = random.nextInt(3) - 1;
|
||||
Vector p;
|
||||
|
||||
BaseBlock log = new BaseBlock(BlockID.LOG);
|
||||
|
||||
switch (t) {
|
||||
case 0:
|
||||
if (random.nextBoolean()) {
|
||||
placeVine(basePos, pos.add(1, 0, 0));
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
editSession.setBlockIfAir(pos.add(1, h, -1), log);
|
||||
affected++;
|
||||
}
|
||||
editSession.setBlockIfAir(p = pos.add(0, 0, -1), plant.next(p));
|
||||
affected++;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (random.nextBoolean()) {
|
||||
placeVine(basePos, pos.add(0, 0, 1));
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
editSession.setBlockIfAir(pos.add(1, h, 0), log);
|
||||
affected++;
|
||||
}
|
||||
editSession.setBlockIfAir(p = pos.add(1, 0, 1), plant.next(p));
|
||||
affected++;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (random.nextBoolean()) {
|
||||
placeVine(basePos, pos.add(0, 0, -1));
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
editSession.setBlockIfAir(pos.add(-1, h, 0), log);
|
||||
affected++;
|
||||
}
|
||||
editSession.setBlockIfAir(p = pos.add(-1, 0, 1), plant.next(p));
|
||||
affected++;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (random.nextBoolean()) {
|
||||
placeVine(basePos, pos.add(-1, 0, 0));
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
editSession.setBlockIfAir(pos.add(-1, h, -1), log);
|
||||
affected++;
|
||||
}
|
||||
editSession.setBlockIfAir(p = pos.add(-1, 0, -1), plant.next(p));
|
||||
affected++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
if (editSession.getBlock(position).getType() != BlockID.AIR) {
|
||||
position = position.add(0, 1, 0);
|
||||
}
|
||||
|
||||
BaseBlock leavesBlock = new BaseBlock(BlockID.LEAVES);
|
||||
|
||||
editSession.setBlockIfAir(position, leavesBlock);
|
||||
|
||||
placeVine(position, position.add(0, 0, 1));
|
||||
placeVine(position, position.add(0, 0, -1));
|
||||
placeVine(position, position.add(1, 0, 0));
|
||||
placeVine(position, position.add(-1, 0, 0));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pattern that creates pumpkins with different faces.
|
||||
*
|
||||
* @return a pumpkin pattern
|
||||
*/
|
||||
public static Pattern getPumpkinPattern() {
|
||||
List<BlockChance> chance = new ArrayList<BlockChance>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
chance.add(new BlockChance(new BaseBlock(BlockID.PUMPKIN, i), 100));
|
||||
}
|
||||
return new RandomFillPattern(chance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pattern that creates melons.
|
||||
*
|
||||
* @return a melon pattern
|
||||
*/
|
||||
public static Pattern getMelonPattern() {
|
||||
return new SingleBlockPattern(new BaseBlock(BlockID.MELON_BLOCK));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user