From 48baa6de5f04428715624c7a233eba668953386c Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 9 Apr 2024 20:35:29 -0400 Subject: [PATCH] Move Collisions to Stats --- src/main/java/noppes/npcs/DataDisplay.java | 10 ------ src/main/java/noppes/npcs/DataStats.java | 35 ++++++++++++------- .../client/gui/mainmenu/GuiNpcDisplay.java | 12 ++----- .../npcs/client/gui/mainmenu/GuiNpcStats.java | 7 +++- .../npcs/entity/EntityNPCInterface.java | 14 ++++---- .../npcs/scripted/entity/ScriptNpc.java | 4 +-- .../assets/customnpcs/lang/en_US.lang | 2 +- 7 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index 2921958a5..897514080 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -58,9 +58,6 @@ public class DataDisplay { public ArrayList invisibleToList = new ArrayList<>(); - // 0 - Yes, 1 - No, 2 - Only NPCs, 3 - Only Players, 4 - NPCs and Players - public int collidesWith = 1; - public DataDisplay(EntityNPCInterface npc){ this.npc = npc; markovGeneratorId = new Random().nextInt(CustomNpcs.MARKOV_GENERATOR.length-1); @@ -109,8 +106,6 @@ public class DataDisplay { nbttagcompound.setBoolean("NoLivingAnimation", disableLivingAnimation); nbttagcompound.setByte("BossBar", showBossBar); - nbttagcompound.setInteger("CollidesWith",collidesWith); - NBTTagList list = new NBTTagList(); for(UUID uuid : invisibleToList){ list.appendTag(new NBTTagString(uuid.toString())); @@ -195,11 +190,6 @@ public class DataDisplay { invisibleToList = new ArrayList<>(); } - if(nbttagcompound.hasKey("CollidesWith")) - collidesWith = nbttagcompound.getInteger("CollidesWith"); - else - collidesWith = 1; - if(prevSkinType != skinType || !texture.equals(prevTexture)|| !url.equals(prevUrl)) npc.textureLocation = null; npc.updateHitbox(); diff --git a/src/main/java/noppes/npcs/DataStats.java b/src/main/java/noppes/npcs/DataStats.java index 3867ade5b..e1c8acb5f 100644 --- a/src/main/java/noppes/npcs/DataStats.java +++ b/src/main/java/noppes/npcs/DataStats.java @@ -9,12 +9,12 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.util.ValueUtil; public class DataStats { - + private float attackStrength = 5; public int attackSpeed = 20, swingWarmUp = 0, attackRange = 2, knockback = 0; public int minDelay = 20, maxDelay = 40, rangedRange = 15, fireRate = 5, burstCount = 1, shotCount = 1, accuracy = 60; public int aggroRange = 16; - + public EnumPotionType potionType = EnumPotionType.None; public int potionDuration = 5; //20 = 1 second public int potionAmp = 0; @@ -25,7 +25,7 @@ public class DataStats { public boolean hideKilledBody = false; public boolean canDespawn = false; public boolean playerSetCanDespawn = false; - + public Resistances resistances = new Resistances(); public boolean ignoreCobweb = false; @@ -47,17 +47,20 @@ public class DataStats { public String fireSound = "random.bow"; public boolean aimWhileShooting = false; public boolean projectilesKeepTerrain = false; - + public EnumCreatureAttribute creatureType = EnumCreatureAttribute.UNDEFINED; - + private EntityNPCInterface npc; public boolean attackInvisible = false; - + + // 0 - Yes, 1 - No, 2 - Only NPCs, 3 - Only Players, 4 - NPCs and Players + public int collidesWith = 1; + public DataStats(EntityNPCInterface npc){ this.npc = npc; } public NBTTagCompound writeToNBT(NBTTagCompound compound) - { + { compound.setTag("Resistances", resistances.writeToNBT()); compound.setDouble("MaxHealth", maxHealth); compound.setInteger("AggroRange", aggroRange); @@ -68,7 +71,7 @@ public class DataStats { compound.setBoolean("IgnoreCobweb", ignoreCobweb); compound.setFloat("HealthRegen", healthRegen); compound.setFloat("CombatRegen", combatRegen); - + compound.setFloat("AttackStrenght", attackStrength); compound.setInteger("AttackRange", attackRange); compound.setInteger("AttackSpeed", attackSpeed); @@ -77,7 +80,7 @@ public class DataStats { compound.setInteger("PotionEffect", potionType.ordinal()); compound.setInteger("PotionDuration", potionDuration); compound.setInteger("PotionAmp", potionAmp); - + compound.setInteger("MaxFiringRange", rangedRange); compound.setInteger("FireRate", fireRate); compound.setInteger("minDelay", minDelay); @@ -85,7 +88,7 @@ public class DataStats { compound.setInteger("BurstCount", burstCount); compound.setInteger("ShotCount", shotCount); compound.setInteger("Accuracy", accuracy); - + compound.setFloat("pDamage", pDamage); compound.setInteger("pImpact", pImpact); compound.setInteger("pSize", pSize); @@ -114,7 +117,8 @@ public class DataStats { compound.setBoolean("AttackInvisible", attackInvisible); compound.setBoolean("CanDespawn", canDespawn); compound.setBoolean("PlayerSetCanDespawn", playerSetCanDespawn); - + compound.setInteger("CollidesWith",collidesWith); + return compound; } @@ -176,8 +180,13 @@ public class DataStats { attackInvisible = compound.getBoolean("AttackInvisible"); canDespawn = compound.getBoolean("CanDespawn"); playerSetCanDespawn = compound.getBoolean("PlayerSetCanDespawn"); - + npc.setImmuneToFire(immuneToFire); + + if(compound.hasKey("CollidesWith")) + collidesWith = compound.getInteger("CollidesWith"); + else + collidesWith = 1; } public float getAttackStrength(){ @@ -187,7 +196,7 @@ public class DataStats { attackStrength = (float)(Math.floor(strength)); npc.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(attackStrength); } - + public void setMaxHealth(double maxHealth) { this.maxHealth = Math.floor(maxHealth); npc.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(maxHealth); diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java index 9f4c453bc..94c816936 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -79,15 +79,12 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene y+=23; addLabel(new GuiNpcLabel(5,"display.livingAnimation", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(5, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no"}, display.disableLivingAnimation?1:0)); - - addLabel(new GuiNpcLabel(6,"display.collides", guiLeft + 185, y + 5)); - this.addButton(new GuiNpcButton(6, guiLeft + 300, y, 100, 20, new String[]{"gui.yes","gui.no","Only CNPCs","Only Players","CNPCs & Players"}, display.collidesWith)); + this.addButton(new GuiNpcButton(13, guiLeft + 185, y , 100, 20, "display.tintsettings")); + this.addButton(new GuiNpcButton(12,guiLeft + 300, y, 100, 20, "display.hitboxsettings")); y+=23; addLabel(new GuiNpcLabel(7,"display.visible", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(7, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no","gui.partly"}, display.visible)); - this.addButton(new GuiNpcButton(13, guiLeft + 185, y , 100, 20, "display.tintsettings")); - this.addButton(new GuiNpcButton(12,guiLeft + 300, y, 100, 20, "display.hitboxsettings")); y+=23; addLabel(new GuiNpcLabel(10,"display.bossbar", guiLeft + 5, y + 5)); @@ -130,7 +127,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene boolean isGlow = true; if(npc.display.skinOverlayData.has(0)) isGlow = npc.display.skinOverlayData.overlayList.get(0).getGlow(); - + SkinOverlay skinOverlay = new SkinOverlay(textfield.getText()); skinOverlay.setGlow(isGlow); skinOverlay.setBlend(isGlow); @@ -166,9 +163,6 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene else if(button.id == 5){ display.disableLivingAnimation = button.getValue() == 1; } - else if(button.id == 6){ - display.collidesWith = button.getValue(); - } else if(button.id == 7){ display.visible = button.getValue(); } diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java index f58eeef08..1e6bfed23 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java @@ -58,8 +58,10 @@ public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener, addLabel(new GuiNpcLabel(10,"stats.fireimmune", guiLeft + 5, y + 5)); addButton(new GuiNpcButton(5,guiLeft + 217, y, 56, 20, new String[]{"stats.never","stats.inWater","stats.inAir"} , stats.drowningType)); addLabel(new GuiNpcLabel(11,"stats.candrown", guiLeft + 140, y + 5)); + addButton(new GuiNpcButton(23, guiLeft + 358, y, 56, 20, new String[]{"display.all","gui.none","NPCs","Players","Both"}, stats.collidesWith)); + addLabel(new GuiNpcLabel(23,"stats.collides", guiLeft + 275, y + 5)); - addButton(new GuiNpcButton(6,guiLeft + 82, y+=22, 56, 20, new String[]{"gui.no","gui.yes"} ,stats.burnInSun? 1:0)); + addButton(new GuiNpcButton(6,guiLeft + 82, y+=22, 56, 20, new String[]{"gui.no","gui.yes"} ,stats.burnInSun? 1:0)); addLabel(new GuiNpcLabel(12,"stats.burninsun", guiLeft + 5, y + 5)); addButton(new GuiNpcButton(7,guiLeft + 217, y, 56, 20, new String[]{"gui.no","gui.yes"} ,stats.noFallDamage? 1:0)); addLabel(new GuiNpcLabel(13,"stats.nofalldamage", guiLeft + 140, y + 5)); @@ -138,6 +140,9 @@ public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener, else if (button.id == 22) { stats.ignoreCobweb = (button.getValue() == 0); } + else if(button.id == 23){ + stats.collidesWith = button.getValue(); + } // Button 300 if(guibutton instanceof GuiNpcButton) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index a376087f9..22eb5633b 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -249,7 +249,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti boolean didAttack = false; if(DBCAddon.instance.canDBCAttack(this, f, receiver)){ - didAttack = receiver.attackEntityFrom(new NpcDamageSource("mob", this), 1.0f); + didAttack = receiver.attackEntityFrom(new NpcDamageSource("mob", this), 0.001f); if(didAttack) DBCAddon.instance.doDBCDamage(this, f, receiver); } @@ -1773,13 +1773,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public boolean canBePushed() { - return this.display.collidesWith == 0; + return this.stats.collidesWith == 0; } // checks for any entity within a certain boundingbox, eg minecarts @Override protected void collideWithNearbyEntities() { - if(this.display.collidesWith != 1) { + if(this.stats.collidesWith != 1) { List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D)); if (list != null && !list.isEmpty()) { @@ -1787,8 +1787,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti Entity entity = (Entity) list.get(i); if (this.canBePushed() || - (entity instanceof EntityNPCInterface && (this.display.collidesWith == 2 || this.display.collidesWith == 4)) || - (entity instanceof EntityPlayerMP && (this.display.collidesWith == 3 || this.display.collidesWith == 4)) + (entity instanceof EntityNPCInterface && (this.stats.collidesWith == 2 || this.stats.collidesWith == 4)) || + (entity instanceof EntityPlayerMP && (this.stats.collidesWith == 3 || this.stats.collidesWith == 4)) ) { super.collideWithEntity(entity); } @@ -1824,8 +1824,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti d0 *= (double)(1.0F - this.entityCollisionReduction); d1 *= (double)(1.0F - this.entityCollisionReduction); if (this.canBePushed() || - (entity instanceof EntityNPCInterface && (this.display.collidesWith == 2 || this.display.collidesWith == 4)) || - (entity instanceof EntityPlayerMP && (this.display.collidesWith == 3 || this.display.collidesWith == 4)) + (entity instanceof EntityNPCInterface && (this.stats.collidesWith == 2 || this.stats.collidesWith == 4)) || + (entity instanceof EntityPlayerMP && (this.stats.collidesWith == 3 || this.stats.collidesWith == 4)) ) this.addVelocity(-d0, 0.0D, -d1); entity.addVelocity(d0, 0.0D, d1); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index fc2ca4852..d9f02a23a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -1363,10 +1363,10 @@ public class ScriptNpc extends ScriptLiving imp } public void setCollisionType(int type){ - npc.display.collidesWith = type; + npc.stats.collidesWith = type; } public int getCollisionType(){ - return npc.display.collidesWith; + return npc.stats.collidesWith; } public void updateClient() { this.npc.updateClient(); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index f16677ed9..c7e162574 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -263,7 +263,6 @@ display.overlay=Overlay display.player=Player display.selectTexture=Select Texture display.livingAnimation=Has a living animation -display.collides=Collides With Entities display.visible=Visible display.bossbar=BossBar display.squareTexture=Square Texture @@ -402,6 +401,7 @@ stats.attackInvisible=Attack Invi stats.never=Never stats.inWater=In Water stats.inAir=In Air +stats.collides=CollisionWith stats.size=Size stats.speed=Speed