Skip to content

Commit

Permalink
Advanced Entity Spawner IC.
Browse files Browse the repository at this point in the history
Signed-off-by: me4502 <mnmiller1@hotmail.com>
  • Loading branch information
me4502 committed Nov 3, 2012
1 parent 21428cc commit 499b0ea
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 8 deletions.
Expand Up @@ -90,6 +90,7 @@
import com.sk89q.craftbook.gates.weather.WeatherControl;
import com.sk89q.craftbook.gates.weather.WeatherControlAdvanced;
import com.sk89q.craftbook.gates.weather.WeatherFaker;
import com.sk89q.craftbook.gates.world.AdvancedEntitySpawner;
import com.sk89q.craftbook.gates.world.ArrowBarrage;
import com.sk89q.craftbook.gates.world.ArrowShooter;
import com.sk89q.craftbook.gates.world.AutomaticCrafter;
Expand Down Expand Up @@ -340,6 +341,7 @@ private void registerICs() {
registerIC("MC1224", "time bomb", new TimedExplosion.Factory(server), familySISO, familyAISO); //Restricted
registerIC("MC1225", "pump", new Pump.Factory(server), familySISO, familyAISO);
registerIC("MC1226", "spigot", new Spigot.Factory(server), familySISO, familyAISO);
registerIC("MC1227", "avd spawner", new AdvancedEntitySpawner.Factory(server), familySISO, familyAISO); // Restricted
registerIC("MC1230", "sense day", new DaySensor.Factory(server), familySISO, familyAISO);
registerIC("MC1231", "t control", new TimeControl.Factory(server), familySISO, familyAISO); // Restricted
registerIC("MC1232", "time set", new TimeSet.Factory(server), familySISO, familyAISO); // Restricted
Expand Down
@@ -0,0 +1,210 @@
package com.sk89q.craftbook.gates.world;

import net.minecraft.server.Enchantment;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;

import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;

import com.sk89q.craftbook.ic.AbstractICFactory;
import com.sk89q.craftbook.ic.ChipState;
import com.sk89q.craftbook.ic.IC;
import com.sk89q.craftbook.ic.ICFactory;
import com.sk89q.craftbook.ic.RestrictedIC;
import com.sk89q.craftbook.util.SignUtil;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.bukkit.BukkitUtil;

public class AdvancedEntitySpawner extends CreatureSpawner {

public AdvancedEntitySpawner(Server server, Sign sign, ICFactory factory) {
super(server, sign, factory);
load();
}

Location location;
EntityType type = EntityType.PIG;
int amount = 1;

@Override
public String getTitle() {
return "Advanced Entity Spawner";
}

@Override
public String getSignTitle() {
return "ADV ENT SPAWNER";
}

public void load() {

type = EntityType.fromName(getSign().getLine(3).trim().split("\\*")[0]);

try {
amount = Integer.parseInt(getSign().getLine(3).trim().split("\\*")[1]);
}
catch(Exception e) {
amount = 1;
}

try {
double x, y, z;
x = Double.parseDouble(getSign().getLine(2).split(":")[0]);
y = Double.parseDouble(getSign().getLine(2).split(":")[1]);
z = Double.parseDouble(getSign().getLine(2).split(":")[2]);
x += getSign().getX();
y += getSign().getY();
z += getSign().getZ();
location = new Location(BukkitUtil.getLocalWorld(getSign().getWorld()), new Vector(x,y,z));
}
catch(Exception e){
location = new Location(BukkitUtil.getLocalWorld(getSign().getWorld()),
new Vector(getSign().getX(),getSign().getY(),getSign().getZ()));
}
}

@Override
public void trigger(ChipState chip) {

if(!chip.getInput(0))
return;
Block left = SignUtil.getLeftBlock(getSign().getBlock());
Sign effectSign = null;
if(left.getTypeId() == BlockID.WALL_SIGN) {
effectSign = (Sign) left.getState();
}

Block right = SignUtil.getRightBlock(getSign().getBlock());
Sign armourSign = null;
if(right.getTypeId() == BlockID.WALL_SIGN) {
armourSign = (Sign) right.getState();
}

for(int i = 0; i < amount; i++) {
Entity ent = getSign().getWorld().spawnEntity(BukkitUtil.toLocation(location), type);

if(armourSign != null) { //Apply armor
if(ent instanceof LivingEntity) {
CraftLivingEntity cle = (CraftLivingEntity) ent;
EntityLiving eliv = cle.getHandle();

for(int s = 0; s < 4; s++) {
try {
String bit = armourSign.getLine(s);
if(bit == null || bit.trim().length() == 0)
continue;

byte data = 0;
try {
data = Byte.parseByte(bit.split(";")[0].split(":")[1]);
}
catch(Exception e){}

ItemStack slot = new ItemStack(Item.byId[Integer.parseInt(bit.split(";")[0].split(":")[0])], 1, data);
try {
for(int e = 1; e < bit.split(";").length; e++) {
slot.addEnchantment(Enchantment.byId[Integer.parseInt(bit.split(";")[e].split(":")[0])],
Integer.parseInt(bit.split(";")[e].split(":")[1]));
}
}
catch(Exception e){}
eliv.setEquipment(s + 1, slot);
}
catch(Exception e){}
}
}
}

if(effectSign != null) { //Apply effects
for(int s = 0; s < 4; s++) {
try {
String bit = armourSign.getLine(s);
if(bit == null || bit.trim().length() == 0)
continue;

String[] data = bit.split(":");

if(data[0].equalsIgnoreCase("e"))
setEntityData(ent, data[1]);
else if(data[0].equalsIgnoreCase("p")) {
//TODO potion effects
}
else if(data[0].equalsIgnoreCase("v")) {
try {
double x, y, z;
x = Double.parseDouble(getSign().getLine(2).split(":")[0]);
y = Double.parseDouble(getSign().getLine(2).split(":")[1]);
z = Double.parseDouble(getSign().getLine(2).split(":")[2]);
ent.setVelocity(new org.bukkit.util.Vector(x,y,z));
}
catch(Exception e){
}
}
else if(data[0].equalsIgnoreCase("s")) {
if(!(ent instanceof LivingEntity))
continue;
CraftLivingEntity cle = (CraftLivingEntity) ent;
EntityLiving eliv = cle.getHandle();

byte d = 0;
try {
d = Byte.parseByte(bit.split(";")[0].split(":")[2]);
}
catch(Exception e){}

ItemStack slot = new ItemStack(Item.byId[Integer.parseInt(bit.split(";")[0].split(":")[1])], 1, d);
try {
for(int e = 1; e < bit.split(";").length; e++) {
slot.addEnchantment(Enchantment.byId[Integer.parseInt(bit.split(";")[e].split(":")[1])],
Integer.parseInt(bit.split(";")[e].split(":")[2]));
}
}
catch(Exception e){}
eliv.setEquipment(0, slot);
}
}
catch(Exception e){}
}
}
}
}

public static class Factory extends AbstractICFactory implements RestrictedIC {

public Factory(Server server) {

super(server);
}

@Override
public IC create(Sign sign) {

return new AdvancedEntitySpawner(getServer(), sign, this);
}

@Override
public String getDescription() {

return "Spawns a mob with many customizations.";
}

@Override
public String[] getLineHelp() {

String[] lines = new String[] {
"x:y:z",
"entitytype*amount"
};
return lines;
}
}
}
Expand Up @@ -18,16 +18,31 @@

package com.sk89q.craftbook.gates.world;

import com.sk89q.craftbook.ic.*;
import com.sk89q.craftbook.util.LocationUtil;
import com.sk89q.craftbook.util.SignUtil;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.entity.*;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.MagmaCube;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Sheep;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Wolf;

import com.sk89q.craftbook.ic.AbstractIC;
import com.sk89q.craftbook.ic.AbstractICFactory;
import com.sk89q.craftbook.ic.ChipState;
import com.sk89q.craftbook.ic.IC;
import com.sk89q.craftbook.ic.ICFactory;
import com.sk89q.craftbook.ic.RestrictedIC;
import com.sk89q.craftbook.util.LocationUtil;
import com.sk89q.craftbook.util.SignUtil;

public class CreatureSpawner extends AbstractIC {

Expand Down Expand Up @@ -88,6 +103,16 @@ public void trigger(ChipState chip) {

public void setEntityData(Entity ent, String data) {

if (ent instanceof Ageable && data.equalsIgnoreCase("baby")) {
((Ageable) ent).setBaby();
}

if (ent instanceof Ageable && data.equalsIgnoreCase("babylock")) {
((Ageable) ent).setBaby();
((Ageable) ent).setAgeLock(true);
}


switch (ent.getType()) {
case CREEPER:
if (data.equalsIgnoreCase("charged")) {
Expand All @@ -103,6 +128,12 @@ public void setEntityData(Entity ent, String data) {
((Slime) ent).setSize(6);
} else if (data.equalsIgnoreCase("small")) {
((Slime) ent).setSize(3);
} else {
try {
int size = Integer.parseInt(data);
((Slime) ent).setSize(size);
}
catch(Exception e){}
}
break;
case MAGMA_CUBE:
Expand All @@ -114,6 +145,12 @@ public void setEntityData(Entity ent, String data) {
((MagmaCube) ent).setSize(6);
} else if (data.equalsIgnoreCase("small")) {
((MagmaCube) ent).setSize(3);
} else {
try {
int size = Integer.parseInt(data);
((MagmaCube) ent).setSize(size);
}
catch(Exception e){}
}
break;
case WOLF:
Expand Down Expand Up @@ -177,11 +214,7 @@ public void setEntityData(Entity ent, String data) {
}
break;
default:
if (ent instanceof Animals && data.equalsIgnoreCase("baby")) {
((Animals) ent).setBaby();
}
break;

}
}

Expand Down

0 comments on commit 499b0ea

Please sign in to comment.