diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 49b46d13a..4b53ebf1c 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import cpw.mods.fml.common.eventhandler.EventBus; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -121,12 +122,16 @@ public class NpcAPI extends AbstractNpcAPI { return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); } + public IBlock getIBlock(World world, Block block, BlockPos pos) { + return new ScriptBlock(world, block, pos); + } + 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 INbt getINbt(NBTTagCompound compound) { - return compound == null?new ScriptNbt(new NBTTagCompound()):new ScriptNbt(compound); + public INbt getINbt(NBTTagCompound nbtTagCompound) { + return nbtTagCompound == null?new ScriptNbt(new NBTTagCompound()):new ScriptNbt(nbtTagCompound); } public INbt stringToNbt(String str) { @@ -272,6 +277,7 @@ public class NpcAPI extends AbstractNpcAPI { //if(!world.getMCWorld().isRemote) NoppesUtilServer.runCommand(world.getMCWorld(), "API", command); } + public String getRandomName(int dictionary, int gender) { return CustomNpcs.MARKOV_GENERATOR[dictionary].fetch(gender); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index 8c4f25673..9747d4aa5 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -18,7 +18,7 @@ import noppes.npcs.scripted.interfaces.*; import noppes.npcs.util.LRUHashMap; public class ScriptBlock implements IBlock { - private static final Map blockCache = new LRUHashMap(400); + private static final Map blockCache = new LRUHashMap(400); protected final IWorld world; protected final Block block; protected final BlockPos pos; @@ -62,19 +62,19 @@ public class ScriptBlock implements IBlock { return this.block.isAir(this.world.getMCWorld(), getX(), getY(), getZ()); } - public ScriptBlock setBlock(String blockName) { + public IBlock setBlock(String blockName) { Block block = (Block)Block.blockRegistry.getObject(new ResourceLocation(blockName)); if(block == null) { return this; } else { this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block); - return new ScriptBlock(this.world.getMCWorld(), block, this.pos); + return NpcAPI.Instance().getIBlock(world.getMCWorld(), block, new BlockPos(getX(),getY(),getZ())); } } - public ScriptBlock setBlock(IBlock block) { + public IBlock setBlock(IBlock block) { this.world.getMCWorld().setBlock(getX(),getY(),getZ(),block.getMCBlock()); - return new ScriptBlock(this.world.getMCWorld(), block.getMCBlock(), this.pos); + return NpcAPI.Instance().getIBlock(world.getMCWorld(), block.getMCBlock(), new BlockPos(getX(),getY(),getZ())); } public boolean isContainer() { diff --git a/src/main/java/noppes/npcs/scripted/ScriptContainer.java b/src/main/java/noppes/npcs/scripted/ScriptContainer.java index 31a849364..95e1efe13 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptContainer.java +++ b/src/main/java/noppes/npcs/scripted/ScriptContainer.java @@ -94,10 +94,6 @@ public class ScriptContainer implements IContainer { container.detectAndSendChanges(); } - public void putStackInSlot(int slot, IItemStack itemStack){ - container.putStackInSlot(slot,itemStack.getMCItemStack()); - } - public boolean isPlayerNotUsingContainer(IPlayer player){ return container.isPlayerNotUsingContainer((EntityPlayerMP) player.getMCEntity()); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptNbt.java b/src/main/java/noppes/npcs/scripted/ScriptNbt.java index 968ea698d..a01544945 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptNbt.java +++ b/src/main/java/noppes/npcs/scripted/ScriptNbt.java @@ -200,7 +200,7 @@ public class ScriptNbt implements INbt { } public boolean isEqual(INbt nbt) { - return nbt == null?false:this.compound.equals(nbt.getMCNBT()); + return nbt != null && this.compound.equals(nbt.getMCNBT()); } public void clear() { diff --git a/src/main/java/noppes/npcs/scripted/ScriptParticle.java b/src/main/java/noppes/npcs/scripted/ScriptParticle.java index 5a70d91dc..2d8481c6c 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptParticle.java +++ b/src/main/java/noppes/npcs/scripted/ScriptParticle.java @@ -17,7 +17,7 @@ public class ScriptParticle implements IParticle { private double x = 0,y = 0,z = 0; private double motionX = 0,motionY = 0,motionZ = 0; private float gravity = 0; - private float scale1 = 1.0f,scale2 = 1.0f,scaleRate = 0.0f; + private float scale1 = 20.0f,scale2 = 20.0f,scaleRate = 0.0f; private float alpha1 = 1.0f,alpha2 = 1.0f,alphaRate = 0.0f; private int scaleRateStart = 0, alphaRateStart = 0; diff --git a/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java b/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java index 9aecc2268..e0d963d5e 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptTileEntity.java @@ -4,6 +4,7 @@ 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; @@ -32,8 +33,8 @@ public class ScriptTileEntity implements ITileEntity { 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 IBlock getBlockType(){ + return NpcAPI.Instance().getIBlock(tileEntity.getWorldObj(), tileEntity.getBlockType(), new BlockPos(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); } public boolean isInvalid(){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index eebbcb8f7..078361150 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -71,7 +71,7 @@ public class ScriptWorld implements IWorld { Block block = world.getBlock(x, y, z); if(block == null || block.isAir(world, x, y, z)) return null; - return new ScriptBlock(world, block, new BlockPos(x,y,z)); + return NpcAPI.Instance().getIBlock(world, block, new BlockPos(x,y,z)); } public boolean isBlockFreezable(int x, int y, int z){ @@ -103,7 +103,7 @@ public class ScriptWorld implements IWorld { 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)); + return NpcAPI.Instance().getIBlock(world, block, new BlockPos(x,y,z)); } public int getHeightValue(int x, int z){ diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 5fe85514b..7a6c8d193 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -388,7 +388,7 @@ public class ScriptPlayer extends ScriptLivingBase return NpcAPI.Instance().getIEntity(player.dropOneItem(dropStack)); } - public boolean canHarvestBlock(ScriptBlock block){ + public boolean canHarvestBlock(IBlock block){ return player.canHarvestBlock(block.getMCBlock()); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java index 611848222..939341e73 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java @@ -9,6 +9,7 @@ import java.io.File; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.EventBus; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; @@ -32,6 +33,10 @@ import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay; import noppes.npcs.scripted.overlay.ScriptOverlay; +/** + * This object stores functions available to all scripting handlers through the "API" keyword. + * + */ public abstract class AbstractNpcAPI { private static AbstractNpcAPI instance = null; @@ -50,12 +55,18 @@ public abstract class AbstractNpcAPI { public abstract ICustomNpc createNPC(World 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 IEntity getIEntity(Entity var1); public abstract IBlock getIBlock(World var1, BlockPos var2); + public abstract IBlock getIBlock(World world, Block block, BlockPos pos); + public abstract IBlock getIBlock(World world, int x, int y, int z); public abstract IContainer getIContainer(IInventory var1); @@ -101,9 +112,28 @@ public abstract class AbstractNpcAPI { public abstract void executeCommand(IWorld var1, String var2); - public abstract String getRandomName(int var1, int var2); + /** + * Generates a new name as a String using the Markov name generator. + * + * @param dictionary An integer representing which dictionary to use: + * 0: Roman + * 1: Japanese + * 2: Slavic + * 3: Welsh + * 4: Saami + * 5: Old Norse + * 6: Ancient Greek + * 7: Aztec + * 8: CustomNPCs Classic + * 9: Spanish + * @param gender The gender of the name: + * 0: Random + * 1: Male + * 2: Female + */ + public abstract String getRandomName(int dictionary, int gender); - public abstract INbt getINbt(NBTTagCompound entityData); + public abstract INbt getINbt(NBTTagCompound nbtTagCompound); public abstract IPlayer[] getAllServerPlayers(); @@ -113,14 +143,30 @@ public abstract class AbstractNpcAPI { public abstract void playSoundToNearExcept(IPlayer player, String sound, float volume, float pitch); + /** + * + * @return Returns the server's Message of The Day. + */ public abstract String getMOTD(); + /** + * @param motd The server's new Message of The Day. + */ public abstract void setMOTD(String motd); + /** + * + * @return A new IParticle object initialized with the given texture. + */ public abstract IParticle createParticle(String directory); + @Deprecated public abstract IParticle createEntityParticle(String directory); + /** + * + * @return The uptime of the server in MC ticks. + */ public abstract int getServerTime(); public abstract boolean arePlayerScriptsEnabled(); @@ -135,9 +181,25 @@ public abstract class AbstractNpcAPI { public abstract void enableGlobalNPCScripts(boolean enable); + /** + * + * @param id The id of the custom GUI. + * @param width The width of the GUI in pixels. + * @param height The height of the GUI in pixels. + * @param pauseGame Whether the GUI pauses the game or not. + * @return A new ICustomGui object with the given attributes. + */ public abstract ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame); + /** + * + * @return A new ICustomOverlay overlay object with the given ID. + */ public abstract ICustomOverlay createCustomOverlay(int id); + /** + * + * @return A new ISkinOverlay object initialized with the given texture. + */ public abstract ISkinOverlay createSkinOverlay(String texture); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IBlock.java b/src/main/java/noppes/npcs/scripted/interfaces/IBlock.java index 3dfa5a466..c3f99a78b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IBlock.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IBlock.java @@ -17,13 +17,13 @@ public interface IBlock { /** * - * @return Returns an IPos object with the block's XYZ position. + * @return An IPos object with the block's XYZ position. */ IPos getPos(); /** * - * @return Returns the block name as it appears in the block registry. Return example: "minecraft:stone" + * @return The block name as it appears in the block registry. Return example: "minecraft:stone" */ String getName(); @@ -37,44 +37,44 @@ public interface IBlock { /** * * @param blockName The name of the block to be set in place of this block. - * @return Returns the new block set in place of this block as an IBlock object. + * @return The new block set in place of this block as an IBlock object. */ IBlock setBlock(String blockName); /** * * @param block Input IBlock object to replace this block. - * @return Returns the new block set in place of the previous block. + * @return The new block set in place of the previous block. */ IBlock setBlock(IBlock block); /** * - * @return Returns true if the block can contain items like a chest does. + * @return True if the block can contain items like a chest does. */ boolean isContainer(); /** * - * @return Returns the container object of this block. If this block is not a container, an exception will be thrown. + * @return The container object of this block. If this block is not a container, an exception will be thrown. */ IContainer getContainer(); /** * - * @return Returns an IWorld object of the world this block is in. + * @return An IWorld object of the world this block is in. */ IWorld getWorld(); /** * - * @return Returns true if this block has a tile entity. Blocks with custom data like signs, player skulls, chests, etc. will have tile entities. + * @return True if this block has a tile entity. Blocks with custom data like signs, player skulls, chests, etc. will have tile entities. */ boolean hasTileEntity(); /** * - * @return Returns an ITileEntity object which can modify this block's tile entity. + * @return An ITileEntity object which can modify this block's tile entity. */ ITileEntity getTileEntity(); @@ -86,13 +86,13 @@ public interface IBlock { /** * - * @return Returns a non-script, obfuscated MC object for the block's tile entity. + * @return An obfuscated MC object for the block's tile entity. */ TileEntity getMCTileEntity(); /** * - * @return Returns a non-script, obfuscated MC block object. + * @return An obfuscated MC block object. */ Block getMCBlock(); @@ -100,7 +100,7 @@ public interface IBlock { /** * - * @return Returns an INbt object which can modify the block's tile entity's NBT data. + * @return An INbt object which can modify the block's tile entity's NBT data. */ INbt getTileEntityNBT(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IContainer.java b/src/main/java/noppes/npcs/scripted/interfaces/IContainer.java index e639dabbe..e06c5dc3a 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IContainer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IContainer.java @@ -24,13 +24,13 @@ public interface IContainer { /** * - * @return Returns a non-script, obfuscated MC inventory object. + * @return An obfuscated MC inventory object. */ IInventory getMCInventory(); /** * - * @return Returns a non-script, obfuscated MC container object. + * @return An obfuscated MC container object. */ Container getMCContainer(); @@ -39,25 +39,26 @@ public interface IContainer { * @param itemStack The item stack to be searched in the container * @param ignoreDamage Whether damage should be ignored when searching * @param ignoreNBT Whether NBT values should be ignored when searching - * @return Returns the amount of the item stack found, based on the flags given above. + * @return The amount of the item stack found, based on the flags given above. */ int count(IItemStack itemStack, boolean ignoreDamage, boolean ignoreNBT); /** * - * @return Returns a list of all item stacks in the container as a list of IItemStack objects. + * @return A list of all item stacks in the container as a list of IItemStack objects. */ IItemStack[] getItems(); /** * - * @return Returns true if this container belongs to a Custom GUI. + * @return True if this container belongs to a Custom GUI. */ boolean isCustomGUI(); + /** + * Sends changes to be reflected on the player's client. + */ void detectAndSendChanges(); - void putStackInSlot(int slot, IItemStack itemStack); - boolean isPlayerNotUsingContainer(IPlayer player); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java b/src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java index 838b66699..eada96094 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IDamageSource.java @@ -11,7 +11,7 @@ import noppes.npcs.scripted.interfaces.entity.IEntity; public interface IDamageSource { /** * - * @return Returns the damage type of the damage source as a string. Ex: "lava", "explosion", "magic", "outOfWorld", etc. + * @return The damage type of the damage source as a string. Ex: "lava", "explosion", "magic", "outOfWorld", etc. */ String getType(); @@ -21,19 +21,19 @@ public interface IDamageSource { /** * - * @return Returns the entity source of where the damage source originated. If a player was shot by an arrow from a skeleton, this would return an IEntity object of the skeleton. + * @return The entity source of where the damage source originated. If a player was shot by an arrow from a skeleton, this would return an IEntity object of the skeleton. */ IEntity getTrueSource(); /** * - * @return Returns the entity source of where the damage source originated. If a player was shot by an arrow from a skeleton, this would return an IEntity object of the arrow. + * @return The entity source of where the damage source originated. If a player was shot by an arrow from a skeleton, this would return an IEntity object of the arrow. */ IEntity getImmediateSource(); /** * - * @return Returns a non-script, obfuscated MC damage source object. + * @return An obfuscated MC damage source object. */ DamageSource getMCDamageSource(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/INbt.java b/src/main/java/noppes/npcs/scripted/interfaces/INbt.java index 0ff2b9f77..62a4f1061 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/INbt.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/INbt.java @@ -7,70 +7,136 @@ package noppes.npcs.scripted.interfaces; import net.minecraft.nbt.NBTTagCompound; +/** + * A scripted data representation of an MC NBTTagCompound object. Using these functions modifies the compound tag + * associated with this object. Any changes made to the compound tag are made directly to its "tagMap" attribute, + * minimizing the impact of setting/getting NBT data with this object on performance. + * + * Compound tags, unlike list tags, can contain multiple types of NBT tag types. Compound tags can even + * contain compound tags inside them, and if that compound tag is accessed, an object like this one will also be returned! + * + * Every tag inside a compound tag has a -unique- "key". If you try to put another tag of the same key inside the + * compound tag, it will replace the previous tag. + * + * The types and their type as an integer are as follows: + * 1: Byte + * 2: Short + * 3: Int + * 4: Long + * 5: Float + * 6: Double + * 7: Byte array + * 8: String + * 9: Tag list + * 10: Compound + * 11: Integer array + * + */ public interface INbt { - void remove(String var1); + /** + * Returns the tag with the given key from the compound tag. + */ + void remove(String key); - boolean has(String var1); + /** + * @return True if the compound tag has a tag with the given key. + */ + boolean has(String key); - boolean getBoolean(String var1); + boolean getBoolean(String key); - void setBoolean(String var1, boolean var2); + void setBoolean(String key, boolean value); - short getShort(String var1); + short getShort(String key); - void setShort(String var1, short var2); + void setShort(String key, short value); - int getInteger(String var1); + int getInteger(String key); - void setInteger(String var1, int var2); + void setInteger(String key, int value); - byte getByte(String var1); + byte getByte(String key); - void setByte(String var1, byte var2); + void setByte(String key, byte value); - long getLong(String var1); + long getLong(String key); - void setLong(String var1, long var2); + void setLong(String key, long value); - double getDouble(String var1); + double getDouble(String key); - void setDouble(String var1, double var2); + void setDouble(String key, double value); - float getFloat(String var1); + float getFloat(String key); - void setFloat(String var1, float var2); + void setFloat(String key, float value); - String getString(String var1); + String getString(String key); - void setString(String var1, String var2); + void setString(String key, String value); - byte[] getByteArray(String var1); + byte[] getByteArray(String key); - void setByteArray(String var1, byte[] var2); + void setByteArray(String key, byte[] value); - int[] getIntegerArray(String var1); + int[] getIntegerArray(String key); - void setIntegerArray(String var1, int[] var2); + void setIntegerArray(String key, int[] value); - Object[] getList(String var1, int var2); + /** + * Returns a tag list of objects with this key in the compound tag. All the objects in the list + * will always be of the same type. + * + * @return The tag list of objects, depending on the tag type. + */ + Object[] getList(String key, int value); - int getListType(String var1); + /** + * Returns the type of the tag list with this key, as an integer. + */ + int getListType(String key); - void setList(String var1, Object[] var2); + /** + * Adds a new tag list to the compound tag with the given key. + * + * @param key The key for the list tag + * @param value The list of objects to be in the list. The type of the first element in this list becomes the tag + * list's type, and if later objects are not of this type, they will not be added. + */ + void setList(String key, Object[] value); - INbt getCompound(String var1); + INbt getCompound(String key); - void setCompound(String var1, INbt var2); + void setCompound(String key, INbt value); + /** + * + * @return A list of all the compound tag's keys. + */ String[] getKeys(); - int getType(String var1); + /** + * + * @return The type of the tag with the input key as an integer. + */ + int getType(String key); + /** + * + * @return An obfuscated MC NBTTagCompound object. + */ NBTTagCompound getMCNBT(); + /** + * + * @return A curly-bracket formatted JSON string of all the compound tag. + */ String toJsonString(); - boolean isEqual(INbt var1); + boolean isEqual(INbt nbt); + /** + * Completely clears the compound tag of all tags inside it. + */ void clear(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java b/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java index 228495ad9..ba718d2f3 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IParticle.java @@ -4,40 +4,117 @@ import noppes.npcs.NoppesUtilServer; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.interfaces.entity.IEntity; +/** + * A particle that can be spawned in the world, complete with translation, scale, rotate, and color transformations. + * (CNPC+ original!) + * + * To create a particle object: + * API.createParticle(directory); + * Then modify its attributes as you please, and call the particle's spawn functions to see it in the world. + * + * Spawning this particle in the world sends a hefty packet with all its data to the client. The particle is then + * rendered with a custom renderer based on all the given attributes. + * + * If a particle appears to not appear at first, try increasing its scale or changing its position. The entity it's + * being spawned on or a block in the world may be blocking it. + * + */ public interface IParticle { + /** + * + * @param entity Spawns this particle object on the given entity. When spawned this way, the particle will always have its origin at the entity. + */ void spawnOnEntity(IEntity entity); + /** + * + * @param world Spawns the particle in the given world, at a position corresponding to this particle's position variables. + */ void spawnInWorld(ScriptWorld world); + /** + * + * @param world Spawns the particle in the given world, at a position determined by the input parameters. + * @param x The X position the particle will spawn in the world. + * @param y The Y position the particle will spawn in the world. + * @param z The Z position the particle will spawn in the world. + */ void spawnInWorld(ScriptWorld world, double x, double y, double z); + /** + * + * @param facePlayer Whether the particle is always facing the player's camera. If this is disabled, the particle will appear to be laying flat face down on the ground if its rotation is unchanged. + */ void setFacePlayer(boolean facePlayer); boolean getFacePlayer(); + /** + * + * @param directory The directory of this particle's texture. This can be any texture in a resource pack or mod, and even a URL! + */ void setDirectory(String directory); String getDirectory(); + /** + * + * @param amount The amount of multiples of this particle to spawn in the world. Not too good looking if used, but has some edge cases where it's alright. + */ void setAmount(int amount); int getAmount(); + /** + * + * @param maxAge The maximum age this particle will be around for, in MC ticks. + */ void setMaxAge(int maxAge); int getMaxAge(); + /** + * The width and height of the particle's texture you want to render in pixels. Anything more gets cut off. + * @param width The width of the particle's texture, in pixels. + * @param height The height of the particle's texture, in pixels. + */ void setSize(int width, int height); int getWidth(); int getHeight(); + /** + * The horizontal and vertical offset of the particle's texture from the top-left, starts rendering the particle at this point. + * @param offsetX The horizontal offset, in pixels (u). + * @param offsetY The vertical offset, in pixels (v). + */ void setOffset(int offsetX, int offsetY); int getOffsetX(); int getOffsetY(); + /** + * Enables animation on the particle. Must set a custom width and height first using the setSize(width,height) function. + * Every frame of animation the particle goes through should be saved on a single image file. + * + * The renderer will read the frames of animation based on the given width and height of the particle, starting from the given X & Y offsets. + * The renderer then goes rightwards (width) pixels for every frame. Once it can't go rightwards anymore, + * the animation goes down (height) pixels, and once again keeps going rightwards if it has to. + * + * If the animation loops, once there is nowhere downward to go, the animation will start over at the X & Y offset. + * + * @param animRate The frame rate of the particle's animation, in MC ticks. (20 ticks = 1 second) + * @param animLoop Whether the animation loops or not. + * @param animStart The amount of ticks before the particle starts animating. + * @param animEnd The amount of ticks the particle is around for before it stops animating. + */ void setAnim(int animRate, boolean animLoop, int animStart, int animEnd); int getAnimRate(); boolean getAnimLoop(); int getAnimStart(); int getAnimEnd(); + /** + * + * @param x The X position from the particle's origin the particle will spawn at. + * @param y The Y position from the particle's origin the particle will spawn at. + * @param z The Z position from the particle's origin the particle will spawn at. + */ void setPosition(double x, double y, double z); double getX(); double getY(); @@ -49,36 +126,85 @@ public interface IParticle { double getMotionZ(); float getGravity(); + /** + * + * @param HEXColor The starting HEX color of the particle. + * @param HEXColor2 The ending HEX color of the particle. + * @param HEXColorRate The rate of interpolation between the two HEX colors. + * @param HEXColorStart The amount of ticks the particle is around for before its colors begin interpolating between HEXColor and HEXColor2. + */ void setHEXColor(int HEXColor, int HEXColor2, float HEXColorRate, int HEXColorStart); int getHEXColor1(); int getHEXColor2(); float getHEXColorRate(); int getHEXColorStart(); + /** + * + * @param alpha1 The starting transparency of the particle. + * @param alpha2 The ending transparency of the particle. + * @param alphaRate The rate of interpolation between the two transparency values. + * @param alphaRateStart The amount of ticks the particle is around for before its colors begin interpolating between alpha1 and alpha2. + */ void setAlpha(float alpha1, float alpha2, float alphaRate, int alphaRateStart); float getAlpha1(); float getAlpha2(); float getAlphaRate(); int getAlphaRateStart(); + /** + * + * @param scale1 The starting scale/size of the particle. + * @param scale2 The ending scale/size of the particle. + * @param scaleRate The rate of interpolation between the two scale values. + * @param scaleRateStart The amount of ticks the particle is around for before its colors begin interpolating between scale1 and scale2. + */ void setScale(float scale1, float scale2, float scaleRate, int scaleRateStart); float getScale1(); float getScale2(); float getScaleRate(); int getScaleRateStart(); + /** + * Enables rotation about the X axis. + * If the particle is set to always face the player, this axis is a constant horizontal line on the player's camera. + * + * @param rotationX1 The starting X rotation of the particle. + * @param rotationX2 The ending X rotation of the particle. + * @param rotationXRate The rate of interpolation between the two X rotation values. + * @param rotationXRateStart The amount of ticks the particle is around for before its colors begin interpolating between rotationX1 and rotationX2. + */ void setRotationX(float rotationX1, float rotationX2, float rotationXRate, int rotationXRateStart); float getRotationX1(); float getRotationX2(); float getRotationXRate(); int getRotationXRateStart(); + /** + * Enables rotation about the Y axis. + * If the particle is set to always face the player, this axis is a constant vertical line on the player's camera. + * + * @param rotationY1 The starting Y rotation of the particle. + * @param rotationY2 The ending Y rotation of the particle. + * @param rotationYRate The rate of interpolation between the two Y rotation values. + * @param rotationYRateStart The amount of ticks the particle is around for before its colors begin interpolating between rotationY1 and rotationY2. + */ void setRotationY(float rotationY1, float rotationY2, float rotationYRate, int rotationYRateStart); float getRotationY1(); float getRotationY2(); float getRotationYRate(); int getRotationYRateStart(); + /** + * Enables rotation about the Y axis. + * If the particle is set to always face the player, this axis is a constant line going into the player's camera. + * You'll be using this one most often if the particle is set to face the player. + * + * @param rotationZ1 The starting Z rotation of the particle. + * @param rotationZ2 The ending Z rotation of the particle. + * @param rotationZRate The rate of interpolation between the two Z rotation values. + * @param rotationZRateStart The amount of ticks the particle is around for before its colors begin interpolating between rotationZ1 and rotationZ2. + */ void setRotationZ(float rotationZ1, float rotationZ2, float rotationZRate, int rotationZRateStart); float getRotationZ1(); float getRotationZ2(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPos.java b/src/main/java/noppes/npcs/scripted/interfaces/IPos.java index 3743f60aa..5bbd363f4 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPos.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPos.java @@ -14,45 +14,154 @@ public interface IPos { int getZ(); + /** + * Shifts the IPos up by 1 block and returns the new object. + * + */ IPos up(); - IPos up(int var1); + /** + * + * @param n The number of blocks to move the position up by. + * @return The new IPos object. + */ + IPos up(int n); + /** + * Shifts the IPos down by 1 block and returns the new object. + * + */ IPos down(); - IPos down(int var1); + /** + * + * @param n The number of blocks to move the position down by. + * @return The new IPos object. + */ + IPos down(int n); + /** + * Shifts the IPos north by 1 block and returns the new object. + * + */ IPos north(); - IPos north(int var1); + /** + * + * @param n The number of blocks to move the position north by. + * @return The new IPos object. + */ + IPos north(int n); + /** + * Shifts the IPos east by 1 block and returns the new object. + * + */ IPos east(); - IPos east(int var1); + /** + * + * @param n The number of blocks to move the position east by. + * @return The new IPos object. + */ + IPos east(int n); + /** + * Shifts the IPos south by 1 block and returns the new object. + * + */ IPos south(); - IPos south(int var1); + /** + * + * @param n The number of blocks to move the position south by. + * @return The new IPos object. + */ + IPos south(int n); + /** + * Shifts the IPos west by 1 block and returns the new object. + * + */ IPos west(); - IPos west(int var1); + /** + * + * @param n The number of blocks to move the position west by. + * @return The new IPos object. + */ + IPos west(int n); - IPos add(int var1, int var2, int var3); + /** + * Adds the IPos' coordinates by each of the parameters given. + * + * @param x X coordinate amount to be added + * @param y Y coordinate amount to be added + * @param z Z coordinate amount to be added + * @return The resulting IPos from the addition. + */ + IPos add(int x, int y, int z); - IPos add(IPos var1); + /** + * Directly adds the coordinates of two IPos objects and returns the resulting IPos sum. + * For example, if one IPos was represented by the coordinates (0,60,5), and another by (-10,-30,25), + * the resulting object's coordinates are (0 - 10,60 - 30,5 + 25) = (-10,30,30). + * + * @param pos The position to be added to this IPos object. + * @return The sum of the two IPos objects as a new IPos object. + */ + IPos add(IPos pos); - IPos subtract(int var1, int var2, int var3); + /** + * Subtracts the IPos' coordinates by each of the parameters given. + * + * @param x X coordinate amount to be subtracted + * @param y Y coordinate amount to be subtracted + * @param z Z coordinate amount to be subtracted + * @return The resulting IPos from the subtraction. + */ + IPos subtract(int x, int y, int z); - IPos subtract(IPos var1); + /** + * Directly subtracts the coordinates of two IPos objects and returns the resulting IPos difference. + * For example, if one IPos was represented by the coordinates (0,60,5), and another by (-10,-30,25), + * the resulting object's coordinates are (0 + 10,60 + 30,5 - 25) = (10,90,-20). + * + * @param pos The position to be subtracted from this IPos object. + * @return The difference of the two IPos objects as a new IPos object. + */ + IPos subtract(IPos pos); + /** + * Returns a normalized vector of this block's position, calculated by: + * + * + * @return The normalized vector of this block position. + */ double[] normalize(); + /** + * + * @return An obfuscated MC BlockPos object. + */ BlockPos getMCBlockPos(); - IPos offset(int var1); + /** + * Offsets the block by 1 block in the given direction and returns the resulting IPos object + * + */ + IPos offset(int direction); - IPos offset(int var1, int var2); + /** + * Offsets the block by n blocks in the given direction and returns the resulting IPos object + * + */ + IPos offset(int direction, int n); - double distanceTo(IPos var1); + /** + * + * @param pos The IPos object to calculate the distance to + * @return The distance between this IPos object and the other. + */ + double distanceTo(IPos pos); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java b/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java index 18e8d3951..637c52a7b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java @@ -2,34 +2,65 @@ package noppes.npcs.scripted.interfaces; import net.minecraft.util.ResourceLocation; +/** + * A skin overlay object for both NPCs and players. Several skin overlays at a time can be layered on top of each other. + * In an NPC's case, the old overlay texture is now the skin overlay with ID 0. + * + * Modifying these attributes, an overlay can be made to look like a powered creeper effect, just a new skin, or both! + */ public interface ISkinOverlay { + /** + * Sets the directory texture of the overlay. Does not support URLs. + */ void setTexture(String texture); - String getTexture(); + /** + * Sets whether this overlay glows in the dark or not. + */ void setGlow(boolean glow); - boolean getGlow(); + /** + * Sets the transparency of the overlay, from 0 to 1. + */ void setAlpha(float alpha); float getAlpha(); + /** + * Sets the size of the entire overlay when rendered on the entity. By default, overlays render slightly on top of + * the entity's model. + */ void setSize(float size); float getSize(); + /** + * Sets the texture scale of the overlay. Higher values will "zoom in" to the texture more. + */ void setScale(float scaleX, float scaleY); float getScaleX(); float getScaleY(); + /** + * Sets the "texture speed" by which the texture shifts on each render tick. Used to create a powered creeper effect! + * This does not move the entire overlay, it just moves the position at which the texture begins rendering. + */ void setSpeed(float speedX, float speedY); float getSpeedX(); float getSpeedY(); + /** + * Sets the amount in each direction by which the overlay will be offset from the entity. + */ void setOffset(float offsetX, float offsetY, float offsetZ); float getOffsetX(); float getOffsetY(); float getOffsetZ(); + /** + * + * @return The MC resource location object used to bind the overlay's texture. + */ ResourceLocation getLocation(); void setLocation(ResourceLocation location); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java index e46dc7978..d2448b23b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITileEntity.java @@ -5,25 +5,64 @@ import noppes.npcs.scripted.ScriptBlock; import noppes.npcs.scripted.ScriptWorld; public interface ITileEntity { + /** + * + * @return An integer representing the metadata of this block. Blocks with different states will + * return different values. For example, each stage of growth for a wheat crop will return a different value, each + * orientation of a stair block will return a different value, etc. + */ int getBlockMetadata(); + /** + * + * @return The world this tile entity is in. + */ ScriptWorld getWorld(); + /** + * + * @return An obfuscated MC tile entity object. + */ TileEntity getMCTileEntity(); + /** + * Reads an INbt compound tag, creates a tile entity based on the data, and replaces this entity with the new one. + */ void readFromNBT(INbt nbt); + /** + * @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); - ScriptBlock getBlockType(); + /** + * @return A new IBlock object based on this tile entity's type. + */ + IBlock getBlockType(); + /** + * + * @return True if the tile entity is invalid, false otherwise. + */ boolean isInvalid(); + /** + * Invalidates the tile entity. + */ void invalidate(); + /** + * Validates the tile entity for use. + */ void validate(); + /** + * Updates the block's tile entity to the values set in this object. + */ void updateContainingBlockInfo(); + /** + * Writes the tile entity to NBT and returns the compound tag. + */ INbt getNBT(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java b/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java index df3623e97..92d18082b 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITimers.java @@ -6,29 +6,84 @@ package noppes.npcs.scripted.interfaces; public interface ITimers { - void start(int var1, int var2, boolean var3); + /** + * Adds a timer to the NPC or player with the given attributes. If this function is used and there is already a + * timer with the given ID, an exception will be thrown. + * + * @param id The id of the timer. + * @param ticks The amount of ticks before the timer ends. + * @param repeat Whether this timer repeats when it reaches its maximum amount of ticks. + */ + void start(int id, int ticks, boolean repeat); - void forceStart(int var1, int var2, boolean var3); + /** + * Adds a timer to the NPC or player with the given attributes. No exception will be thrown if there is already a + * timer with the given ID when using this function. + * + * @param id The id of the timer. + * @param ticks The amount of ticks before the timer ends. + * @param repeat Whether this timer repeats when it reaches its maximum amount of ticks. + */ + void forceStart(int id, int ticks, boolean repeat); - boolean has(int var1); + /** + * + * @return True if the set of timers contains a timer with the given id, false otherwise. + */ + boolean has(int id); - boolean stop(int var1); + /** + * Stops the timer with the given id + * + * @return True if there was a timer with the given id. + */ + boolean stop(int id); - void reset(int var1); + /** + * Resets the ticks elapsed in the timer with the given id to 0. + */ + void reset(int id); + /** + * Removes all timers. + */ void clear(); + /** + * @return The amount of ticks elapsed in the timer. + */ int ticks(int id); + /** + * Sets the amount of ticks elapsed in the timer with the given id to a different value. + * + * @param ticks The new ticks elapsed by the timer. + */ void setTicks(int id, int ticks); + /** + * @return The maximum amount of ticks the timer with the given id runs for before it stops. + */ int maxTicks(int id); + /** + * Sets the maximum amount of ticks the timer with the given id can run for before it stops. + */ void setMaxTicks(int id, int maxTicks); + /** + * @return True if the timer with the given id repeats, false otherwise. + */ boolean repeats(int id); + /** + * Sets whether the timer with the given id repeats or not. + */ void setRepeats(int id, boolean repeat); + /** + * + * @return The amount of timers in the set of timers. + */ int size(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 828ff5dd3..152c14573 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -28,6 +28,10 @@ public interface IWorld { */ IBlock getBlock(int x, int y, int z); + /** + * + * @return The top-most block in the world as an IBlock object. + */ IBlock getTopBlock(int x, int z); boolean isBlockFreezable(int x, int y, int z); @@ -42,10 +46,19 @@ public interface IWorld { 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); + /** + * @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); + /** + * @return The metadata of the block at this position. + */ int getBlockMetadata(int x, int y, int z); boolean setBlockMetadataWithNotify(int x, int y, int z, int metadata, int flag); @@ -72,12 +85,27 @@ public interface IWorld { IPlayer getClosestVulnerablePlayer(double x, double y, double z, double range); + /** + * + * @param entity The entity whose type will be used as a parameter + * @return The amount of entities of the given type in the world. + */ int countEntities(IEntity entity); + /** + * Sets the block's tile entity at the given position. + */ void setTileEntity(int x, int y, int z, ITileEntity tileEntity); + /** + * Removes the block's tile entity at the given position. + */ void removeTileEntity(int x, int y, int z); + /** + * + * @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); long getSeed(); @@ -173,6 +201,7 @@ public interface IWorld { * @param directory The particle's texture directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png" * @return Returns IEntityParticle object */ + @Deprecated IParticle createEntityParticle(String directory); /** @@ -266,6 +295,10 @@ public interface IWorld { ScriptScoreboard getScoreboard(); + /** + * + * @return An obfuscated MC BlockPos object. + */ BlockPos getMCBlockPos(int x, int y, int z); /** @@ -275,5 +308,9 @@ public interface IWorld { */ WorldServer getMCWorld(); + /** + * + * @return The ID of this world's dimension. 0 for overworld, 1 for End, -1 for Nether, etc. + */ int getDimensionID(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java index dec675a23..d45165fd1 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java @@ -169,7 +169,7 @@ public interface IPlayer extends IEntityLivingBase IEntity dropOneItem(boolean dropStack); - boolean canHarvestBlock(ScriptBlock block); + boolean canHarvestBlock(IBlock block); boolean interactWith(IEntity entity);