Skip to content

Commit

Permalink
Add ModSpawn Tag; calls default getCanSpawnHere. Invertable and Chain…
Browse files Browse the repository at this point in the history
…able. Closes #39
  • Loading branch information
Crudedragos committed Jun 3, 2013
1 parent 4c82e6e commit 1122906
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum Key {
KeyParserNormalCube.class), liquid("liquid", KeyParserLiquid.class), opaque("opaque",
KeyParserOpaqueBlock.class), solidSide("solidSide", KeyParserSolidSide.class), difficulty("difficulty",
KeyParserDifficulty.class), torchLight("torchLight", KeyParserTorchLight.class), ground("ground",
KeyParserGround.class), top("top", KeyParserTop.class), fill("fill", KeyParserFill.class),
KeyParserGround.class), top("top", KeyParserTop.class), fill("fill", KeyParserFill.class), modspawn(
"modSpawn", KeyParserModSpawn.class),

/* Sub Tags */
blockRangeX("blockRangeX", null), blockRangeY("blockRangeY", null), blockRangeZ("blockRangeZ", null),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package jas.common.spawner.creature.handler.parsing.keys;

import jas.common.JASLog;
import jas.common.spawner.creature.handler.parsing.TypeValuePair;
import jas.common.spawner.creature.handler.parsing.settings.OptionalSettings.Operand;

import java.util.ArrayList;
import java.util.HashMap;

import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;

public class KeyParserModSpawn extends KeyParserBase {

public KeyParserModSpawn(Key key) {
super(key, true, KeyType.CHAINABLE);
}

@Override
public boolean parseChainable(String parseable, ArrayList<TypeValuePair> parsedChainable,
ArrayList<Operand> operandvalue) {
String[] pieces = parseable.split(",");
Operand operand = getOperand(pieces);
if (pieces.length == 1) {
parsedChainable.add(new TypeValuePair(key, isInverted(parseable)));
operandvalue.add(operand);
return true;
} else {
JASLog.severe("Error Parsing Needs %s parameter. Invalid Argument Length.", key.key);
return false;
}
}

@Override
public boolean parseValue(String parseable, HashMap<String, Object> valueCache) {
throw new UnsupportedOperationException();
}

@Override
public boolean isValidLocation(World world, EntityLiving entity, int xCoord, int yCoord, int zCoord,
TypeValuePair typeValuePair, HashMap<String, Object> valueCache) {
boolean isInverted = (Boolean) typeValuePair.getValue();
boolean canSpawn = entity.getCanSpawnHere();
return isInverted ? canSpawn : !canSpawn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class OptionalSettingsSpawning extends OptionalSettingsBase {
public OptionalSettingsSpawning(String parseableString) {
super(parseableString.replace("}", ""), EnumSet.of(Key.spawn, Key.light, Key.block, Key.blockFoot,
Key.spawnRange, Key.sky, Key.entityCap, Key.minSpawnHeight, Key.maxSpawnHeight, Key.liquid, Key.opaque,
Key.normal, Key.solidSide, Key.difficulty, Key.torchLight, Key.ground, Key.top, Key.fill));
Key.normal, Key.solidSide, Key.difficulty, Key.torchLight, Key.ground, Key.top, Key.fill, Key.modspawn));
}

public Integer getEntityCap() {
Expand Down

0 comments on commit 1122906

Please sign in to comment.