diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index 9cf52a980..d7ab06245 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -34,6 +34,7 @@ public class ScriptBlock implements IBlock { } protected void setTile(TileEntity tile) { + world.setTileEntity(pos.getX(),pos.getY(), pos.getZ(),new ScriptTileEntity(tile)); this.tile = tile; } @@ -112,6 +113,15 @@ public class ScriptBlock implements IBlock { return this.tile != null; } + public ScriptTileEntity getTileEntity() { + return new ScriptTileEntity(this.tile); + } + + public void setTileEntity(ScriptTileEntity tileEntity){ + world.setTileEntity(pos.getX(),pos.getY(), pos.getZ(),tileEntity); + this.tile = tileEntity.getMCTileEntity(); + } + public TileEntity getMCTileEntity() { return this.tile; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java b/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java new file mode 100644 index 000000000..5eb9e3966 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java @@ -0,0 +1,61 @@ +package noppes.npcs.scripted; + +import jdk.nashorn.internal.ir.Block; +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.INbt; +import noppes.npcs.scripted.interfaces.ITileEntity; + +public class ScriptTileEntity implements ITileEntity { + protected T tileEntity; + + public ScriptTileEntity(T tileEntity) { this.tileEntity = tileEntity; } + + public int getBlockMetadata(){ + return tileEntity.getBlockMetadata(); + } + + public ScriptWorld getWorld(){ + return (ScriptWorld) NpcAPI.Instance().getIWorld((WorldServer) tileEntity.getWorldObj()); + } + + public TileEntity getMCTileEntity() { + return this.tileEntity; + } + + public void readFromNBT(INbt nbt){ + this.tileEntity.readFromNBT(nbt.getMCNBT()); + } + + public double getDistanceFrom(double x, double y, double z){ + return this.tileEntity.getDistanceFrom(x,y,z); + } + + public ScriptBlock getBlockType(){ + return new ScriptBlock(tileEntity.getWorldObj(), tileEntity.getBlockType(), new BlockPos(tileEntity.xCoord,tileEntity.yCoord,tileEntity.zCoord)); + } + + public boolean isInvalid(){ + return tileEntity.isInvalid(); + } + + public void invalidate(){ + tileEntity.invalidate(); + } + + public void validate() { + tileEntity.validate(); + } + + public void updateContainingBlockInfo(){ + tileEntity.updateContainingBlockInfo(); + } + + public INbt getNBT() { + NBTTagCompound compound = new NBTTagCompound(); + this.tileEntity.writeToNBT(compound); + return NpcAPI.Instance().getINbt(compound); + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index cbcc43f48..e0dda6112 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -3,11 +3,13 @@ package noppes.npcs.scripted; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -29,6 +31,7 @@ import noppes.npcs.scripted.entity.ScriptEntity; import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.interfaces.IBlock; import noppes.npcs.scripted.interfaces.IWorld; +import sun.font.Script; public class ScriptWorld implements IWorld { private static Map tempData = new HashMap(); @@ -54,6 +57,10 @@ public class ScriptWorld implements IWorld { public long getTotalTime(){ return world.getTotalWorldTime(); } + + public boolean areAllPlayersAsleep(){ + return world.areAllPlayersAsleep(); + } /** * @param x World position x @@ -68,6 +75,130 @@ public class ScriptWorld implements IWorld { return new ScriptBlock(world, block, new BlockPos(x,y,z)); } + public boolean isBlockFreezable(int x, int y, int z){ + return world.isBlockFreezable(x,y,z); + } + + public boolean isBlockFreezableNaturally(int x, int y, int z){ + return world.isBlockFreezableNaturally(x,y,z); + } + + public boolean canBlockFreeze(int x, int y, int z, boolean adjacentToWater){ + return world.canBlockFreeze(x,y,z,adjacentToWater); + } + + public boolean canBlockFreezeBody(int x, int y, int z, boolean adjacentToWater){ + return world.canBlockFreezeBody(x,y,z,adjacentToWater); + } + + public boolean canSnowAt(int x, int y, int z, boolean checkLight){ + return world.func_147478_e(x,y,z,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 new ScriptBlock(world, block, new BlockPos(x,y,z)); + } + + public int getHeightValue(int x, int z){ + return world.getHeightValue(x,z); + } + + public int getChunkHeightMapMinimum(int x, int z){ + return world.getChunkHeightMapMinimum(x,z); + } + + public int getBlockMetadata(int x, int y, int z){ + return world.getBlockMetadata(x,y,z); + } + + 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 int getFullBlockLightValue(int x, int y, int z){ + return world.getFullBlockLightValue(x,y,z); + } + + public int getBlockLightValue(int x, int y, int z){ + return world.getBlockLightValue(x,y,z); + } + + public void playSoundAtEntity(ScriptEntity entity, String sound, float volume, float pitch){ + world.playSoundAtEntity(entity.getMCEntity(), sound, volume, pitch); + } + + public void playSoundToNearExcept(ScriptPlayer player, String sound, float volume, float pitch){ + world.playSoundToNearExcept((EntityPlayerMP) player.getMCEntity(), sound, volume, pitch); + } + + public ScriptEntity getEntityByID(int id){ + return (ScriptEntity) NpcAPI.Instance().getIEntity(world.getEntityByID(id)); + } + + public boolean spawnEntityInWorld(ScriptEntity entity){ + return world.spawnEntityInWorld(entity.getMCEntity()); + } + + public ScriptPlayer getClosestPlayerToEntity(ScriptEntity entity, double range){ + return (ScriptPlayer) NpcAPI.Instance().getIEntity(world.getClosestPlayerToEntity(entity.getMCEntity(), range)); + } + + public ScriptPlayer getClosestPlayer(double x, double y, double z, double range){ + return (ScriptPlayer) NpcAPI.Instance().getIEntity(world.getClosestPlayer(x,y,z, range)); + } + + public ScriptPlayer getClosestVulnerablePlayerToEntity(ScriptEntity entity, double range){ + return (ScriptPlayer) NpcAPI.Instance().getIEntity(world.getClosestVulnerablePlayerToEntity(entity.getMCEntity(), range)); + } + + public ScriptPlayer getClosestVulnerablePlayer(double x, double y, double z, double range){ + return (ScriptPlayer) NpcAPI.Instance().getIEntity(world.getClosestVulnerablePlayer(x,y,z, range)); + } + + public int countEntities(ScriptEntity entity){ + return world.countEntities(entity.getMCEntity().getClass()); + } + + public void setTileEntity(int x, int y, int z, ScriptTileEntity tileEntity){ + world.setTileEntity(x,y,z,tileEntity.getMCTileEntity()); + } + + public void removeTileEntity(int x, int y, int z){ + world.removeTileEntity(x,y,z); + } + + public boolean isBlockFullCube(int x, int y, int z){ + return world.func_147469_q(x,y,z); + } + + public long getSeed(){ + return world.getSeed(); + } + + public void setSpawnLocation(int x, int y, int z){ + world.setSpawnLocation(x,y,z); + } + + public boolean canLightningStrikeAt(int x, int y, int z){ + return world.canLightningStrikeAt(x,y,z); + } + + public boolean isBlockHighHumidity(int x, int y, int z){ + return world.isBlockHighHumidity(x,y,z); + } + /** * @param x World position x * @param y World position y @@ -129,6 +260,10 @@ public class ScriptWorld implements IWorld { return null; return (ScriptPlayer) ScriptController.Instance.getScriptForEntity(player); } + + public ScriptPlayer getPlayerByUUID(String uuid){ + return (ScriptPlayer) NpcAPI.Instance().getIEntity(world.func_152378_a(UUID.fromString(uuid))); + } /** * @param time The world time to be set @@ -136,7 +271,7 @@ public class ScriptWorld implements IWorld { public void setTime(long time){ world.setWorldTime(time); } - + /** * @return Whether or not its daytime */ diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 67d2fe5ad..4989d6e1c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -167,6 +167,14 @@ public class ScriptEntity implements IEntity { } public void spawnParticle(ScriptEntityParticle entityParticle) { entityParticle.spawnOnEntity(this); } + public int getEntityId(){ + return entity.getEntityId(); + } + + public String getUniqueID(){ + return entity.getUniqueID().toString(); + } + public double getYOffset() { return entity.getYOffset(); } /** @@ -639,10 +647,6 @@ public class ScriptEntity implements IEntity { entity.setSprinting(sprinting); } - public String getUniqueID(){ - return entity.getUniqueID().toString(); - } - public boolean hasCollided() { return entity.isCollided; } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java new file mode 100644 index 000000000..ca2dd8e9e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java @@ -0,0 +1,33 @@ +package noppes.npcs.scripted.interfaces; + +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.NpcAPI; +import noppes.npcs.scripted.ScriptBlock; +import noppes.npcs.scripted.ScriptWorld; + +public interface ITileEntity { + int getBlockMetadata(); + + ScriptWorld getWorld(); + + TileEntity getMCTileEntity(); + + void readFromNBT(INbt nbt); + + double getDistanceFrom(double x, double y, double z); + + ScriptBlock getBlockType(); + + boolean isInvalid(); + + void invalidate(); + + void validate(); + + void updateContainingBlockInfo(); + + INbt getNBT(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 9c7b14534..c378e6894 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -1,5 +1,7 @@ package noppes.npcs.scripted.interfaces; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -18,6 +20,8 @@ public interface IWorld { */ public long getTotalTime(); + boolean areAllPlayersAsleep(); + /** * @param x World position x * @param y World position y @@ -26,6 +30,66 @@ public interface IWorld { */ public IBlock getBlock(int x, int y, int z); + IBlock getTopBlock(int x, int z); + + public boolean isBlockFreezable(int x, int y, int z); + + public boolean isBlockFreezableNaturally(int x, int y, int z); + + public boolean canBlockFreeze(int x, int y, int z, boolean adjacentToWater); + + public boolean canBlockFreezeBody(int x, int y, int z, boolean adjacentToWater); + + public boolean canSnowAt(int x, int y, int z, boolean checkLight); + + public boolean canSnowAtBody(int x, int y, int z, boolean checkLight); + + public int getHeightValue(int x, int z); + + public int getChunkHeightMapMinimum(int x, int z); + + public int getBlockMetadata(int x, int y, int z); + + public boolean setBlockMetadataWithNotify(int x, int y, int z, int metadata, int flag); + + public boolean canBlockSeeTheSky(int x, int y, int z); + + public int getFullBlockLightValue(int x, int y, int z); + + public int getBlockLightValue(int x, int y, int z); + + public void playSoundAtEntity(ScriptEntity entity, String sound, float volume, float pitch); + + public void playSoundToNearExcept(ScriptPlayer player, String sound, float volume, float pitch); + + public ScriptEntity getEntityByID(int id); + + public boolean spawnEntityInWorld(ScriptEntity entity); + + public ScriptPlayer getClosestPlayerToEntity(ScriptEntity entity, double range); + + public ScriptPlayer getClosestPlayer(double x, double y, double z, double range); + + public ScriptPlayer getClosestVulnerablePlayerToEntity(ScriptEntity entity, double range); + + public ScriptPlayer getClosestVulnerablePlayer(double x, double y, double z, double range); + + public int countEntities(ScriptEntity entity); + + public void setTileEntity(int x, int y, int z, ScriptTileEntity tileEntity); + + public void removeTileEntity(int x, int y, int z); + + public boolean isBlockFullCube(int x, int y, int z); + + public long getSeed(); + + public void setSpawnLocation(int x, int y, int z); + + public boolean canLightningStrikeAt(int x, int y, int z); + + boolean isBlockHighHumidity(int x, int y, int z); + /** * @param x World position x * @param y World position y @@ -56,6 +120,8 @@ public interface IWorld { */ public ScriptPlayer getPlayer(String name); + ScriptPlayer getPlayerByUUID(String uuid); + /** * @param time The world time to be set */ diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 631f486c6..5fb686421 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -265,6 +265,24 @@ public class WrapperNpcAPI extends NpcAPI { return new ScriptItemStack(new ItemStack(item, size, damage)); } + public void playSoundAtEntity(ScriptEntity entity, String sound, float volume, float pitch){ + entity.getWorld().getMCWorld().playSoundAtEntity(entity.getMCEntity(), sound, volume, pitch); + } + + public void playSoundToNearExcept(ScriptPlayer player, String sound, float volume, float pitch){ + player.getWorld().getMCWorld().playSoundToNearExcept((EntityPlayerMP) player.getMCEntity(), sound, volume, pitch); + } + + public String getMOTD() + { + return MinecraftServer.getServer().getMOTD(); + } + + public void setMOTD(String motd) + { + MinecraftServer.getServer().setMOTD(motd); + } + public ScriptEntityParticle createEntityParticle(String directory){ return new ScriptEntityParticle(directory); }