mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 16:34:46 +00:00
Added Custom Particles for scripted entities that work on server and client sides.
This commit is contained in:
1 parent
9f4ab7f01e
commit
fbc22fdef2
6 files changed
+295
-11
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@@ -8,9 +9,13 @@ public class ModelPartData {
|
||||
public String texture;
|
||||
public byte type = 0;
|
||||
public boolean playerTexture;
|
||||
|
||||
|
||||
public int amount, maxAge, scaleRateStart, alphaRateStart;
|
||||
public float scale1, scale2, scaleRate, gravity, alpha1, alpha2, alphaRate;
|
||||
public double x, y, z, motionX, motionY, motionZ;
|
||||
|
||||
private ResourceLocation location;
|
||||
|
||||
|
||||
public ModelPartData(){
|
||||
playerTexture = true;
|
||||
}
|
||||
@@ -24,26 +29,108 @@ public class ModelPartData {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setByte("Type", type);
|
||||
compound.setInteger("Color", color);
|
||||
|
||||
compound.setInteger("Amount", amount);
|
||||
compound.setInteger("MaxAge", maxAge);
|
||||
|
||||
compound.setFloat("Scale1", scale1);
|
||||
compound.setFloat("Scale2", scale2);
|
||||
compound.setFloat("ScaleRate", scaleRate);
|
||||
compound.setInteger("ScaleRateStart",scaleRateStart);
|
||||
|
||||
compound.setFloat("Alpha1", alpha1);
|
||||
compound.setFloat("Alpha2", alpha2);
|
||||
compound.setFloat("AlphaRate", alphaRate);
|
||||
compound.setInteger("AlphaRateStart",alphaRateStart);
|
||||
|
||||
compound.setDouble("X",x);
|
||||
compound.setDouble("Y",y);
|
||||
compound.setDouble("Z",z);
|
||||
compound.setDouble("MotionX",motionX);
|
||||
compound.setDouble("MotionY",motionY);
|
||||
compound.setDouble("MotionZ",motionZ);
|
||||
compound.setFloat("Gravity",gravity);
|
||||
|
||||
if(texture != null && !texture.isEmpty())
|
||||
compound.setString("Texture", texture);
|
||||
compound.setBoolean("PlayerTexture", playerTexture);
|
||||
return compound;
|
||||
}
|
||||
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
type = compound.getByte("Type");
|
||||
color = compound.getInteger("Color");
|
||||
texture = compound.getString("Texture");
|
||||
|
||||
amount = compound.getInteger("Amount");
|
||||
maxAge = compound.getInteger("MaxAge");
|
||||
|
||||
scale1 = compound.getFloat("Scale1");
|
||||
scale2 = compound.getFloat("Scale2");
|
||||
scaleRate = compound.getFloat("ScaleRate");
|
||||
scaleRateStart = compound.getInteger("ScaleRateStart");
|
||||
|
||||
alpha1 = compound.getFloat("Alpha1");
|
||||
alpha2 = compound.getFloat("Alpha2");
|
||||
alphaRate = compound.getFloat("AlphaRate");
|
||||
alphaRateStart = compound.getInteger("AlphaRateStart");
|
||||
|
||||
x = compound.getDouble("X");
|
||||
y = compound.getDouble("Y");
|
||||
z = compound.getDouble("Z");
|
||||
motionX = compound.getDouble("MotionX");
|
||||
motionY = compound.getDouble("MotionY");
|
||||
motionZ = compound.getDouble("MotionZ");
|
||||
gravity = compound.getFloat("Gravity");
|
||||
|
||||
playerTexture = compound.getBoolean("PlayerTexture");
|
||||
location = null;
|
||||
}
|
||||
|
||||
|
||||
public void setAttributes(String texture, int HEXcolor, int amount, int maxAge,
|
||||
double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ, float gravity,
|
||||
float scale1, float scale2, float scaleRate, int scaleRateStart,
|
||||
float alpha1, float alpha2, float alphaRate, int alphaRateStart) {
|
||||
this.location = null;
|
||||
if(texture.isEmpty()){
|
||||
playerTexture = true;
|
||||
this.texture = texture;
|
||||
}
|
||||
else{
|
||||
this.texture = texture;
|
||||
this.color = HEXcolor;
|
||||
this.amount = amount;
|
||||
|
||||
this.scale1 = scale1;
|
||||
this.scale2 = scale2;
|
||||
this.scaleRate = scaleRate;
|
||||
this.scaleRateStart = scaleRateStart;
|
||||
|
||||
this.alpha1 = alpha1;
|
||||
this.alpha2 = alpha2;
|
||||
this.alphaRate = alphaRate;
|
||||
this.alphaRateStart = alphaRateStart;
|
||||
|
||||
this.maxAge = maxAge;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.motionX = motionX;
|
||||
this.motionY = motionY;
|
||||
this.motionZ = motionZ;
|
||||
this.gravity = gravity;
|
||||
|
||||
playerTexture = false;
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceLocation getResource(){
|
||||
if(texture.isEmpty())
|
||||
return null;
|
||||
if(location != null)
|
||||
return location;
|
||||
location = new ResourceLocation(texture);
|
||||
location = new ResourceLocation(texture);
|
||||
return location;
|
||||
}
|
||||
|
||||
@@ -59,7 +146,7 @@ public class ModelPartData {
|
||||
playerTexture = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String toString(){
|
||||
return "Color: " + color + " Type: " + type;
|
||||
}
|
||||
@@ -67,9 +154,60 @@ public class ModelPartData {
|
||||
public String getColor() {
|
||||
String str = Integer.toHexString(color);
|
||||
|
||||
while(str.length() < 6)
|
||||
str = "0" + str;
|
||||
|
||||
return str;
|
||||
while(str.length() < 6)
|
||||
str = "0" + str;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
public double getMotionX() {
|
||||
return motionX;
|
||||
}
|
||||
public double getMotionY() {
|
||||
return motionY;
|
||||
}
|
||||
public double getMotionZ() {
|
||||
return motionZ;
|
||||
}
|
||||
|
||||
public float getScale1() {
|
||||
return scale1;
|
||||
}
|
||||
public float getScale2() {return scale2;}
|
||||
public float getScaleRate() {
|
||||
return scaleRate;
|
||||
}
|
||||
public int getScaleRateStart() {return scaleRateStart;}
|
||||
|
||||
public float getAlpha1() {return alpha1;}
|
||||
public float getAlpha2() {return alpha2;}
|
||||
public float getAlphaRate() {
|
||||
return alphaRate;
|
||||
}
|
||||
public int getAlphaRateStart() {return alphaRateStart;}
|
||||
|
||||
public int getMaxAge() {
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
public float getGravity() {
|
||||
return gravity;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -291,6 +291,34 @@ public class NoppesUtilServer {
|
||||
Server.sendAssociatedData(entity, EnumPacketClient.PARTICLE, entity.posX, entity.posY, entity.posZ, entity.height, entity.width, entity.yOffset, particle);
|
||||
}
|
||||
|
||||
public static void spawnScriptedParticle(Entity entity, String directory, int HEXcolor, int amount, int maxAge,
|
||||
double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ, float gravity,
|
||||
float scale1, float scale2, float scaleRate, int scaleRateStart,
|
||||
float alpha1, float alpha2, float alphaRate, int alphaRateStart,
|
||||
String playerName, EntityPlayer playerObj
|
||||
){
|
||||
List<Entity> playerEntities = playerObj.worldObj.getEntitiesWithinAABB(Entity.class, playerObj.boundingBox.expand(300, 300, 300));
|
||||
|
||||
String UUID = "";
|
||||
int entityID = -1;
|
||||
for(Entity e : playerEntities){
|
||||
if(e.equals(entity)){
|
||||
UUID = e.getUniqueID().toString();
|
||||
entityID = e.getEntityId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Server.sendAssociatedData(entity, EnumPacketClient.SCRIPTED_PARTICLE,
|
||||
directory, HEXcolor, amount, maxAge,
|
||||
x, y, z,
|
||||
motionX, motionY, motionZ, gravity,
|
||||
scale1, scale2, scaleRate, scaleRateStart,
|
||||
alpha1, alpha2, alphaRate, alphaRateStart,
|
||||
playerName, UUID, entityID
|
||||
);
|
||||
}
|
||||
|
||||
public static void deleteNpc(EntityNPCInterface npc,EntityPlayer player) {
|
||||
Server.sendAssociatedData(npc, EnumPacketClient.DELETE_NPC, npc.getEntityId());
|
||||
|
||||
@@ -6,12 +6,14 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -19,8 +21,10 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.ModelPartData;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.client.fx.EntityCustomFX;
|
||||
import noppes.npcs.client.gui.player.GuiDialogInteract;
|
||||
import noppes.npcs.client.gui.player.GuiQuestCompletion;
|
||||
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
|
||||
@@ -67,6 +71,71 @@ public class NoppesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void spawnScriptedParticle(ByteBuf buffer){
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
|
||||
String directory = Server.readString(buffer);
|
||||
|
||||
int HEXcolor = buffer.readInt();
|
||||
int amount = buffer.readInt();
|
||||
int maxAge = buffer.readInt();
|
||||
|
||||
double x = buffer.readDouble();
|
||||
double y = buffer.readDouble();
|
||||
double z = buffer.readDouble();
|
||||
|
||||
double motionX = buffer.readDouble();
|
||||
double motionY = buffer.readDouble();
|
||||
double motionZ = buffer.readDouble();
|
||||
float gravity = buffer.readFloat();
|
||||
|
||||
float scale1 = buffer.readFloat();
|
||||
float scale2 = buffer.readFloat();
|
||||
float scaleRate = buffer.readFloat();
|
||||
int scaleRateStart = buffer.readInt();
|
||||
|
||||
float alpha1 = buffer.readFloat();
|
||||
float alpha2 = buffer.readFloat();
|
||||
float alphaRate = buffer.readFloat();
|
||||
int alphaRateStart = buffer.readInt();
|
||||
|
||||
String playerName = Server.readString(buffer);
|
||||
String UUID = Server.readString(buffer);
|
||||
|
||||
int entityID = buffer.readInt();
|
||||
|
||||
ModelPartData particle = new ModelPartData();
|
||||
particle.setAttributes(
|
||||
directory, HEXcolor, amount, maxAge,
|
||||
x, y, z,
|
||||
motionX, motionY, motionZ, gravity,
|
||||
scale1, scale2, scaleRate, scaleRateStart,
|
||||
alpha1, alpha2, alphaRate, alphaRateStart
|
||||
);
|
||||
|
||||
World worldObj = Minecraft.getMinecraft().theWorld;
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(playerName);
|
||||
List<Entity> entities = player.worldObj.getEntitiesWithinAABB(Entity.class, player.boundingBox.expand(300, 300, 300));
|
||||
for(Entity entity : entities){
|
||||
if(UUID.equals(entity.getPersistentID().toString()) || (entity.getEntityId() == entityID)){
|
||||
EntityCustomFX fx = new EntityCustomFX(
|
||||
entity,
|
||||
x, y, z,
|
||||
motionX, motionY, motionZ, gravity,
|
||||
scale1, scale2, scaleRate, scaleRateStart,
|
||||
alpha1, alpha2, alphaRate, alphaRateStart,
|
||||
particle.getMaxAge(),
|
||||
particle
|
||||
);
|
||||
|
||||
for(int i = 0; i < particle.getAmount(); i++){
|
||||
minecraft.effectRenderer.addEffect(fx);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void clickSound() {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
}
|
||||
|
||||
@@ -151,6 +151,9 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
EnumGuiType gui = EnumGuiType.values()[buffer.readInt()];
|
||||
CustomNpcs.proxy.openGui(NoppesUtil.getLastNpc(), gui, buffer.readInt(), buffer.readInt(), buffer.readInt());
|
||||
}
|
||||
else if(type == EnumPacketClient.SCRIPTED_PARTICLE){
|
||||
NoppesUtil.spawnScriptedParticle(buffer);
|
||||
}
|
||||
else if(type == EnumPacketClient.PARTICLE){
|
||||
NoppesUtil.spawnParticle(buffer);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
public enum EnumPacketClient {
|
||||
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG
|
||||
CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -18,6 +19,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
@@ -30,6 +35,47 @@ public class ScriptEntity {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param directory The particle's directory. Use only forward slashes when writing a directory. Example: "customnpcs:textures/particle/tail.png"
|
||||
* @param HEXcolor The particle's color as a HEX integer
|
||||
* @param amount The amount of particles to spawn
|
||||
|
||||
* @param scale1 The particle's starting scale1
|
||||
* @param scale2 The particle's ending scale1
|
||||
* @param scaleRate Multiplier for the particle's growth rate. Using a negative number shrinks the particle, positive expands it, and value of 0 keeps it from growing or shrinking altogether.
|
||||
* @param maxAge The particle's maximum age in MC ticks
|
||||
|
||||
* @param x The particle's x position
|
||||
* @param y The particle's y position
|
||||
* @param z The particle's z position
|
||||
|
||||
* @param motionX The particle's speed in the x axis
|
||||
* @param motionY The particle's speed in the y axis
|
||||
* @param motionZ The particle's speed in the z axis
|
||||
*
|
||||
* @param gravity The particle's gravity
|
||||
*/
|
||||
public void spawnParticle(String directory, int HEXcolor, int amount, int maxAge,
|
||||
double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ, float gravity,
|
||||
float scale1, float scale2, float scaleRate, int scaleRateStart,
|
||||
float alpha1, float alpha2, float alphaRate, int alphaRateStart
|
||||
) {
|
||||
List<EntityPlayer> entities = entity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, entity.boundingBox.expand(300, 300, 300));
|
||||
if(entities.size() < 1)
|
||||
return;
|
||||
EntityPlayer playerObj = entities.get(0);
|
||||
String playerName = playerObj.getDisplayName();
|
||||
|
||||
NoppesUtilServer.spawnScriptedParticle(entity, directory, HEXcolor, amount, maxAge,
|
||||
x, y, z,
|
||||
motionX, motionY, motionZ, gravity,
|
||||
scale1, scale2, scaleRate, scaleRateStart,
|
||||
alpha1, alpha2, alphaRate, alphaRateStart,
|
||||
playerName, playerObj
|
||||
);
|
||||
}
|
||||
|
||||
public double getYOffset() { return entity.getYOffset(); }
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user