Added several more functions to pre-existing classes:

-Spawner, Transport, Healer, Guard, Bard jobs received more functions.
-Added more functions to the transporter role.
-IRole: Added getNpc() function.
-IAnimal, IEntityLiving, and IEntityLivingBase received more functions from their MC counterparts.
-Nearly every function with that takes position/vector parameters now has an equivalent with IPos as a parameter instead.
This commit is contained in:
Luis C.M committed 2022-11-05 20:19:14 -05:00
1 parent 112e82a09d
commit e9a8f8cebc
51 files changed
+1025 -227

No files matched your search

+1 -1
View File
@@ -518,7 +518,7 @@ public class EventHooks {
public static boolean onCNPCNaturalSpawn(INaturalSpawn naturalSpawn, BlockPos blockPos, boolean animalSpawnPassed, boolean monsterSpawnPassed, boolean liquidSpawnPassed, boolean airSpawnPassed) {
ForgeDataScript handler = ScriptController.Instance.forgeScripts;
if (handler.isEnabled()) {
IPos attemptPosition = new ScriptBlockPos(blockPos);
IPos attemptPosition = NpcAPI.Instance().getIPos(blockPos);
CustomNPCsEvent.CNPCNaturalSpawnEvent event = new CustomNPCsEvent.CNPCNaturalSpawnEvent(naturalSpawn, attemptPosition, animalSpawnPassed, monsterSpawnPassed, liquidSpawnPassed, airSpawnPassed);
handler.callScript("onCNPCNaturalSpawn", event);
return NpcAPI.EVENT_BUS.post(event);
@@ -691,8 +691,8 @@ public class NoppesUtilServer {
return entity;
}
public static Entity spawnClone(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
public static Entity getEntityFromNBT(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
ServerCloneController.Instance.cleanTags(compound);
compound.setTag("Pos", NBTTags.nbtDoubleList(x + 0.5, y + 1, z + 0.5));
Entity entity = EntityList.createEntityFromNBT(compound, worldObj);
@@ -705,6 +705,15 @@ public class NoppesUtilServer {
npc.ticksExisted = 0;
npc.totalTicksAlive = 0;
}
return entity;
}
public static Entity spawnClone(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
Entity entity = NoppesUtilServer.getEntityFromNBT(compound,x,y,z,worldObj);
if(entity == null){
return null;
}
worldObj.spawnEntityInWorld(entity);
return entity;
}
@@ -103,7 +103,7 @@ public class ScriptItemEventHandler {
try {
if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem());
ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock(event.entityPlayer.worldObj, new BlockPos(event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ)));
ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock(NpcAPI.Instance().getIWorld(event.entityPlayer.worldObj), NpcAPI.Instance().getIPos(event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ)));
event.setCanceled(EventHooks.onScriptItemInteract(isw, eve));
}
} catch(Exception e) {}
@@ -119,7 +119,7 @@ public class ScriptPlayerEventHandler {
if(!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.getPlayer());
noppes.npcs.scripted.event.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.PlayerEvent.BreakEvent(scriptPlayer, NpcAPI.Instance().getIBlock(event.world, new BlockPos(event.x,event.y,event.z)), event.getExpToDrop());
noppes.npcs.scripted.event.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.PlayerEvent.BreakEvent(scriptPlayer, NpcAPI.Instance().getIBlock(NpcAPI.Instance().getIWorld(event.world), NpcAPI.Instance().getIPos(event.x,event.y,event.z)), event.getExpToDrop());
event.setCanceled(EventHooks.onPlayerBreak(handler, ev));
event.setExpToDrop(ev.exp);
}
@@ -19,6 +19,7 @@ import noppes.npcs.LogWriter;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.handler.ICloneHandler;
import noppes.npcs.scripted.interfaces.entity.IEntity;
import noppes.npcs.scripted.interfaces.IWorld;
@@ -209,10 +210,18 @@ public class ServerCloneController implements ICloneHandler {
}
}
public IEntity spawn(IPos pos, int tab, String name, IWorld world, boolean ignoreProtection) {
return this.spawn(pos.getX(),pos.getY(),pos.getZ(),tab,name,world,ignoreProtection);
}
public IEntity spawn(double x, double y, double z, int tab, String name, IWorld world) {
return spawn(x, y, z, tab, name, world, true);
}
public IEntity spawn(IPos pos, int tab, String name, IWorld world) {
return this.spawn(pos.getX(),pos.getY(),pos.getZ(),tab,name,world);
}
public IEntity[] getTab(int tab, IWorld world) {
File dir = new File(getDir(), tab + "");
if (!dir.exists() || !dir.isDirectory() || dir.listFiles() == null) {
@@ -2,6 +2,8 @@ package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.TransportController;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
public class TransportLocation implements ITransportLocation {
@@ -78,6 +80,16 @@ public class TransportLocation implements ITransportLocation {
this.posZ = z;
}
public void setPosition(IPos pos) {
this.posX = pos.getX();
this.posY = pos.getY();
this.posZ = pos.getZ();
}
public IPos getPos() {
return NpcAPI.Instance().getIPos(this.posX, this.posY, this.posZ);
}
public double getX() {
return posX;
}
@@ -250,7 +250,7 @@ public class JobSpawner extends JobInterface{
return null;
}
private boolean isEmpty(){
public boolean isEmpty(){
if(compound1 != null && compound1.hasKey("id"))
return false;
if(compound2 != null && compound2.hasKey("id"))
@@ -365,7 +365,7 @@ public class JobSpawner extends JobInterface{
return living;
}
private NBTTagCompound getCompound(int i) {
public NBTTagCompound getCompound(int i) {
if(i <= 1 && compound1 != null && compound1.hasKey("id")){
number = 1;
return compound1;
@@ -394,7 +394,7 @@ public class JobSpawner extends JobInterface{
}
private List<EntityLivingBase> getNearbySpawned(){
public List<EntityLivingBase> getNearbySpawned(){
List<EntityLivingBase> spawnList = new ArrayList<EntityLivingBase>();
List<EntityLivingBase> list = npc.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, npc.boundingBox.expand(40, 40, 40));
for(EntityLivingBase entity : list){
@@ -12,6 +12,7 @@ import noppes.npcs.controllers.data.PlayerTransportData;
import noppes.npcs.controllers.TransportController;
import noppes.npcs.controllers.data.TransportLocation;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
public class RoleTransporter extends RoleInterface{
@@ -77,12 +78,12 @@ public class RoleTransporter extends RoleInterface{
}
}
private void unlock(EntityPlayer player, TransportLocation loc){
public void unlock(EntityPlayer player, ITransportLocation loc){
PlayerTransportData data = PlayerDataController.instance.getPlayerData(player).transportData;
if(data.transports.contains(transportId))
return;
data.transports.add(transportId);
player.addChatMessage(new ChatComponentTranslation("transporter.unlock", loc.name));
player.addChatMessage(new ChatComponentTranslation("transporter.unlock", loc.getName()));
}
public TransportLocation getLocation(){
if(npc.isRemote())
@@ -94,9 +95,9 @@ public class RoleTransporter extends RoleInterface{
return loc != null && loc.id == transportId;
}
public void setTransport(TransportLocation location) {
transportId = location.id;
name = location.name;
public void setTransport(ITransportLocation location) {
transportId = location.getId();
name = location.getName();
}
}
+84 -57
View File
@@ -5,11 +5,6 @@
package noppes.npcs.scripted;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import cpw.mods.fml.common.eventhandler.EventBus;
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
import net.minecraft.block.Block;
@@ -19,13 +14,13 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.math.BlockPos;
@@ -34,24 +29,22 @@ import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.BiomeGenBase;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.containers.ContainerNpcInterface;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.entity.*;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.handler.*;
import noppes.npcs.scripted.interfaces.*;
import noppes.npcs.scripted.interfaces.entity.ICustomNpc;
import noppes.npcs.scripted.interfaces.entity.IEntity;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.gui.ICustomGui;
import noppes.npcs.scripted.interfaces.handler.data.IFaction;
import noppes.npcs.scripted.interfaces.handler.*;
import noppes.npcs.scripted.interfaces.handler.data.ISound;
import noppes.npcs.scripted.interfaces.item.IItemStack;
import noppes.npcs.scripted.interfaces.AbstractNpcAPI;
import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay;
import noppes.npcs.scripted.item.*;
import noppes.npcs.scripted.overlay.ScriptOverlay;
@@ -59,8 +52,13 @@ import noppes.npcs.util.JsonException;
import noppes.npcs.util.LRUHashMap;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class NpcAPI extends AbstractNpcAPI {
private static final Map<Integer, ScriptWorld> worldCache = new LRUHashMap(10);
private static final Map<Integer, ScriptWorld> worldCache = new LRUHashMap<>(10);
public static final EventBus EVENT_BUS = new EventBus();
private static AbstractNpcAPI instance = null;
@@ -110,7 +108,7 @@ public class NpcAPI extends AbstractNpcAPI {
@Override
public String[] getAllBiomeNames() {
List<String> biomes = new ArrayList<String>();
List<String> biomes = new ArrayList<>();
for (BiomeGenBase base : BiomeGenBase.getBiomeGenArray()) {
if (base != null && base.biomeName != null) {
biomes.add(base.biomeName);
@@ -120,7 +118,7 @@ public class NpcAPI extends AbstractNpcAPI {
return biomes.toArray(new String[]{});
}
public IEntity getIEntity(Entity entity) {
public IEntity<?> getIEntity(Entity entity) {
if(entity == null)
return null;
if(entity instanceof EntityNPCInterface)
@@ -130,26 +128,26 @@ public class NpcAPI extends AbstractNpcAPI {
if(data != null)
return data.base;
if(entity instanceof EntityPlayerMP)
data = new ScriptEntityData(new ScriptPlayer((EntityPlayerMP) entity));
data = new ScriptEntityData(new ScriptPlayer<>((EntityPlayerMP) entity));
else if(PixelmonHelper.isPixelmon(entity))
return new ScriptPixelmon((EntityTameable) entity);
return new ScriptPixelmon<EntityTameable>((EntityTameable) entity);
else if(entity instanceof EntityAnimal)
data = new ScriptEntityData(new ScriptAnimal((EntityAnimal) entity));
data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity));
else if(entity instanceof EntityMob)
data = new ScriptEntityData(new ScriptMonster((EntityMob) entity));
data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity));
else if(entity instanceof EntityLiving)
data = new ScriptEntityData(new ScriptLiving((EntityLiving) entity));
data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity));
else if(entity instanceof EntityLivingBase)
data = new ScriptEntityData(new ScriptLivingBase((EntityLivingBase)entity));
data = new ScriptEntityData(new ScriptLivingBase<>((EntityLivingBase)entity));
else
data = new ScriptEntityData(new ScriptEntity(entity));
data = new ScriptEntityData(new ScriptEntity<>(entity));
entity.registerExtendedProperties("ScriptedObject", data);
return data.base;
}
}
public IEntity[] getLoadedEntities() {
ArrayList<IEntity> list = new ArrayList<>();
public IEntity<?>[] getLoadedEntities() {
ArrayList<IEntity<?>> list = new ArrayList<>();
for (IWorld world : worldCache.values()) {
for (Object obj : world.getMCWorld().loadedEntityList) {
@@ -160,16 +158,44 @@ public class NpcAPI extends AbstractNpcAPI {
return list.toArray(new IEntity[0]);
}
public IBlock getIBlock(World world, BlockPos pos) {
return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos);
public IBlock getIBlock(IWorld world, int x, int y, int z) {
Block block = world.getMCWorld().getBlock(x, y, z);
if(block == null || block.isAir(world.getMCWorld(), x, y, z))
return null;
return new ScriptBlock(world.getMCWorld(), world.getMCWorld().getBlock(x, y, z), new BlockPos(x,y,z));
}
public IBlock getIBlock(World world, Block block, BlockPos pos) {
return new ScriptBlock(world, block, pos);
public IBlock getIBlock(IWorld world, IPos pos) {
return this.getIBlock(world, pos.getX(),pos.getY(),pos.getZ());
}
public IBlock getIBlock(World world, int x, int y, int z) {
return new ScriptBlock(world, world.getBlock(x, y, z), new BlockPos(x,y,z));
public ITileEntity getITileEntity(IWorld world, IPos pos) {
return new ScriptTileEntity<>(world.getMCWorld().getTileEntity(pos.getX(), pos.getY(),pos.getZ()));
}
public ITileEntity getITileEntity(IWorld world, int x, int y, int z) {
return new ScriptTileEntity<>(world.getMCWorld().getTileEntity(x,y,z));
}
public ITileEntity getITileEntity(TileEntity tileEntity) {
return new ScriptTileEntity<>(tileEntity);
}
public IPos getIPos(BlockPos pos) {
return new ScriptBlockPos(pos);
}
public IPos getIPos(int x, int y, int z) {
return new ScriptBlockPos(new BlockPos(x,y,z));
}
public IPos getIPos(double x, double y, double z) {
return this.getIPos((int)x,(int)y,(int)z);
}
public IPos getIPos(float x, float y, float z) {
return this.getIPos((int)x,(int)y,(int)z);
}
public INbt getINbt(NBTTagCompound nbtTagCompound) {
@@ -181,34 +207,38 @@ public class NpcAPI extends AbstractNpcAPI {
try {
return this.getINbt(NBTJsonUtil.Convert(str));
} catch (JsonException var3) {
throw new CustomNPCsException(var3, "Failed converting " + str, new Object[0]);
throw new CustomNPCsException(var3, "Failed converting " + str);
}
} else {
throw new CustomNPCsException("Cant cast empty string to nbt", new Object[0]);
throw new CustomNPCsException("Cant cast empty string to nbt");
}
}
public ICustomNpc createNPC(World world) {
if (world.isRemote) {
public ICustomNpc<?> createNPC(IWorld world) {
if (world.getMCWorld().isRemote) {
return null;
} else {
EntityCustomNpc npc = new EntityCustomNpc(world);
EntityCustomNpc npc = new EntityCustomNpc(world.getMCWorld());
return npc.wrappedNPC;
}
}
public ICustomNpc spawnNPC(World world, int x, int y, int z) {
if (world.isRemote) {
public ICustomNpc<?> spawnNPC(IWorld world, int x, int y, int z) {
if (world.getMCWorld().isRemote) {
return null;
} else {
EntityCustomNpc npc = new EntityCustomNpc(world);
npc.setPositionAndRotation((double)x + 0.5D, (double)y, (double)z + 0.5D, 0.0F, 0.0F);
EntityCustomNpc npc = new EntityCustomNpc(world.getMCWorld());
npc.setPositionAndRotation((double)x + 0.5D, y, (double)z + 0.5D, 0.0F, 0.0F);
npc.setHealth(npc.getMaxHealth());
world.spawnEntityInWorld(npc);
world.getMCWorld().spawnEntityInWorld(npc);
return npc.wrappedNPC;
}
}
public ICustomNpc<?> spawnNPC(IWorld world, IPos pos) {
return this.spawnNPC(world, pos.getX(), pos.getY(), pos.getZ());
}
public static AbstractNpcAPI Instance() {
if (instance == null) {
instance = new NpcAPI();
@@ -250,25 +280,22 @@ public class NpcAPI extends AbstractNpcAPI {
ScriptWorld w = worldCache.get(world.provider.dimensionId);
if (w != null) {
w.world.provider.dimensionId = world.provider.dimensionId;
return w;
} else {
worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world.provider.dimensionId));
return w;
}
return w;
}
public IWorld getIWorld(int dimensionId) {
WorldServer[] var2 = CustomNpcs.getServer().worldServers;
int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) {
WorldServer world = var2[var4];
for (WorldServer world : var2) {
if (world.provider.dimensionId == dimensionId) {
return this.getIWorld(world);
}
}
throw new CustomNPCsException("Unknown dimension id: " + dimensionId, new Object[0]);
throw new CustomNPCsException("Unknown dimension id: " + dimensionId);
}
public IContainer getIContainer(IInventory inventory) {
@@ -276,12 +303,12 @@ public class NpcAPI extends AbstractNpcAPI {
}
public IContainer getIContainer(Container container) {
return (IContainer)(container instanceof ContainerNpcInterface ? ContainerNpcInterface.getOrCreateIContainer((ContainerNpcInterface)container) : new ScriptContainer(container));
return container instanceof ContainerNpcInterface ? ContainerNpcInterface.getOrCreateIContainer((ContainerNpcInterface)container) : new ScriptContainer(container);
}
private void checkWorld() {
if (CustomNpcs.getServer() == null || CustomNpcs.getServer().isServerStopped()) {
throw new CustomNPCsException("No world is loaded right now", new Object[0]);
throw new CustomNPCsException("No world is loaded right now");
}
}
@@ -308,7 +335,7 @@ public class NpcAPI extends AbstractNpcAPI {
return new ScriptDamageSource(damagesource);
}
public IDamageSource getIDamageSource(IEntity entity) {
public IDamageSource getIDamageSource(IEntity<?> entity) {
if(entity.getType() == 1)//if player
return new ScriptDamageSource(new EntityDamageSource("player",entity.getMCEntity()));
else
@@ -324,29 +351,29 @@ public class NpcAPI extends AbstractNpcAPI {
return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender);
}
public IPlayer[] getAllServerPlayers(){
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
IPlayer[] arr = new IPlayer[list.size()];
public IPlayer<?>[] getAllServerPlayers(){
List<?> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
IPlayer<?>[] arr = new IPlayer[list.size()];
for(int i = 0; i < list.size(); i++){
arr[i] = (IPlayer) NpcAPI.Instance().getIEntity(list.get(i));
arr[i] = (IPlayer<?>) NpcAPI.Instance().getIEntity((EntityPlayerMP)list.get(i));
}
return arr;
}
public String[] getPlayerNames() {
IPlayer[] players = getAllServerPlayers();
IPlayer<?>[] players = getAllServerPlayers();
String[] names = new String[players.length];
for (int i = 0; i < names.length; ++i) names[i] = players[i].getDisplayName();
return names;
}
public void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch){
public void playSoundAtEntity(IEntity<?> entity, String sound, float volume, float pitch){
entity.getWorld().getMCWorld().playSoundAtEntity(entity.getMCEntity(), sound, volume, pitch);
}
public void playSoundToNearExcept(IPlayer player, String sound, float volume, float pitch){
player.getWorld().getMCWorld().playSoundToNearExcept((EntityPlayerMP) player.getMCEntity(), sound, volume, pitch);
public void playSoundToNearExcept(IPlayer<?> player, String sound, float volume, float pitch){
player.getWorld().getMCWorld().playSoundToNearExcept(player.getMCEntity(), sound, volume, pitch);
}
public String getMOTD()
@@ -30,7 +30,7 @@ public class ScriptBlock implements IBlock {
this.world = NpcAPI.Instance().getIWorld(world);
this.block = block;
this.pos = pos;
this.bPos = new ScriptBlockPos(pos);
this.bPos = NpcAPI.Instance().getIPos(pos);
this.tile = new ScriptTileEntity<>(world.getTileEntity(pos.getX(),pos.getY(), pos.getZ()));
}
@@ -64,13 +64,13 @@ public class ScriptBlock implements IBlock {
return this;
} else {
this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block);
return NpcAPI.Instance().getIBlock(world.getMCWorld(), block, new BlockPos(getX(),getY(),getZ()));
return NpcAPI.Instance().getIBlock(world, getX(),getY(),getZ());
}
}
public IBlock setBlock(IBlock block) {
this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block.getMCBlock());
return NpcAPI.Instance().getIBlock(world.getMCWorld(), block.getMCBlock(), new BlockPos(getX(),getY(),getZ()));
return NpcAPI.Instance().getIBlock(world, getX(),getY(),getZ());
}
public boolean isContainer() {
@@ -10,7 +10,7 @@ import net.minecraft.util.math.BlockPos;
import noppes.npcs.scripted.interfaces.IPos;
public class ScriptBlockPos implements IPos {
private BlockPos blockPos;
public BlockPos blockPos;
public ScriptBlockPos(BlockPos pos) {
this.blockPos = pos;
@@ -29,75 +29,75 @@ public class ScriptBlockPos implements IPos {
}
public IPos up() {
return new ScriptBlockPos(this.blockPos.up());
return NpcAPI.Instance().getIPos(this.blockPos.up());
}
public IPos up(int n) {
return new ScriptBlockPos(this.blockPos.up(n));
return NpcAPI.Instance().getIPos(this.blockPos.up(n));
}
public IPos down() {
return new ScriptBlockPos(this.blockPos.down());
return NpcAPI.Instance().getIPos(this.blockPos.down());
}
public IPos down(int n) {
return new ScriptBlockPos(this.blockPos.down(n));
return NpcAPI.Instance().getIPos(this.blockPos.down(n));
}
public IPos north() {
return new ScriptBlockPos(this.blockPos.north());
return NpcAPI.Instance().getIPos(this.blockPos.north());
}
public IPos north(int n) {
return new ScriptBlockPos(this.blockPos.north(n));
return NpcAPI.Instance().getIPos(this.blockPos.north(n));
}
public IPos east() {
return new ScriptBlockPos(this.blockPos.east());
return NpcAPI.Instance().getIPos(this.blockPos.east());
}
public IPos east(int n) {
return new ScriptBlockPos(this.blockPos.east(n));
return NpcAPI.Instance().getIPos(this.blockPos.east(n));
}
public IPos south() {
return new ScriptBlockPos(this.blockPos.south());
return NpcAPI.Instance().getIPos(this.blockPos.south());
}
public IPos south(int n) {
return new ScriptBlockPos(this.blockPos.south(n));
return NpcAPI.Instance().getIPos(this.blockPos.south(n));
}
public IPos west() {
return new ScriptBlockPos(this.blockPos.west());
return NpcAPI.Instance().getIPos(this.blockPos.west());
}
public IPos west(int n) {
return new ScriptBlockPos(this.blockPos.west(n));
return NpcAPI.Instance().getIPos(this.blockPos.west(n));
}
public IPos add(int x, int y, int z) {
return new ScriptBlockPos(this.blockPos.add(x, y, z));
return NpcAPI.Instance().getIPos(this.blockPos.add(x, y, z));
}
public IPos add(IPos pos) {
return new ScriptBlockPos(this.blockPos.add(this.blockPos));
return NpcAPI.Instance().getIPos(this.blockPos.add(this.blockPos));
}
public IPos subtract(int x, int y, int z) {
return new ScriptBlockPos(this.blockPos.add(-x, -y, -z));
return NpcAPI.Instance().getIPos(this.blockPos.add(-x, -y, -z));
}
public IPos subtract(IPos pos) {
return new ScriptBlockPos(this.blockPos.add(-pos.getX(), -pos.getY(), -pos.getZ()));
return NpcAPI.Instance().getIPos(this.blockPos.add(-pos.getX(), -pos.getY(), -pos.getZ()));
}
public IPos offset(int direction) {
return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction]));
return NpcAPI.Instance().getIPos(this.blockPos.offset(EnumFacing.values()[direction]));
}
public IPos offset(int direction, int n) {
return new ScriptBlockPos(this.blockPos.offset(EnumFacing.values()[direction], n));
return NpcAPI.Instance().getIPos(this.blockPos.offset(EnumFacing.values()[direction], n));
}
public double[] normalize() {
@@ -111,4 +111,8 @@ public class ScriptBlockPos implements IPos {
double d2 = (double)(this.getZ() - pos.getZ());
return Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
}
public BlockPos getMCPos() {
return this.blockPos;
}
}
@@ -3,6 +3,7 @@ package noppes.npcs.scripted;
import net.minecraft.nbt.*;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.scripted.interfaces.IParticle;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.interfaces.entity.IEntity;
@@ -230,6 +231,13 @@ public class ScriptParticle implements IParticle {
return z;
}
public void setPosition(IPos pos) {
this.setPosition(pos.getX(),pos.getY(),pos.getZ());
}
public void getPos() {
NpcAPI.Instance().getIPos(x,y,z);
}
public void setMotion(double motionX, double motionY, double motionZ, float gravity){
this.motionX = motionX;
this.motionY = motionY;
@@ -156,7 +156,7 @@ public class ScriptSound implements ISound {
}
public IPos getPos() {
return new ScriptBlockPos(new BlockPos(xPosF,yPosF,zPosF));
return NpcAPI.Instance().getIPos(xPosF, yPosF, zPosF);
}
public float getX() {
@@ -4,27 +4,39 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.interfaces.IBlock;
import noppes.npcs.scripted.interfaces.INbt;
import noppes.npcs.scripted.interfaces.ITileEntity;
import noppes.npcs.scripted.interfaces.*;
public class ScriptTileEntity<T extends TileEntity> implements ITileEntity {
protected T tileEntity;
protected IWorld world;
public ScriptTileEntity(T tileEntity) { this.tileEntity = tileEntity; }
public ScriptTileEntity(T tileEntity) {
this.tileEntity = tileEntity;
this.world = NpcAPI.Instance().getIWorld(tileEntity.getWorldObj());
}
public int getBlockMetadata(){
return tileEntity.getBlockMetadata();
}
public ScriptWorld getWorld(){
return (ScriptWorld) NpcAPI.Instance().getIWorld((WorldServer) tileEntity.getWorldObj());
public IWorld getWorld(){
return world;
}
public void setWorld(IWorld world) {
this.tileEntity.setWorldObj(world.getMCWorld());
this.world = world;
}
public TileEntity getMCTileEntity() {
return this.tileEntity;
}
public void markDirty()
{
this.tileEntity.markDirty();
}
public void readFromNBT(INbt nbt){
this.tileEntity.readFromNBT(nbt.getMCNBT());
}
@@ -33,8 +45,12 @@ public class ScriptTileEntity<T extends TileEntity> implements ITileEntity {
return this.tileEntity.getDistanceFrom(x,y,z);
}
public double getDistanceFrom(IPos pos){
return this.getDistanceFrom(pos.getX(),pos.getY(),pos.getZ());
}
public IBlock getBlockType(){
return NpcAPI.Instance().getIBlock(tileEntity.getWorldObj(), tileEntity.getBlockType(), new BlockPos(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
return NpcAPI.Instance().getIBlock(world, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
}
public boolean isInvalid(){
@@ -18,7 +18,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilServer;
@@ -34,9 +33,10 @@ import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.handler.data.ISound;
import noppes.npcs.scripted.interfaces.item.IItemStack;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.scoreboard.ScriptScoreboard;
public class ScriptWorld implements IWorld {
private static Map<String,Object> tempData = new HashMap<String,Object>();
private static final Map<String,Object> tempData = new HashMap<>();
public WorldServer world;
public ScriptWorld(WorldServer world){
this.world = world;
@@ -60,7 +60,7 @@ public class ScriptWorld implements IWorld {
public long getTime(){
return world.getWorldTime();
}
/**
* @return The total world time
*/
@@ -79,72 +79,128 @@ public class ScriptWorld implements IWorld {
* @return The block at the given position. Returns null if there isn't a block
*/
public IBlock getBlock(int x, int y, int z){
Block block = world.getBlock(x, y, z);
if(block == null || block.isAir(world, x, y, z))
return null;
return NpcAPI.Instance().getIBlock(world, block, new BlockPos(x,y,z));
return NpcAPI.Instance().getIBlock(this, x,y,z);
}
/**
* @param pos
* @return The block at the given position. Returns null if there isn't a block
*/
public IBlock getBlock(IPos pos){
return NpcAPI.Instance().getIBlock(this, pos);
}
public boolean isBlockFreezable(IPos pos) {
return this.isBlockFreezable(pos.getX(),pos.getY(),pos.getZ());
}
public boolean isBlockFreezable(int x, int y, int z){
return world.isBlockFreezable(x,y,z);
}
public boolean isBlockFreezableNaturally(IPos pos) {
return this.isBlockFreezableNaturally(pos.getX(),pos.getY(),pos.getZ());
}
public boolean isBlockFreezableNaturally(int x, int y, int z){
return world.isBlockFreezableNaturally(x,y,z);
}
public boolean canBlockFreeze(IPos pos, boolean adjacentToWater) {
return this.canBlockFreeze(pos.getX(),pos.getY(),pos.getZ(), adjacentToWater);
}
public boolean canBlockFreeze(int x, int y, int z, boolean adjacentToWater){
return world.canBlockFreeze(x,y,z,adjacentToWater);
}
public boolean canBlockFreezeBody(IPos pos, boolean adjacentToWater) {
return this.canBlockFreezeBody(pos.getX(),pos.getY(),pos.getZ(), adjacentToWater);
}
public boolean canBlockFreezeBody(int x, int y, int z, boolean adjacentToWater){
return world.canBlockFreezeBody(x,y,z,adjacentToWater);
}
public boolean canSnowAt(IPos pos, boolean checkLight) {
return this.canSnowAt(pos.getX(),pos.getY(),pos.getZ(), checkLight);
}
public boolean canSnowAt(int x, int y, int z, boolean checkLight){
return world.func_147478_e(x,y,z,checkLight);
}
public boolean canSnowAtBody(IPos pos, boolean checkLight) {
return this.canSnowAtBody(pos.getX(),pos.getY(),pos.getZ(), checkLight);
}
public boolean canSnowAtBody(int x, int y, int z, boolean checkLight){
return world.canSnowAtBody(x,y,z,checkLight);
}
public IBlock getTopBlock(int x, int z){
int y;
for (y = 63; !world.isAirBlock(x, y + 1, z); ++y) {;}
Block block = world.getBlock(x, y, z);
return NpcAPI.Instance().getIBlock(this, x, world.getTopSolidOrLiquidBlock(x,z) ,z);
}
return NpcAPI.Instance().getIBlock(world, block, new BlockPos(x,y,z));
public IBlock getTopBlock(IPos pos) {
return this.getTopBlock(pos.getX(),pos.getZ());
}
public int getHeightValue(int x, int z){
return world.getHeightValue(x,z);
}
public int getHeightValue(IPos pos) {
return this.getHeightValue(pos.getX(),pos.getZ());
}
public int getChunkHeightMapMinimum(int x, int z){
return world.getChunkHeightMapMinimum(x,z);
}
public int getChunkHeightMapMinimum(IPos pos){
return this.getChunkHeightMapMinimum(pos.getX(),pos.getZ());
}
public int getBlockMetadata(int x, int y, int z){
return world.getBlockMetadata(x,y,z);
}
public int getBlockMetadata(IPos pos){
return this.getBlockMetadata(pos.getX(),pos.getY(),pos.getZ());
}
public boolean setBlockMetadataWithNotify(int x, int y, int z, int metadata, int flag){
return world.setBlockMetadataWithNotify(x,y,z,metadata,flag);
}
public boolean canBlockSeeTheSky(int x, int y, int z){
return world.canBlockSeeTheSky(x,y,z);
public boolean setBlockMetadataWithNotify(IPos pos, int metadata, int flag){
return this.setBlockMetadataWithNotify(pos.getX(),pos.getY(),pos.getZ(), metadata, flag);
}
public boolean canSeeSky(int x, int y, int z) {
return world.canBlockSeeTheSky(x, y, z);
}
public boolean canSeeSky(IPos pos) {
return canSeeSky(pos.getX(), pos.getY(), pos.getZ());
}
public int getFullBlockLightValue(int x, int y, int z){
return world.getFullBlockLightValue(x,y,z);
}
public int getFullBlockLightValue(IPos pos){
return this.getFullBlockLightValue(pos.getX(),pos.getY(),pos.getZ());
}
public int getBlockLightValue(int x, int y, int z){
return world.getBlockLightValue(x,y,z);
}
public int getBlockLightValue(IPos pos){
return this.getBlockLightValue(pos.getX(),pos.getY(),pos.getZ());
}
public void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch){
world.playSoundAtEntity(entity.getMCEntity(), sound, volume, pitch);
}
@@ -206,6 +262,15 @@ public class ScriptWorld implements IWorld {
return world.spawnEntityInWorld(entity.getMCEntity());
}
public boolean spawnEntityInWorld(IEntity entity, double x, double y, double z){
entity.setPosition(x, y, z);
return this.spawnEntityInWorld(entity);
}
public boolean spawnEntityInWorld(IEntity entity, IPos pos) {
return this.spawnEntityInWorld(entity, pos.getX(), pos.getY(), pos.getZ());
}
public IPlayer getClosestPlayerToEntity(IEntity entity, double range){
return (IPlayer) NpcAPI.Instance().getIEntity(world.getClosestPlayerToEntity(entity.getMCEntity(), range));
}
@@ -214,6 +279,10 @@ public class ScriptWorld implements IWorld {
return (IPlayer) NpcAPI.Instance().getIEntity(world.getClosestPlayer(x,y,z, range));
}
public IPlayer getClosestPlayer(IPos pos, double range){
return this.getClosestPlayer(pos.getX(),pos.getY(),pos.getZ(), range);
}
public IPlayer getClosestVulnerablePlayerToEntity(IEntity entity, double range){
return (IPlayer) NpcAPI.Instance().getIEntity(world.getClosestVulnerablePlayerToEntity(entity.getMCEntity(), range));
}
@@ -222,6 +291,10 @@ public class ScriptWorld implements IWorld {
return (IPlayer) NpcAPI.Instance().getIEntity(world.getClosestVulnerablePlayer(x,y,z, range));
}
public IPlayer getClosestVulnerablePlayer(IPos pos, double range){
return this.getClosestVulnerablePlayer(pos.getX(),pos.getY(),pos.getZ(), range);
}
public int countEntities(IEntity entity){
return world.countEntities(entity.getMCEntity().getClass());
}
@@ -246,8 +319,8 @@ public class ScriptWorld implements IWorld {
}
list.sort((e1, e2) -> {
double dist1 = e1.getPos().distanceTo(position);
double dist2 = e2.getPos().distanceTo(position);
double dist1 = e1.getPosition().distanceTo(position);
double dist2 = e2.getPosition().distanceTo(position);
if (dist1 > dist2) {
return 1;
@@ -261,21 +334,33 @@ public class ScriptWorld implements IWorld {
}
public IEntity[] getEntitiesNear(double x, double y, double z, double range) {
return getEntitiesNear(new ScriptBlockPos(new BlockPos(x,y,z)), range);
return getEntitiesNear(NpcAPI.Instance().getIPos(x,y,z), range);
}
public void setTileEntity(int x, int y, int z, ITileEntity tileEntity){
world.setTileEntity(x,y,z,tileEntity.getMCTileEntity());
}
public void setTileEntity(IPos pos, ITileEntity tileEntity){
this.setTileEntity(pos.getX(),pos.getY(),pos.getZ(),tileEntity);
}
public void removeTileEntity(int x, int y, int z){
world.removeTileEntity(x,y,z);
}
public void removeTileEntity(IPos pos){
this.removeTileEntity(pos.getX(),pos.getY(),pos.getZ());
}
public boolean isBlockFullCube(int x, int y, int z){
return world.func_147469_q(x,y,z);
}
public boolean isBlockFullCube(IPos pos){
return this.isBlockFullCube(pos.getX(),pos.getY(),pos.getZ());
}
public long getSeed(){
return world.getSeed();
}
@@ -284,20 +369,24 @@ public class ScriptWorld implements IWorld {
world.setSpawnLocation(x,y,z);
}
public void setSpawnLocation(IPos pos){
this.setSpawnLocation(pos.getX(),pos.getY(),pos.getZ());
}
public boolean canLightningStrikeAt(int x, int y, int z){
return world.canLightningStrikeAt(x,y,z);
}
public boolean canLightningStrikeAt(IPos pos){
return this.canLightningStrikeAt(pos.getX(),pos.getY(),pos.getZ());
}
public boolean isBlockHighHumidity(int x, int y, int z){
return world.isBlockHighHumidity(x,y,z);
}
/**
* @param pos
* @return The block at the given position. Returns null if there isn't a block
*/
public IBlock getBlock(IPos pos){
return getBlock(pos.getX(), pos.getY(), pos.getZ());
public boolean isBlockHighHumidity(IPos pos){
return this.canLightningStrikeAt(pos.getX(),pos.getY(),pos.getZ());
}
/**
@@ -309,10 +398,10 @@ public class ScriptWorld implements IWorld {
*/
public String getSignText(int x, int y, int z){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileBigSign)
return ((TileBigSign)tile).getText();
if(tile instanceof TileEntitySign){
TileEntitySign tileSign = (TileEntitySign)tile;
String s = tileSign.signText[0] + "\n";
@@ -321,18 +410,26 @@ public class ScriptWorld implements IWorld {
s += tileSign.signText[3];
return s;
}
return null;
}
public String getSignText(IPos pos) {
return this.getSignText(pos.getX(),pos.getY(),pos.getZ());
}
public void setBlock(int x, int y, int z, IBlock block){
if(block == null || block.getMCBlock().isAir(world, x, y, z)){
removeBlock(x, y, z);
this.removeBlock(x, y, z);
return;
}
world.setBlock(x, y, z, block.getMCBlock());
}
public void setBlock(IPos pos, IBlock block){
this.setBlock(pos.getX(),pos.getY(),pos.getZ(),block);
}
/**
* @param x World position x
* @param y World position y
@@ -341,7 +438,7 @@ public class ScriptWorld implements IWorld {
*/
public void setBlock(int x, int y, int z, IItemStack item){
if(item == null){
removeBlock(x, y, z);
this.removeBlock(x, y, z);
return;
}
Block block = Block.getBlockFromItem(item.getMCItemStack().getItem());
@@ -349,7 +446,11 @@ public class ScriptWorld implements IWorld {
return;
world.setBlock(x, y, z, block);
}
public void setBlock(IPos pos, IItemStack itemStack){
this.setBlock(pos.getX(),pos.getY(),pos.getZ(),itemStack);
}
/**
* @param x World position x
* @param y World position y
@@ -359,6 +460,10 @@ public class ScriptWorld implements IWorld {
world.setBlock(x, y, z, Blocks.air);
}
public void removeBlock(IPos pos){
this.removeBlock(pos.getX(),pos.getY(),pos.getZ());
}
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
if (startPos.length != 3 || lookVector.length != 3) {
return null;
@@ -369,7 +474,7 @@ public class ScriptWorld implements IWorld {
while (rep++ < maxDistance + 10) {
currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]);
pos = new ScriptBlockPos(new BlockPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord));
pos = NpcAPI.Instance().getIPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord);
IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
if (block != null && stopOnBlock) {
@@ -458,7 +563,7 @@ public class ScriptWorld implements IWorld {
while (rep++ < maxDistance + 10) {
currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]);
IPos pos = new ScriptBlockPos(new BlockPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord));
IPos pos = NpcAPI.Instance().getIPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord);
IBlock block = getBlock(pos);
if (block != null && stopOnBlock) {
@@ -503,14 +608,6 @@ public class ScriptWorld implements IWorld {
return rayCastEntities(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance, offset, range, true, false, true);
}
public boolean canSeeSky(int x, int y, int z) {
return world.canBlockSeeTheSky(x, y, z);
}
public boolean canSeeSky(IPos pos) {
return canSeeSky(pos.getX(), pos.getY(), pos.getZ());
}
/**
* @param name The name of the player to be returned
* @return The Player with name. Null is returned when the player isnt found
@@ -525,7 +622,7 @@ public class ScriptWorld implements IWorld {
public IPlayer getPlayerByUUID(String uuid){
return (IPlayer) NpcAPI.Instance().getIEntity(world.func_152378_a(UUID.fromString(uuid)));
}
/**
* @param time The world time to be set
*/
@@ -539,21 +636,21 @@ public class ScriptWorld implements IWorld {
public boolean isDay(){
return world.getWorldTime() % 24000 < 12000;
}
/**
* @return Whether or not its currently raining
*/
public boolean isRaining(){
return world.getWorldInfo().isRaining();
}
/**
* @param bo Set if it's raining
*/
public void setRaining(boolean bo){
world.getWorldInfo().setRaining(bo);
}
/**
* @param x The x position
* @param y The y position
@@ -562,7 +659,11 @@ public class ScriptWorld implements IWorld {
public void thunderStrike(double x, double y, double z){
world.addWeatherEffect(new EntityLightningBolt(world, x, y, z));
}
public void thunderStrike(IPos pos){
this.thunderStrike(pos.getX(),pos.getY(),pos.getZ());
}
/**
* Sends a packet from the server to the client everytime its called. Probably should not use this too much.
* @param particle Particle name. Particle name list: http://minecraft.gamepedia.com/Particles
@@ -578,7 +679,11 @@ public class ScriptWorld implements IWorld {
public void spawnParticle(String particle, double x, double y, double z, double dx, double dy, double dz, double speed, int count){
world.func_147487_a(particle, x, y, z, count, dx, dy, dz, speed);
}
public void spawnParticle(String particle, IPos pos, double dx, double dy, double dz, double speed, int count){
this.spawnParticle(particle, pos.getX(), pos.getY(), pos.getZ(), dx, dy, dz, speed, count);
}
/**
* @param id The items name
* @param damage The damage value
@@ -605,7 +710,7 @@ public class ScriptWorld implements IWorld {
public Object getTempData(String key){
return tempData.get(key);
}
/**
* Tempdata gets cleared when the server restarts. All worlds share the same temp data.
* @param key The key for the data stored
@@ -614,7 +719,7 @@ public class ScriptWorld implements IWorld {
public void setTempData(String key, Object value){
tempData.put(key, value);
}
/**
* @param key The key thats going to be tested against the temp data
* @return Whether or not temp data containes the key
@@ -622,21 +727,21 @@ public class ScriptWorld implements IWorld {
public boolean hasTempData(String key){
return tempData.containsKey(key);
}
/**
* @param key The key for the temp data to be removed
*/
public void removeTempData(String key){
tempData.remove(key);
}
/**
* Removes all tempdata
*/
public void clearTempData(){
tempData.clear();
}
/**
* @param key The key of the data to be returned
* @return Returns the stored data
@@ -650,7 +755,7 @@ public class ScriptWorld implements IWorld {
return ((NBTPrimitive)base).func_150286_g();
return ((NBTTagString)base).func_150285_a_();
}
/**
* Stored data persists through world restart. Unlike tempdata only Strings and Numbers can be saved
* @param key The key for the data stored
@@ -664,7 +769,7 @@ public class ScriptWorld implements IWorld {
compound.setString(key, (String)value);
ScriptController.Instance.shouldSave = true;
}
/**
* @param key The key of the data to be checked
* @return Returns whether or not the stored data contains the key
@@ -672,7 +777,7 @@ public class ScriptWorld implements IWorld {
public boolean hasStoredData(String key){
return ScriptController.Instance.compound.hasKey(key);
}
/**
* @param key The key of the data to be removed
*/
@@ -680,7 +785,7 @@ public class ScriptWorld implements IWorld {
ScriptController.Instance.compound.removeTag(key);
ScriptController.Instance.shouldSave = true;
}
/**
* Remove all stored data
*/
@@ -688,7 +793,7 @@ public class ScriptWorld implements IWorld {
ScriptController.Instance.compound = new NBTTagCompound();
ScriptController.Instance.shouldSave = true;
}
/**
* @param x Position x
* @param y Position y
@@ -701,6 +806,10 @@ public class ScriptWorld implements IWorld {
world.newExplosion(null, x, y, z, range, fire, grief);
}
public void explode(IPos pos, float range, boolean fire, boolean grief){
this.explode(pos.getX(),pos.getY(),pos.getZ(),range,fire,grief);
}
@Deprecated
public IPlayer[] getAllServerPlayers(){
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
@@ -708,7 +817,7 @@ public class ScriptWorld implements IWorld {
for(int i = 0; i < list.size(); i++){
arr[i] = (IPlayer) NpcAPI.Instance().getIEntity(list.get(i));
}
return arr;
}
@@ -729,7 +838,11 @@ public class ScriptWorld implements IWorld {
public String getBiomeName(int x, int z){
return world.getBiomeGenForCoords(x, z).biomeName;
}
public String getBiomeName(IPos pos){
return this.getBiomeName(pos.getX(),pos.getZ());
}
/**
* Lets you spawn a server side cloned entity
* @param x The x position the clone will be spawned at
@@ -752,10 +865,18 @@ public class ScriptWorld implements IWorld {
return entity == null ? null : NpcAPI.Instance().getIEntity(entity);
}
public IEntity spawnClone(IPos pos, int tab, String name, boolean ignoreProtection) {
return this.spawnClone(pos.getX(),pos.getY(),pos.getZ(),tab,name,ignoreProtection);
}
public IEntity spawnClone(int x, int y, int z, int tab, String name) {
return this.spawnClone(x,y,z,tab,name,true);
}
public IEntity spawnClone(IPos pos, int tab, String name) {
return this.spawnClone(pos.getX(),pos.getY(),pos.getZ(),tab,name);
}
public ScriptScoreboard getScoreboard(){
return new ScriptScoreboard();
}
@@ -1,13 +1,19 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.entity.IAnimal;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.item.IItemStack;
public class ScriptAnimal<T extends EntityAnimal> extends ScriptLiving<T> implements IAnimal {
protected T entity;
public ScriptAnimal(T entity) {
super(entity);
this.entity = entity;
}
@Override
@@ -15,8 +21,35 @@ public class ScriptAnimal<T extends EntityAnimal> extends ScriptLiving<T> implem
return EntityType.ANIMAL;
}
/**
* Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
* the animal type)
*/
public boolean isBreedingItem(IItemStack itemStack) {
return this.entity.isBreedingItem(itemStack.getMCItemStack());
}
/**
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
*/
public boolean interact(IPlayer player) {
return this.entity.interact((EntityPlayer) player.getMCEntity());
}
public boolean isInLove() {
return this.entity.isInLove();
}
public void resetInLove() {
this.entity.resetInLove();
}
public boolean canMateWith(IAnimal animal) {
return this.entity.canMateWith((EntityAnimal) animal.getMCEntity());
}
@Override
public boolean typeOf(int type){
return type == EntityType.ANIMAL?true:super.typeOf(type);
return type == EntityType.ANIMAL || super.typeOf(type);
}
}
@@ -363,6 +363,14 @@ public class ScriptEntity<T extends Entity> implements IEntity {
this.setMotionZ(z);
}
public void setMotion(IPos pos) {
this.setMotion(pos.getX(),pos.getY(),pos.getZ());
}
public IPos getMotion() {
return NpcAPI.Instance().getIPos(entity.motionX,entity.motionY,entity.motionZ);
}
public boolean isAirborne(){
return entity.isAirBorne;
}
@@ -398,13 +406,21 @@ public class ScriptEntity<T extends Entity> implements IEntity {
}
public IPos getPos() {
return new ScriptBlockPos(new BlockPos(entity.posX,entity.posY,entity.posZ));
return NpcAPI.Instance().getIPos(entity.posX, entity.posY, entity.posZ);
}
public IPos getPosition() {
return getPos();
}
public void setPos(IPos pos) {
this.entity.setPosition((double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F));
}
public void setPosition(IPos pos) {
this.setPos(pos);
}
public int getDimension(){
return entity.dimension;
}
@@ -730,6 +746,10 @@ public class ScriptEntity<T extends Entity> implements IEntity {
entity.velocityChanged = true;
}
public void knockback(IPos pos, float direction){
this.knockback(pos.getX(),pos.getY(),pos.getZ(),direction);
}
public void setImmune(int ticks) {
entity.hurtResistantTime = ticks;
};
@@ -789,6 +809,11 @@ public class ScriptEntity<T extends Entity> implements IEntity {
this.entity.readFromNBT(nbt.getMCNBT());
}
public INbt getNbtOptional() {
NBTTagCompound compound = new NBTTagCompound();
return this.entity.writeToNBTOptional(compound) ? NpcAPI.Instance().getINbt(compound) : null;
}
public void storeAsClone(int tab, String name) {
NBTTagCompound compound = new NBTTagCompound();
if (!this.entity.writeToNBTOptional(compound)) {
@@ -63,4 +63,88 @@ public class ScriptLiving<T extends EntityLiving> extends ScriptLivingBase<T> im
public boolean canSeeEntity(IEntity entity){
return this.entity.getEntitySenses().canSee(entity.getMCEntity());
}
public void playLivingSound() {
this.entity.playLivingSound();
}
public void spawnExplosionParticle()
{
this.entity.spawnExplosionParticle();
}
public void setMoveForward(float speed)
{
this.entity.setMoveForward(speed);
}
public void faceEntity(IEntity entity, float pitch, float yaw)
{
this.entity.faceEntity(entity.getMCEntity(), pitch, yaw);
}
public boolean canPickUpLoot()
{
return this.entity.canPickUpLoot();
}
public void setCanPickUpLoot(boolean pickUp)
{
this.entity.setCanPickUpLoot(pickUp);
}
public boolean isPersistent()
{
return this.entity.isNoDespawnRequired();
}
public void enablePersistence() {
this.entity.func_110163_bv();
}
public void setCustomNameTag(String text)
{
this.entity.setCustomNameTag(text);
}
public String getCustomNameTag()
{
return this.entity.getCustomNameTag();
}
public boolean hasCustomNameTag()
{
return this.entity.hasCustomNameTag();
}
public void setAlwaysRenderNameTag(boolean alwaysRender)
{
this.entity.setAlwaysRenderNameTag(alwaysRender);
}
public boolean getAlwaysRenderNameTag()
{
return this.entity.getAlwaysRenderNameTag();
}
public void clearLeashed(boolean sendPacket, boolean dropLeash)
{
this.entity.clearLeashed(sendPacket,dropLeash);
}
public boolean allowLeashing() {
return this.entity.allowLeashing();
}
public boolean getLeashed() {
return this.entity.getLeashed();
}
public IEntity getLeashedTo() {
return NpcAPI.Instance().getIEntity(entity.getLeashedToEntity());
}
public void setLeashedTo(IEntity entity, boolean sendPacket) {
this.entity.setLeashedToEntity(entity.getMCEntity(), sendPacket);
}
}
@@ -1,6 +1,5 @@
package noppes.npcs.scripted.entity;
import net.minecraft.block.BlockLiquid;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.potion.Potion;
@@ -8,18 +7,14 @@ import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.Vec3;
import net.minecraft.util.math.BlockPos;
import noppes.npcs.scripted.ScriptBlockPos;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptDamageSource;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IBlock;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.entity.IEntity;
import noppes.npcs.scripted.interfaces.item.IItemStack;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptDamageSource;
import java.util.ArrayList;
import noppes.npcs.scripted.interfaces.item.IItemStack;
public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T> implements IEntityLivingBase {
protected T entity;
@@ -108,7 +103,7 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
public IPos getLookVector() {
Vec3 lookVec = entity.getLookVec();
return new ScriptBlockPos(new BlockPos(lookVec.xCoord,lookVec.yCoord,lookVec.zCoord));
return NpcAPI.Instance().getIPos(lookVec.xCoord,lookVec.yCoord,lookVec.zCoord);
}
public IBlock getLookingAtBlock(int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
@@ -248,4 +243,54 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
public void setArmor(int slot, IItemStack item){
entity.setCurrentItemOrArmor(slot + 1, item == null?null:item.getMCItemStack());
}
public boolean isChild() {
return this.entity.isChild();
}
public void renderBrokenItemStack(IItemStack itemStack)
{
this.entity.renderBrokenItemStack(itemStack.getMCItemStack());
}
public boolean isOnLadder()
{
return this.entity.isOnLadder();
}
public int getTotalArmorValue()
{
return this.entity.getTotalArmorValue();
}
public int getArrowCountInEntity() {
return this.entity.getArrowCountInEntity();
}
public void setArrowCountInEntity(int count)
{
this.entity.setArrowCountInEntity(count);
}
public void dismountEntity(IEntity entity) {
this.entity.dismountEntity(entity.getMCEntity());
}
public void setAIMoveSpeed(float speed)
{
this.entity.setAIMoveSpeed(speed);
}
public float getAIMoveSpeed() {
return this.entity.getAIMoveSpeed();
}
public void setAbsorptionAmount(float amount)
{
this.entity.setAbsorptionAmount(amount);
}
public float getAbsorptionAmount() {
return this.entity.getAbsorptionAmount();
}
}
@@ -18,6 +18,7 @@ import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.constants.AnimationType;
import noppes.npcs.scripted.constants.EntityType;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.ITimers;
import noppes.npcs.scripted.interfaces.entity.ICustomNpc;
import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase;
@@ -151,6 +152,10 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
npc.script.clientNeedsUpdate = true;
}
public IPos getHome() {
return NpcAPI.Instance().getIPos(npc.ai.startPos[0],npc.ai.startPos[1],npc.ai.startPos[2]);
}
/**
* @return Home position x
*/
@@ -201,6 +206,11 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void setHome(int x, int y, int z){
npc.ai.startPos = new int[]{x, y, z};
}
public void setHome(IPos pos){
npc.ai.startPos = new int[]{pos.getX(), pos.getY(), pos.getZ()};
}
/**
* @param health New max health
*/
@@ -1133,7 +1143,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void setSkinType(byte type) {
npc.display.skinType = type;
npc.updateClient = true;
npc.script.clientNeedsUpdate = true;
}
public byte getSkinType() {
@@ -1146,7 +1156,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
this.npc.display.url = url;
npc.textureLocation = null;
npc.display.skinType = 2;
npc.updateClient = true;
npc.script.clientNeedsUpdate = true;
}
public String getSkinUrl() {
@@ -1155,7 +1165,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public void setCloakTexture(String cloakTexture) {
npc.display.cloakTexture = cloakTexture;
npc.updateClient = true;
npc.script.clientNeedsUpdate = true;
}
public String getCloakTexture() {
@@ -1168,7 +1178,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
}
this.getOverlays().add(0, NpcAPI.Instance().createSkinOverlay(overlayTexture));
npc.updateClient = true;
npc.script.clientNeedsUpdate = true;
}
public String getOverlayTexture() {
@@ -1190,4 +1200,6 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
}
public void updateClient() { this.npc.updateClient(); }
public void updateAI() { this.npc.updateTasks(); }
}
@@ -86,6 +86,10 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
NoppesUtilPlayer.teleportPlayer(player, x, y, z, player.dimension);
}
public void setPosition(IPos pos) {
this.setPosition(pos.getX(),pos.getY(),pos.getZ());
}
public void setPosition(double x, double y, double z, int dimensionId){
if (NpcAPI.Instance().getIWorld(dimensionId) == null)
return;
@@ -93,6 +97,10 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
NoppesUtilPlayer.teleportPlayer(player, x, y, z, dimensionId);
}
public void setPosition(IPos pos, int dimensionId) {
this.setPosition(pos.getX(),pos.getY(),pos.getZ(), dimensionId);
}
public int getHunger(){
return player.getFoodStats().getFoodLevel();
}
@@ -505,6 +513,10 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
y = ValueUtil.CorrectInt(y, 0, 256);
player.setSpawnChunk(new ChunkCoordinates(x, y, z), true);
}
public void setSpawnpoint(IPos pos){
this.setSpawnpoint(pos.getX(),pos.getY(),pos.getZ());
}
public void resetSpawnpoint(){
player.setSpawnChunk(null, false);
@@ -459,7 +459,7 @@ public class PlayerEvent extends CustomNPCsEvent {
public Bonemeal(IPlayer player, int x, int y, int z, World world) {
super(player);
this.block = API.getIBlock(world, x, y, z);
this.block = API.getIBlock(NpcAPI.Instance().getIWorld(world), x, y, z);
this.x = x;
this.y = y;
this.z = z;
@@ -17,6 +17,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -66,23 +67,37 @@ public abstract class AbstractNpcAPI {
public abstract String[] getAllBiomeNames();
public abstract ICustomNpc createNPC(World var1);
public abstract ICustomNpc<?> createNPC(IWorld var1);
/**
*
* Spawns a new NPC in the world at the given coordinates and returns an ICustomNpc object of it.
*/
public abstract ICustomNpc spawnNPC(World var1, int var2, int var3, int var4);
public abstract ICustomNpc<?> spawnNPC(IWorld var1, int var2, int var3, int var4);
public abstract IEntity getIEntity(Entity var1);
public abstract ICustomNpc<?> spawnNPC(IWorld world, IPos pos);
public abstract IEntity[] getLoadedEntities();
public abstract IEntity<?> getIEntity(Entity var1);
public abstract IBlock getIBlock(World var1, BlockPos var2);
public abstract IEntity<?>[] getLoadedEntities();
public abstract IBlock getIBlock(World world, Block block, BlockPos pos);
public abstract IBlock getIBlock(IWorld world, int x, int y, int z);
public abstract IBlock getIBlock(World world, int x, int y, int z);
public abstract IBlock getIBlock(IWorld world, IPos pos);
public abstract ITileEntity getITileEntity(IWorld world, IPos pos);
public abstract ITileEntity getITileEntity(IWorld world, int x, int y, int z);
public abstract ITileEntity getITileEntity(TileEntity tileEntity);
public abstract IPos getIPos(BlockPos pos);
public abstract IPos getIPos(int x, int y, int z);
public abstract IPos getIPos(double x, double y, double z);
public abstract IPos getIPos(float x, float y, float z);
public abstract IContainer getIContainer(IInventory var1);
@@ -98,7 +113,7 @@ public abstract class AbstractNpcAPI {
public abstract IDamageSource getIDamageSource(DamageSource var1);
public abstract IDamageSource getIDamageSource(IEntity entity);
public abstract IDamageSource getIDamageSource(IEntity<?> entity);
public abstract EventBus events();
@@ -117,7 +132,7 @@ public abstract class AbstractNpcAPI {
return null;
} else {
try {
Class c = Class.forName("noppes.npcs.scripted.NpcAPI");
Class<?> c = Class.forName("noppes.npcs.scripted.NpcAPI");
instance = (AbstractNpcAPI) c.getMethod("Instance").invoke((Object) null);
} catch (Exception var1) {
var1.printStackTrace();
@@ -154,15 +169,15 @@ public abstract class AbstractNpcAPI {
public abstract INbt stringToNbt(String str);
public abstract IPlayer[] getAllServerPlayers();
public abstract IPlayer<?>[] getAllServerPlayers();
public abstract String[] getPlayerNames();
public abstract IItemStack createItem(String id, int damage, int size);
public abstract void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch);
public abstract void playSoundAtEntity(IEntity<?> entity, String sound, float volume, float pitch);
public abstract void playSoundToNearExcept(IPlayer player, String sound, float volume, float pitch);
public abstract void playSoundToNearExcept(IPlayer<?> player, String sound, float volume, float pitch);
/**
*
@@ -137,6 +137,9 @@ public interface IParticle {
double getY();
double getZ();
void setPosition(IPos pos);
void getPos();
void setMotion(double motionX, double motionY, double motionZ, float gravity);
double getMotionX();
double getMotionY();
@@ -5,6 +5,8 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.util.math.BlockPos;
public interface IPos {
int getX();
@@ -156,4 +158,6 @@ public interface IPos {
* @return The distance between this IPos object and the other.
*/
double distanceTo(IPos pos);
BlockPos getMCPos();
}
@@ -16,7 +16,9 @@ public interface ITileEntity {
*
* @return The world this tile entity is in.
*/
ScriptWorld getWorld();
IWorld getWorld();
void setWorld(IWorld world);
/**
*
@@ -24,6 +26,8 @@ public interface ITileEntity {
*/
TileEntity getMCTileEntity();
void markDirty();
/**
* Reads an INbt compound tag, creates a tile entity based on the data, and replaces this entity with the new one.
*/
@@ -33,6 +37,7 @@ public interface ITileEntity {
* @return The distance of this tile entity from the point given by the x, y, and z parameters.
*/
double getDistanceFrom(double x, double y, double z);
double getDistanceFrom(IPos pos);
/**
* @return A new IBlock object based on this tile entity's type.
@@ -1,7 +1,7 @@
package noppes.npcs.scripted.interfaces;
import net.minecraft.world.WorldServer;
import noppes.npcs.scripted.ScriptScoreboard;
import noppes.npcs.scripted.scoreboard.ScriptScoreboard;
import noppes.npcs.scripted.interfaces.entity.IEntity;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.handler.data.ISound;
@@ -39,41 +39,65 @@ public interface IWorld {
* @return The top-most block in the world as an IBlock object.
*/
IBlock getTopBlock(int x, int z);
IBlock getTopBlock(IPos pos);
boolean isBlockFreezable(IPos pos);
boolean isBlockFreezable(int x, int y, int z);
boolean isBlockFreezableNaturally(IPos pos);
boolean isBlockFreezableNaturally(int x, int y, int z);
boolean canBlockFreeze(IPos pos, boolean adjacentToWater);
boolean canBlockFreeze(int x, int y, int z, boolean adjacentToWater);
boolean canBlockFreezeBody(IPos pos, boolean adjacentToWater);
boolean canBlockFreezeBody(int x, int y, int z, boolean adjacentToWater);
boolean canSnowAt(IPos pos, boolean checkLight);
boolean canSnowAt(int x, int y, int z, boolean checkLight);
boolean canSnowAtBody(IPos pos, boolean checkLight);
boolean canSnowAtBody(int x, int y, int z, boolean checkLight);
/**
* @return The Y-value of the world at this x & z value based on the height map of the world.
*/
int getHeightValue(int x, int z);
int getHeightValue(IPos pos);
/**
* @return The minimum Y-value of the world at this x & z value based on the height map of the world.
*/
int getChunkHeightMapMinimum(int x, int z);
int getChunkHeightMapMinimum(IPos pos);
/**
* @return The metadata of the block at this position.
*/
int getBlockMetadata(int x, int y, int z);
int getBlockMetadata(IPos pos);
boolean setBlockMetadataWithNotify(int x, int y, int z, int metadata, int flag);
boolean setBlockMetadataWithNotify(IPos pos, int metadata, int flag);
boolean canBlockSeeTheSky(int x, int y, int z);
/**
* @param x
* @param y
* @param z
* @return can the block at this position see the sky or are there no blocks above this one
*/
boolean canSeeSky(int x, int y, int z);
/**
* @param pos
* @return can the block at this position see the sky or are there no blocks above this one
*/
boolean canSeeSky(IPos pos);
int getFullBlockLightValue(int x, int y, int z);
int getFullBlockLightValue(IPos pos);
int getBlockLightValue(int x, int y, int z);
int getBlockLightValue(IPos pos);
void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch);
@@ -96,10 +120,12 @@ public interface IWorld {
IPlayer getClosestPlayerToEntity(IEntity entity, double range);
IPlayer getClosestPlayer(double x, double y, double z, double range);
IPlayer getClosestPlayer(IPos pos, double range);
IPlayer getClosestVulnerablePlayerToEntity(IEntity entity, double range);
IPlayer getClosestVulnerablePlayer(double x, double y, double z, double range);
IPlayer getClosestVulnerablePlayer(IPos pos, double range);
/**
*
@@ -118,25 +144,31 @@ public interface IWorld {
* Sets the block's tile entity at the given position.
*/
void setTileEntity(int x, int y, int z, ITileEntity tileEntity);
void setTileEntity(IPos pos, ITileEntity tileEntity);
/**
* Removes the block's tile entity at the given position.
*/
void removeTileEntity(int x, int y, int z);
void removeTileEntity(IPos pos);
/**
*
* @return True if the block at this position is of cubic shape. (Not a stair, slab, etc.)
*/
boolean isBlockFullCube(int x, int y, int z);
boolean isBlockFullCube(IPos pos);
long getSeed();
void setSpawnLocation(int x, int y, int z);
void setSpawnLocation(IPos pos);
boolean canLightningStrikeAt(int x, int y, int z);
boolean canLightningStrikeAt(IPos pos);
boolean isBlockHighHumidity(int x, int y, int z);
boolean isBlockHighHumidity(IPos pos);
/**
* @param x World position x
@@ -146,6 +178,7 @@ public interface IWorld {
* @since 1.7.10d
*/
String getSignText(int x, int y, int z);
String getSignText(IPos pos);
/**
* @param x World position x
@@ -153,7 +186,8 @@ public interface IWorld {
* @param z World position z
* @param item The block to be set
*/
public void setBlock(int x, int y, int z, IItemStack item);
void setBlock(int x, int y, int z, IItemStack item);
void setBlock(IPos pos, IItemStack item);
/**
* @param x World position x
@@ -161,14 +195,16 @@ public interface IWorld {
* @param z World position z
* @param block The block to be set
*/
public void setBlock(int x, int y, int z, IBlock block);
void setBlock(int x, int y, int z, IBlock block);
void setBlock(IPos pos, IBlock block);
/**
* @param x World position x
* @param y World position y
* @param z World position z
*/
public void removeBlock(int x, int y, int z);
void removeBlock(int x, int y, int z);
void removeBlock(IPos pos);
IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision);
@@ -208,20 +244,6 @@ public interface IWorld {
IEntity[] rayCastEntities(IPos startPos, IPos lookVector, int maxDistance, double offset, double range);
/**
* @param x
* @param y
* @param z
* @return can the block at this position see the sky or are there no blocks above this one
*/
public boolean canSeeSky(int x, int y, int z);
/**
* @param pos
* @return can the block at this position see the sky or are there no blocks above this one
*/
public boolean canSeeSky(IPos pos);
/**
* @param name The name of the player to be returned
* @return The Player with name. Null is returned when the player isnt found
@@ -256,6 +278,7 @@ public interface IWorld {
* @param z The z position
*/
void thunderStrike(double x, double y, double z);
void thunderStrike(IPos pos);
/**
* Sends a packet from the server to the client everytime its called. Probably should not use this too much.
@@ -270,6 +293,7 @@ public interface IWorld {
* @param count Particle count
*/
void spawnParticle(String particle, double x, double y, double z, double dx, double dy, double dz, double speed, int count);
void spawnParticle(String particle, IPos pos, double dx, double dy, double dz, double speed, int count);
/**
* @param id The items name
@@ -353,6 +377,7 @@ public interface IWorld {
* @param grief Whether or not the explosion does damage to blocks
*/
void explode(double x, double y, double z, float range, boolean fire, boolean grief);
void explode(IPos pos, float range, boolean fire, boolean grief);
IPlayer[] getAllServerPlayers();
@@ -365,6 +390,7 @@ public interface IWorld {
* @return Returns the name of the biome
*/
String getBiomeName(int x, int z);
String getBiomeName(IPos pos);
/**
* Lets you spawn a server side cloned entity
@@ -377,8 +403,10 @@ public interface IWorld {
* @return Returns the entity which was spawned
*/
IEntity spawnClone(int x, int y, int z, int tab, String name, boolean ignoreProtection);
IEntity spawnClone(IPos pos, int tab, String name, boolean ignoreProtection);
IEntity spawnClone(int x, int y, int z, int tab, String name);
IEntity spawnClone(IPos pos, int tab, String name);
ScriptScoreboard getScoreboard();
@@ -6,6 +6,23 @@
package noppes.npcs.scripted.interfaces.entity;
import net.minecraft.entity.passive.EntityAnimal;
import noppes.npcs.scripted.interfaces.item.IItemStack;
public interface IAnimal<T extends EntityAnimal> extends IEntityLiving<T> {
/**
* Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
* the animal type)
*/
boolean isBreedingItem(IItemStack itemStack);
/**
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
*/
boolean interact(IPlayer player);
boolean isInLove();
void resetInLove();
boolean canMateWith(IAnimal animal);
}
@@ -6,6 +6,7 @@
package noppes.npcs.scripted.interfaces.entity;
import net.minecraft.entity.EntityCreature;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.ITimers;
import noppes.npcs.scripted.interfaces.handler.IOverlayHandler;
import noppes.npcs.scripted.interfaces.handler.data.IFaction;
@@ -72,6 +73,8 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
*/
void setTexture(String texture);
IPos getHome();
/**
* @return Home position x
*/
@@ -108,6 +111,9 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
* @param z The home z position
*/
void setHome(int x, int y, int z);
void setHome(IPos pos);
/**
* @param health New max health
*/
@@ -808,4 +814,6 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
int getCollisionType();
void updateClient();
void updateAI();
}
@@ -95,6 +95,10 @@ public interface IEntity<T extends Entity> {
void setMotion(double x, double y, double z);
void setMotion(IPos pos);
IPos getMotion();
boolean isAirborne();
/**
@@ -119,9 +123,9 @@ public interface IEntity<T extends Entity> {
*/
void setPosition(double x, double y, double z);
IPos getPos();
void setPosition(IPos pos);
void setPos(IPos pos);
IPos getPosition();
int getDimension();
@@ -305,6 +309,7 @@ public interface IEntity<T extends Entity> {
void knockback(int power, float direction);
void knockback(int xpower, int ypower, int zpower, float direction);
void knockback(IPos pos, float direction);
void setImmune(int ticks);
@@ -341,6 +346,8 @@ public interface IEntity<T extends Entity> {
public void setNbt(INbt nbt);
INbt getNbtOptional();
void storeAsClone(int tab, String name);
IWorld getWorld();
@@ -15,4 +15,40 @@ public interface IEntityLiving<T extends EntityLiving> extends IEntityLivingBase
void navigateTo(double var1, double var3, double var5, double var7);
T getMCEntity();
void playLivingSound();
void spawnExplosionParticle();
void setMoveForward(float speed);
void faceEntity(IEntity entity, float pitch, float yaw);
boolean canPickUpLoot();
void setCanPickUpLoot(boolean pickUp);
boolean isPersistent();
void enablePersistence();
void setCustomNameTag(String text);
String getCustomNameTag();
boolean hasCustomNameTag();
void setAlwaysRenderNameTag(boolean alwaysRender);
boolean getAlwaysRenderNameTag();
void clearLeashed(boolean sendPacket, boolean dropLeash);
boolean allowLeashing();
boolean getLeashed();
IEntity getLeashedTo();
void setLeashedTo(IEntity entity, boolean sendPacket);
}
@@ -146,4 +146,12 @@ public interface IEntityLivingBase<T extends EntityLivingBase> extends IEntity<T
* @param item Item to be set
*/
void setArmor(int slot, IItemStack item);
void setAIMoveSpeed(float speed);
float getAIMoveSpeed();
void setAbsorptionAmount(float amount);
float getAbsorptionAmount();
}
@@ -29,8 +29,10 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
void kick(String reason);
void setPosition(double x, double y, double z);
void setPosition(IPos pos);
void setPosition(double x, double y, double z, int dimensionId);
void setPosition(IPos pos, int dimensionId);
int getHunger();
@@ -210,6 +212,7 @@ public interface IPlayer<T extends EntityPlayerMP> extends IEntityLivingBase<T>
* @param z The z position
*/
void setSpawnpoint(int x, int y, int z);
void setSpawnpoint(IPos pos);
void resetSpawnpoint();
@@ -5,14 +5,17 @@
package noppes.npcs.scripted.interfaces.handler;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.interfaces.entity.IEntity;
public interface ICloneHandler {
IEntity spawn(double x, double y, double z, int tab, String name, IWorld world, boolean ignoreProtection);
IEntity spawn(IPos pos, int tab, String name, IWorld world, boolean ignoreProtection);
IEntity spawn(double x, double y, double z, int tab, String name, IWorld world);
IEntity spawn(IPos pos, int tab, String name, IWorld world);
IEntity[] getTab(int tab, IWorld world);
@@ -1,5 +1,7 @@
package noppes.npcs.scripted.interfaces.handler.data;
import noppes.npcs.scripted.interfaces.IPos;
public interface ITransportLocation {
int getId();
@@ -18,6 +20,8 @@ public interface ITransportLocation {
void setPosition(int x, int y, int z);
void setPosition(IPos pos);
double getX();
double getY();
@@ -5,4 +5,20 @@ public interface IJobBard extends IJob {
String getSong();
void setSong(String song);
void setInstrument(int i);
int getInstrumentId();
void setMinRange(int range);
int getMinRange();
void setMaxRange(int range);
int getMaxRange();
void setStreaming(boolean streaming);
boolean getStreaming();
void hasOffRange(boolean value);
boolean hasOffRange();
}
@@ -1,4 +1,12 @@
package noppes.npcs.scripted.interfaces.jobs;
public interface IJobGuard extends IJob {
boolean attackCreepers();
void attackCreepers(boolean value);
boolean attacksAnimals();
void attacksAnimals(boolean value);
boolean attackHostileMobs();
void attackHostileMobs(boolean value);
}
@@ -5,4 +5,10 @@ import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase;
public interface IJobHealer extends IJob {
void heal(IEntityLivingBase entity, float amount);
void setRange(int range);
int getRange();
void setSpeed(int speed);
int getSpeed();
}
@@ -1,10 +1,31 @@
package noppes.npcs.scripted.interfaces.jobs;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
public interface IJobSpawner extends IJob {
IEntityLivingBase spawnEntity(int number);
IEntityLivingBase<?> spawnEntity(int number);
IEntityLivingBase<?> getEntity(int number, int x, int y, int z, IWorld world);
IEntityLivingBase<?> getEntity(int number, IPos pos, IWorld world);
void setEntity(int number, IEntityLivingBase<?> entityLivingBase);
/**
* Removes all spawned entities
*/
void removeAllSpawned();
IEntityLivingBase<?>[] getNearbySpawned();
boolean hasPixelmon();
boolean isEmpty();
boolean isOnCooldown(IPlayer<EntityPlayerMP> player);
}
@@ -1,6 +1,10 @@
package noppes.npcs.scripted.interfaces.roles;
import net.minecraft.entity.INpc;
public interface IRole {
INpc getNpc();
int getType();
}
@@ -1,5 +1,19 @@
package noppes.npcs.scripted.interfaces.roles;
public interface IRoleTransporter extends IRole {
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
public interface IRoleTransporter extends IRole {
String getName();
int getTransportId();
void unlock(IPlayer<EntityPlayerMP> player, ITransportLocation location);
ITransportLocation getTransport();
boolean hasTransport();
void setTransport(ITransportLocation location);
}
@@ -30,4 +30,50 @@ public class ScriptJobBard extends ScriptJobInterface implements IJobBard {
job.song = song;
npc.script.clientNeedsUpdate = true;
}
/**
*
* @param i The id of the instrument. IDs:
* 0 - None,
* 1 - Banjo,
* 2 - Violin,
* 3 - Guitar,
* 4 - Harp,
* 5 - FrenchHorn
*/
public void setInstrument(int i) {
this.job.setInstrument(i);
}
public int getInstrumentId() {
return this.job.getInstrument().ordinal();
}
public void setMinRange(int range) {
this.job.minRange = range;
}
public int getMinRange() {
return this.job.minRange;
}
public void setMaxRange(int range) {
this.job.maxRange = range;
}
public int getMaxRange() {
return this.job.maxRange;
}
public void setStreaming(boolean streaming) {
this.job.isStreamer = streaming;
}
public boolean getStreaming() {
return this.job.isStreamer;
}
public void hasOffRange(boolean value) {
this.job.hasOffRange = value;
}
public boolean hasOffRange() {
return this.job.hasOffRange;
}
}
@@ -11,6 +11,27 @@ public class ScriptJobGuard extends ScriptJobInterface implements IJobGuard {
super(npc);
this.job = (JobGuard) npc.jobInterface;
}
public boolean attackCreepers() {
return job.attackCreepers;
}
public void attackCreepers(boolean value) {
job.attackCreepers = value;
}
public boolean attacksAnimals() {
return job.attacksAnimals;
}
public void attacksAnimals(boolean value) {
job.attacksAnimals = value;
}
public boolean attackHostileMobs() {
return job.attackHostileMobs;
}
public void attackHostileMobs(boolean value) {
job.attackHostileMobs = value;
}
@Override
public int getType(){
@@ -16,6 +16,20 @@ public class ScriptJobHealer extends ScriptJobInterface implements IJobHealer {
public void heal(IEntityLivingBase entity, float amount){
job.heal(entity.getMCEntity(), amount);
}
public void setRange(int range) {
this.job.range = range;
}
public int getRange() {
return this.job.range;
}
public void setSpeed(int speed) {
this.job.speed = speed;
}
public int getSpeed() {
return this.job.speed;
}
@Override
public int getType(){
@@ -1,17 +1,26 @@
package noppes.npcs.scripted.roles;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobSpawner;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.constants.JobType;
import noppes.npcs.scripted.interfaces.INbt;
import noppes.npcs.scripted.interfaces.IPos;
import noppes.npcs.scripted.interfaces.IWorld;
import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.jobs.IJobSpawner;
public class ScriptJobSpawner extends ScriptJobInterface implements IJobSpawner {
private JobSpawner job;
private final JobSpawner job;
public ScriptJobSpawner(EntityNPCInterface npc){
super(npc);
this.job = (JobSpawner) npc.jobInterface;
@@ -27,21 +36,64 @@ public class ScriptJobSpawner extends ScriptJobInterface implements IJobSpawner
* @param number The entity going to be spawned (1-6)
* @return Returns spawned entity
*/
public IEntityLivingBase spawnEntity(int number){
public IEntityLivingBase<?> spawnEntity(int number){
EntityLivingBase base = job.spawnEntity(number);
if(base == null)
return null;
return (IEntityLivingBase) NpcAPI.Instance().getIEntity(base);
return (IEntityLivingBase<?>) NpcAPI.Instance().getIEntity(base);
}
/**
* Removes all spawned entities
*/
public IEntityLivingBase<?> getEntity(int number, int x, int y, int z, IWorld world) {
NBTTagCompound compound = this.job.getCompound(number);
if(compound == null || !compound.hasKey("id"))
return null;
Entity entity = NoppesUtilServer.getEntityFromNBT(compound,x,y,z,world.getMCWorld());
if (!(entity instanceof EntityLivingBase)) {
return null;
}
return (IEntityLivingBase<?>) NpcAPI.Instance().getIEntity(entity);
}
public IEntityLivingBase<?> getEntity(int number, IPos pos, IWorld world) {
return this.getEntity(number,pos.getX(),pos.getY(),pos.getZ(),world);
}
public void setEntity(int number, IEntityLivingBase<?> entityLivingBase){
INbt nbt = entityLivingBase.getNbtOptional();
if (nbt == null)
return;
this.job.setJobCompound(number,nbt.getMCNBT());
}
/**
* Removes all spawned entities
*/
public void removeAllSpawned(){
for(EntityLivingBase entity : job.spawned){
entity.isDead = true;
}
job.spawned = new ArrayList<EntityLivingBase>();
job.spawned = new ArrayList<>();
}
public IEntityLivingBase<?>[] getNearbySpawned() {
List<EntityLivingBase> nearbySpawned = this.job.getNearbySpawned();
List<IEntityLivingBase<?>> list = new ArrayList<>();
for (EntityLivingBase entity : nearbySpawned) {
list.add((IEntityLivingBase<?>) NpcAPI.Instance().getIEntity(entity));
}
return list.toArray(new IEntityLivingBase[0]);
}
public boolean hasPixelmon() {
return this.job.hasPixelmon();
}
public boolean isEmpty() {
return this.job.isEmpty();
}
public boolean isOnCooldown(IPlayer<EntityPlayerMP> player) {
return this.job.isOnCooldown(player.getName());
}
}
@@ -1,7 +1,9 @@
package noppes.npcs.scripted.roles;
import net.minecraft.entity.INpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleInterface;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.constants.RoleType;
import noppes.npcs.scripted.interfaces.roles.IRole;
@@ -14,6 +16,10 @@ public class ScriptRoleInterface implements IRole {
this.role = npc.roleInterface;
}
public INpc getNpc() {
return (INpc) NpcAPI.Instance().getIEntity(npc);
}
/**
* @see noppes.npcs.scripted.constants.RoleType
* @return The RoleType of this role
@@ -1,13 +1,44 @@
package noppes.npcs.scripted.roles;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleTransporter;
import noppes.npcs.scripted.constants.RoleType;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation;
import noppes.npcs.scripted.interfaces.roles.IRoleTransporter;
public class ScriptRoleTransporter extends ScriptRoleInterface implements IRoleTransporter {
private final RoleTransporter role;
public ScriptRoleTransporter(EntityNPCInterface npc) {
super(npc);
role = (RoleTransporter) npc.roleInterface;
}
public String getName() {
return role.name;
}
public int getTransportId() {
return role.transportId;
}
public void unlock(IPlayer<EntityPlayerMP> player, ITransportLocation location) {
this.role.unlock(player.getMCEntity(), location);
}
public ITransportLocation getTransport(){
return this.role.getLocation();
}
public boolean hasTransport(){
return this.role.hasTransport();
}
public void setTransport(ITransportLocation location) {
this.role.setTransport(location);
}
@Override
@@ -1,4 +1,4 @@
package noppes.npcs.scripted;
package noppes.npcs.scripted.scoreboard;
import java.util.ArrayList;
import java.util.List;
@@ -15,8 +15,8 @@ import net.minecraft.server.MinecraftServer;
*/
public class ScriptScoreboard {
private Scoreboard board;
protected ScriptScoreboard(){
public ScriptScoreboard(){
board = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard();
}
@@ -1,4 +1,4 @@
package noppes.npcs.scripted;
package noppes.npcs.scripted.scoreboard;
import net.minecraft.scoreboard.ScoreObjective;
@@ -1,4 +1,4 @@
package noppes.npcs.scripted;
package noppes.npcs.scripted.scoreboard;
import java.util.ArrayList;
import java.util.List;