From a4361b84205b36d381f850569d1db855256391a7 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Tue, 24 May 2022 03:06:16 -0500 Subject: [PATCH 01/16] Added various things to the API and other small changes This adds some useful functions to the api and a few other changes. I had been creating a custom build of this mod while working on stuff because I couldn't figure out how to do certain things without changing the mod. So this is a collection api features that I think everyone would find useful. Api additions: -purchase counting, and disabling trades for the trader role. (if a trade is disabled the gui still says insufficient funds, maybe allow a custom message to appear) added get the traders currency items and sell items. -if an npc's projectile does explosive damage, you can disable it destroying blocks even if mob griefing is on -int arrays as stored data for entities -entity.playSound(...) -get set if npcs can drown -player read and unread dialog -player set faction points -extra player.sendMessage functions to add custom colors/bold/underline -player clear inventory -get set if a follower npc is following a player or waiting -a bunch of stuff to script faction -is an item food and how many food points? -get scoreboard team by it's name -get and create factions from the script world -world.rayCastBlockPos is used for getting what block a player is looking at. -world.getNearestAir is meant to get the block of air above or around the result of world.rayCastBlockPos, or at least that's how I've been using it. Changes: -in NoppesUtilServer I feel like if an npc is cloned it's ticksExisted or age should bee zero -follower npcs should have the canDespawn field automatically set to false...? maybe make it an option --- .../java/noppes/npcs/NoppesUtilServer.java | 2 + .../npcs/containers/ContainerNPCTrader.java | 3 +- .../npcs/entity/EntityNPCInterface.java | 7 +- .../noppes/npcs/entity/EntityProjectile.java | 4 +- .../java/noppes/npcs/roles/JobFollower.java | 1 + .../java/noppes/npcs/roles/RoleFollower.java | 1 + .../java/noppes/npcs/roles/RoleTrader.java | 18 ++- .../noppes/npcs/scripted/ScriptFaction.java | 77 +++++++++++++ .../noppes/npcs/scripted/ScriptItemStack.java | 11 ++ .../npcs/scripted/ScriptScoreboard.java | 10 ++ .../npcs/scripted/ScriptScoreboardTeam.java | 4 + .../noppes/npcs/scripted/ScriptWorld.java | 108 ++++++++++++++++++ .../npcs/scripted/entity/ScriptEntity.java | 25 +++- .../npcs/scripted/entity/ScriptNpc.java | 20 +++- .../npcs/scripted/entity/ScriptPlayer.java | 62 ++++++++++ .../npcs/scripted/interfaces/ICustomNpc.java | 10 +- .../npcs/scripted/interfaces/IEntity.java | 7 +- .../npcs/scripted/interfaces/IPlayer.java | 22 +++- .../npcs/scripted/interfaces/IWorld.java | 36 +++++- .../scripted/roles/ScriptRoleFollower.java | 8 ++ .../npcs/scripted/roles/ScriptRoleTrader.java | 45 ++++++++ 21 files changed, 468 insertions(+), 13 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index eff4322f9..eef05193c 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -658,6 +658,8 @@ public class NoppesUtilServer { if(entity instanceof EntityNPCInterface){ EntityNPCInterface npc = (EntityNPCInterface) entity; npc.ai.startPos = new int[]{MathHelper.floor_double(npc.posX),MathHelper.floor_double(npc.posY),MathHelper.floor_double(npc.posZ)}; + npc.ticksExisted = 0; + npc.totalTicksAlive = 0; } worldObj.spawnEntityInWorld(entity); return entity; diff --git a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java index 77a3b8a43..5459ccc0a 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java +++ b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java @@ -66,6 +66,7 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ NoppesUtilPlayer.consumeItem(entityplayer, role.inventoryCurrency.getStackInSlot(i + 18), role.ignoreDamage, role.ignoreNBT); ItemStack soldItem = item.copy(); givePlayer(soldItem, entityplayer); + ++role.purchases[i]; return soldItem; } @@ -74,7 +75,7 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ ItemStack currency2 = role.inventoryCurrency.getStackInSlot(slot + 18); if(currency == null && currency2 == null) return true; - + if (role.disableSlot[slot] > 0) return false; if(currency == null){ currency = currency2; currency2 = null; diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index c8b672a82..a0b075600 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -139,7 +139,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public boolean updateClient = false; public boolean updateAI = false; - + public boolean projectilesKeepTerrain = false; + public FlyingMoveHelper flyMoveHelper = new FlyingMoveHelper(this); public PathNavigate flyNavigator = new PathNavigateFlying(this, worldObj); @@ -956,6 +957,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti totalTicksAlive = compound.getLong("TotalTicksAlive"); linkedName = compound.getString("LinkedNpcName"); + + projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain"); + if(!isRemote()) LinkedNpcController.Instance.loadNpcData(this); @@ -987,6 +991,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti compound.setLong("TotalTicksAlive", totalTicksAlive); compound.setInteger("ModRev", npcVersion); compound.setString("LinkedNpcName", linkedName); + compound.setBoolean("ProjectilesKeepTerrain", projectilesKeepTerrain); } public void updateHitbox() { diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index dec7f789e..dad83d04c 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -77,6 +77,7 @@ public class EntityProjectile extends EntityThrowable { public boolean accelerate = false; public boolean explosive = false; public boolean explosiveDamage = true; + public boolean destroyTerrain = true; public int explosiveRadius = 0; public EnumPotionType effect = EnumPotionType.None; public int duration = 5; @@ -138,6 +139,7 @@ public class EntityProjectile extends EntityThrowable { if (isNPC) { this.npc = (EntityNPCInterface) this.thrower; this.getStatProperties(this.npc.stats); + this.destroyTerrain = !this.npc.projectilesKeepTerrain; } } @@ -562,7 +564,7 @@ public class EntityProjectile extends EntityThrowable { if (explosive){ if (this.explosiveRadius != 0 || this.effect == EnumPotionType.None){ - boolean terraindamage = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing") && explosiveDamage; + boolean terraindamage = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing") && explosiveDamage && destroyTerrain; Explosion explosion = new Explosion(worldObj, this, posX, posY, posZ, explosiveRadius); explosion.isFlaming = this.effect == EnumPotionType.Fire; explosion.isSmoking = terraindamage; diff --git a/src/main/java/noppes/npcs/roles/JobFollower.java b/src/main/java/noppes/npcs/roles/JobFollower.java index 69e44850a..7d6e6d65b 100644 --- a/src/main/java/noppes/npcs/roles/JobFollower.java +++ b/src/main/java/noppes/npcs/roles/JobFollower.java @@ -15,6 +15,7 @@ public class JobFollower extends JobInterface{ public JobFollower(EntityNPCInterface npc) { super(npc); + npc.stats.canDespawn = false; } @Override diff --git a/src/main/java/noppes/npcs/roles/RoleFollower.java b/src/main/java/noppes/npcs/roles/RoleFollower.java index 67a578f3c..8c885820c 100644 --- a/src/main/java/noppes/npcs/roles/RoleFollower.java +++ b/src/main/java/noppes/npcs/roles/RoleFollower.java @@ -35,6 +35,7 @@ public class RoleFollower extends RoleInterface{ super(npc); inventory = new NpcMiscInventory(3); rates = new HashMap(); + npc.stats.canDespawn = false; } @Override diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index d8da53a7c..b6f21eda6 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -24,10 +24,15 @@ public class RoleTrader extends RoleInterface{ public boolean toSave = false; + public int[] purchases; + public int[] disableSlot; + public RoleTrader(EntityNPCInterface npc) { super(npc); inventoryCurrency = new NpcMiscInventory(36); inventorySold = new NpcMiscInventory(18); + purchases = new int[18]; + disableSlot = new int[18]; } @Override @@ -46,6 +51,8 @@ public class RoleTrader extends RoleInterface{ nbttagcompound.setTag("TraderSold", inventorySold.getToNBT()); nbttagcompound.setBoolean("TraderIgnoreDamage", ignoreDamage); nbttagcompound.setBoolean("TraderIgnoreNBT", ignoreNBT); + nbttagcompound.setIntArray("Purchases", purchases); + nbttagcompound.setIntArray("DisableSlot", disableSlot); return nbttagcompound; } @@ -67,7 +74,16 @@ public class RoleTrader extends RoleInterface{ inventorySold.setFromNBT(nbttagcompound.getCompoundTag("TraderSold")); ignoreDamage = nbttagcompound.getBoolean("TraderIgnoreDamage"); ignoreNBT = nbttagcompound.getBoolean("TraderIgnoreNBT"); - + purchases = nbttagcompound.getIntArray("Purchases"); + if (purchases == null || purchases.length < 18) { + purchases = new int[18]; + for (int i = 0; i < purchases.length; ++i) purchases[i] = 0; + } + disableSlot = nbttagcompound.getIntArray("DisableSlot"); + if (disableSlot == null || disableSlot.length < 18) { + disableSlot = new int[18]; + for (int i = 0; i < disableSlot.length; ++i) disableSlot[i] = 0; + } } @Override diff --git a/src/main/java/noppes/npcs/scripted/ScriptFaction.java b/src/main/java/noppes/npcs/scripted/ScriptFaction.java index 972ecaf2b..2fc999337 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptFaction.java +++ b/src/main/java/noppes/npcs/scripted/ScriptFaction.java @@ -1,11 +1,17 @@ package noppes.npcs.scripted; import noppes.npcs.controllers.Faction; +import noppes.npcs.controllers.FactionController; import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.entity.ScriptPlayer; public class ScriptFaction { + private Faction faction; + + public void saveFaction() { + FactionController.getInstance().saveFaction(faction); + } public ScriptFaction(Faction faction){ this.faction = faction; @@ -25,14 +31,58 @@ public class ScriptFaction { return faction.name; } + public void setName(String name) { + faction.name = name; + } + public int getDefaultPoints(){ return faction.defaultPoints; } + + public void setDefaultPoints(int p) { + faction.defaultPoints = p; + } + + public int getFriendlyPoints() { + return faction.friendlyPoints; + } + + public void setFriendlyPoints(int p) { + faction.friendlyPoints = p; + } + + public int getNeutralPoints() { + return faction.neutralPoints; + } + + public void setNeutralPoints(int p) { + faction.neutralPoints = p; + } + + public boolean getHideFaction() { + return faction.hideFaction; + } + + public void setHideFaction(boolean b) { + faction.hideFaction = b; + } + + public boolean getGetsAttacked() { + return faction.getsAttacked; + } + + public void setGetsAttacked(boolean b) { + faction.getsAttacked = b; + } public int getColor(){ return faction.color; } + public void setColor(int c) { + faction.color = c; + } + public boolean isFriendlyToPlayer(ScriptPlayer player){ return faction.isFriendlyToPlayer(player.player); } @@ -48,4 +98,31 @@ public class ScriptFaction { public boolean isAggressiveToNpc(ScriptNpc npc){ return faction.isAggressiveToNpc(npc.npc); } + + public int[] getFactionEnemies() { + if (faction.attackFactions == null) return null; + int[] r = new int[faction.attackFactions.size()]; + Object[] objects = faction.attackFactions.toArray(); + for (int i = 0; i < r.length; ++i) { + r[i] = (Integer)objects[i]; + } + return r; + } + + public boolean isEnemyFaction(int id) { + if (faction.attackFactions == null) return false; + int[] enemies = getFactionEnemies(); + for (int i = 0; i < enemies.length; ++i) { + if (enemies[i] == id) return true; + } + return false; + } + + public void addFactionEnemy(int id) { + if (!faction.attackFactions.contains(id)) faction.attackFactions.add(id); + } + + public void removeFactionEnemy(int id) { + faction.attackFactions.remove(id); + } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java index 81fb082a0..f15b8d41a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/ScriptItemStack.java @@ -6,12 +6,14 @@ import java.util.List; import java.util.Map; import com.google.common.collect.Multimap; + import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; +import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase.NBTPrimitive; @@ -346,6 +348,15 @@ public class ScriptItemStack implements IItemStack { return false; return true; } + + public boolean isFood() { + return item.getItem() instanceof ItemFood; + } + + public int getFoodPoints() { + if (isFood()) return ((ItemFood)item.getItem()).func_150905_g(item); + return -1; + } public INbt getNbt() { NBTTagCompound compound = this.item.getTagCompound(); diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java b/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java index 603f88ec8..513f9cc7f 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java +++ b/src/main/java/noppes/npcs/scripted/ScriptScoreboard.java @@ -152,6 +152,16 @@ public class ScriptScoreboard { return teams; } + public ScriptScoreboardTeam getTeamByName(String name) { + ScriptScoreboardTeam[] teams = getTeams(); + for (int i = 0; i < teams.length; i++) { + if (teams[i].getName().equals(name)) { + return teams[i]; + } + } + return null; + } + public boolean hasTeam(String name){ return board.getPlayersTeam(name) != null; } diff --git a/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java b/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java index 639ee0b3e..bed2b0a24 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java +++ b/src/main/java/noppes/npcs/scripted/ScriptScoreboardTeam.java @@ -44,6 +44,10 @@ public class ScriptScoreboardTeam { return list.toArray(new String[list.size()]); } + public int getTeamsize() { + return team.getMembershipCollection().size(); + } + public void clearPlayers(){ List list = new ArrayList(team.getMembershipCollection()); for(String player : list){ diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index cbcc43f48..b2e7fe1cd 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -3,6 +3,7 @@ package noppes.npcs.scripted; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -18,11 +19,14 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; +import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; +import noppes.npcs.controllers.Faction; +import noppes.npcs.controllers.FactionController; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.scripted.entity.ScriptEntity; @@ -93,6 +97,14 @@ public class ScriptWorld implements IWorld { return null; } + public void setBlock(int x, int y, int z, Block block){ + if(block == null || block == Blocks.air){ + removeBlock(x, y, z); + return; + } + world.setBlock(x, y, z, block); + } + /** * @param x World position x * @param y World position y @@ -119,6 +131,61 @@ public class ScriptWorld implements IWorld { world.setBlock(x, y, z, Blocks.air); } + public Vec3 rayCastBlockPos(Vec3 pos, Vec3 look, int maxDistance) { + Vec3 currentPos = pos; int rep = 0; + while (rep++ < maxDistance + 10) { + currentPos = currentPos.addVector(look.xCoord, look.yCoord, look.zCoord); + IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + //System.out.println("Checking block at ["+(int)currentPos.xCoord+","+(int)currentPos.yCoord+","+(int)currentPos.zCoord+"]"); + if (block == null) continue; + double distance = Math.pow( + Math.pow(currentPos.xCoord-pos.xCoord,2) + +Math.pow(currentPos.yCoord-pos.yCoord,2) + +Math.pow(currentPos.zCoord-pos.zCoord,2) + , 0.5); + //System.out.println("current distance check: "+distance+" on rep "+rep); + if (distance > maxDistance) return null; + return currentPos; + } + //System.out.println("ScriptWorld:WARNING: Repeated a ray cast to many times"); + return null; + } + + public Vec3 getNearestAir(Vec3 pos, int maxHeight) { + if (pos == null) return null; + Vec3 currentPos = pos; + IBlock block = null; int rep = 0; + while (rep++ < maxHeight) { + //check +x + currentPos = currentPos.addVector(1, 0, 0); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check -x + currentPos = currentPos.addVector(-2, 0, 0); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check +z + currentPos = currentPos.addVector(1, 0, 1); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check -z + currentPos = currentPos.addVector(0, 0, -2); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + //check up 1 + currentPos = currentPos.addVector(0, 1, 1); + block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + if (block == null) break; + } + Vec3 posInt = Vec3.createVectorHelper((int)currentPos.xCoord, + (int)currentPos.yCoord, (int)currentPos.zCoord); + return posInt; + } + + public boolean canSeeSky(int x, int y, int z) { + return world.canBlockSeeTheSky(x, y, z); + } + /** * @param name The name of the player to be returned * @return The Player with name. Null is returned when the player isnt found @@ -317,6 +384,13 @@ public class ScriptWorld implements IWorld { return arr; } + public String[] getPlayerNames() { + ScriptPlayer[] players = getAllServerPlayers(); + String[] names = new String[players.length]; + for (int i = 0; i < names.length; ++i) names[i] = players[i].getDisplayName(); + return names; + } + /** * @since 1.7.10c * @param x Position x @@ -346,6 +420,40 @@ public class ScriptWorld implements IWorld { return ScriptController.Instance.getScriptForEntity(entity); } + public boolean spawnEntity(Entity e) { + if (world.spawnEntityInWorld(e)) return true; + return false; + } + + /** + * Create a new default faction + * @param name The name of the new faction. If the name already exists an '_' will be added at the end + * @return The faction object which was created + */ + public ScriptFaction createFaction(String name) { + //System.out.println("Attempting to create new faction "+name); + int maxValue = 0xFFFFFF; + Random r = new Random(); + int randomColor = r.nextInt(maxValue + 1); + + Faction fac = new Faction(-1, name, randomColor, 1000); + FactionController.getInstance().saveFaction(fac); + + return new ScriptFaction(fac); + } + + public ScriptFaction getFactionFromName(String name) { + Faction f = FactionController.getInstance().getFactionFromName(name); + if (f == null) return null; + return new ScriptFaction(f); + } + + public ScriptFaction getFactionFromId(int id) { + Faction f = FactionController.getInstance().get(id); + if (f == null) return null; + return new ScriptFaction(f); + } + public ScriptScoreboard getScoreboard(){ return new ScriptScoreboard(); } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index ca7d500b2..5434300ad 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -15,8 +15,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase.NBTPrimitive; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; @@ -24,7 +24,12 @@ import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityNPCInterface; -import noppes.npcs.scripted.*; +import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptBlockPos; +import noppes.npcs.scripted.ScriptEntityParticle; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IEntity; import noppes.npcs.scripted.interfaces.INbt; @@ -313,6 +318,10 @@ public class ScriptEntity implements IEntity { public void setPos(IPos pos) { this.entity.setPosition((double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F)); } + + public int getDimension() { + return entity.dimension; + } /** * @param range The search range for entities around this entity @@ -413,6 +422,8 @@ public class ScriptEntity implements IEntity { NBTBase base = compound.getTag(key); if(base instanceof NBTPrimitive) return ((NBTPrimitive)base).func_150286_g(); + else if (base instanceof NBTTagIntArray) + return ((NBTTagIntArray)base).func_150302_c(); return ((NBTTagString)base).func_150285_a_(); } @@ -430,6 +441,12 @@ public class ScriptEntity implements IEntity { compound.setString(key, (String)value); saveStoredCompound(compound); } + + public void setStoredData(String key, int[] array){ + NBTTagCompound compound = getStoredCompound(); + compound.setIntArray(key, array); + saveStoredCompound(compound); + } /** * @param key The key of the data to be checked @@ -528,6 +545,10 @@ public class ScriptEntity implements IEntity { public String getTypeName(){ return EntityList.getEntityString(entity); } + + public void playSound(String name, float volume, float pitch) { + entity.playSound(name, volume, pitch); + } /** * @param item Item to be dropped diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index a777901ae..7775de977 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -269,6 +269,16 @@ public class ScriptNpc extends ScriptLiving imp npc.shoot(target.entity, accuracy, item.item, false); } + public void setProjectilesKeepTerrain(boolean t) { + npc.projectilesKeepTerrain = t; + } + + public boolean getProjectilesKeepTerrain() { + return npc.projectilesKeepTerrain; + } + + + /** * @param message The message the npc will say */ @@ -524,7 +534,8 @@ public class ScriptNpc extends ScriptLiving imp * @param item The item the drop list slot will be changed to */ public void setLootItem(int slot, ScriptItemStack item) { - npc.inventory.setInventorySlotContents(slot+7, item.item); + if (item == null) npc.inventory.setInventorySlotContents(slot+7, null); + else npc.inventory.setInventorySlotContents(slot+7, item.item); } /** @@ -1000,6 +1011,13 @@ public class ScriptNpc extends ScriptLiving imp npc.stats.healthRegen = (float)(Math.floor(regen)); } + public boolean getCanDrown() { + return npc.stats.canDrown; + } + public void setCanDrown(boolean d) { + npc.stats.canDrown = d; + } + @Override public long getAge(){ return npc.totalTicksAlive; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index d3b1fc98f..855188037 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -9,7 +9,10 @@ import net.minecraft.stats.Achievement; import net.minecraft.stats.StatBase; import net.minecraft.stats.StatList; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; import net.minecraft.world.WorldSettings; import noppes.npcs.*; import noppes.npcs.constants.EnumPacketClient; @@ -21,6 +24,7 @@ import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; +import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.gui.ScriptGui; @@ -120,6 +124,14 @@ public class ScriptPlayer extends ScriptLivingBase PlayerDialogData data = PlayerDataController.instance.getPlayerData(player).dialogData; return data.dialogsRead.contains(id); } + + public void readDialog(int id) { + PlayerDataController.instance.getPlayerData(player).dialogData.dialogsRead.add(id); + } + + public void unreadDialog(int id) { + PlayerDataController.instance.getPlayerData(player).dialogData.dialogsRead.remove(id); + } /** * Add the quest from active quest list @@ -192,6 +204,14 @@ public class ScriptPlayer extends ScriptLivingBase PlayerData data = PlayerDataController.instance.getPlayerData(player); data.factionData.increasePoints(faction, points, player); } + /** + * @param faction The faction id + * @param points The new point value for this faction + */ + public void setFactionPoints(int faction, int points) { + PlayerData data = PlayerDataController.instance.getPlayerData(player); + data.factionData.increasePoints(faction, points-getFactionPoints(faction), player); + } /** * @param faction The faction id @@ -209,6 +229,36 @@ public class ScriptPlayer extends ScriptLivingBase player.addChatMessage(new ChatComponentTranslation(NoppesStringUtils.formatText(message,player))); } + /** + * @param message The message you want to send + */ + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean underlined) { + ChatComponentTranslation chat = new ChatComponentTranslation(NoppesStringUtils.formatText(message,player)); + ChatStyle style = new ChatStyle(); + style.setColor(color); + style.setBold(bold); + style.setItalic(italic); + style.setUnderlined(underlined); + chat.setChatStyle(style); + player.addChatMessage(chat); + } + + /** + * @param message The message you want to send + */ + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined) { + ChatComponentTranslation chat = new ChatComponentTranslation(NoppesStringUtils.formatText(message,player)); + ChatStyle style = new ChatStyle(); + style.setColor(color); + style.setBold(bold); + style.setItalic(italic); + style.setObfuscated(obfuscated); + style.setStrikethrough(strikethrough); + style.setUnderlined(underlined); + chat.setChatStyle(style); + player.addChatMessage(chat); + } + /** * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure */ @@ -352,6 +402,11 @@ public class ScriptPlayer extends ScriptLivingBase player.inventory.mainInventory[i] = null; } } + + public void clearInventory() { + for(int i = 0; i < player.inventory.mainInventory.length; i++) player.inventory.mainInventory[i] = null; + for(int i = 0; i < player.inventory.armorInventory.length; i++) player.inventory.armorInventory[i] = null; + } public void setRotation(float rotationYaw){ NoppesUtilPlayer.teleportPlayer(player, player.posX, player.posY, player.posZ, rotationYaw, player.rotationPitch, player.dimension); @@ -407,6 +462,13 @@ public class ScriptPlayer extends ScriptLivingBase return null; return new ScriptPixelmonPlayerData(player); } + + public Vec3 getLookingAtBlock(int maxDistance) { + Vec3 posVec = Vec3.createVectorHelper(player.posX, + player.posY+player.getEyeHeight(), player.posZ); + Vec3 lookVec = player.getLookVec(); + return NpcAPI.Instance().getIWorld(player.dimension).rayCastBlockPos(posVec, lookVec, maxDistance); + } public ITimers getTimers() { return PlayerDataController.instance.getPlayerData(player).timers; diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java index 47f0fa7ab..6f3e5bdcc 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java @@ -162,6 +162,10 @@ public interface ICustomNpc extends IEntityLiving { * @param accuracy Accuracy of the shot (0-100) */ public void shootItem(ScriptLivingBase target, ScriptItemStack item, int accuracy); + + public void setProjectilesKeepTerrain(boolean b); + + public boolean getProjectilesKeepTerrain(); /** * @param message The message the npc will say @@ -343,7 +347,11 @@ public interface ICustomNpc extends IEntityLiving { * @return The maximum XP gained from killing the NPC. */ public int getMaxLootXP(); - + + public boolean getCanDrown(); + + public void setCanDrown(boolean b); + /** * @param type The AnimationType */ diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index a806676d9..83618ef57 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -129,7 +129,8 @@ public interface IEntity { * @param z The z position */ public void setPosition(double x, double y, double z); - + + public int getDimension(); /** * @param range The search range for entities around this entity @@ -190,6 +191,8 @@ public interface IEntity { * @param value The data stored. This data can be either a Number or a String. Other data is not stored */ public void setStoredData(String key, Object value); + + public void setStoredData(String key, int[] array); /** * @param key The key of the data to be checked @@ -251,6 +254,8 @@ public interface IEntity { * @return Name as which it's registered in minecraft */ public String getTypeName(); + + public void playSound(String name, float volume, float pitch); /** * @param item Item to be dropped diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index cafe9629e..6d1799193 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -1,6 +1,8 @@ package noppes.npcs.scripted.interfaces; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; @@ -26,6 +28,10 @@ public interface IPlayer extends IEntityLivingBase public void showDialog(int id); public boolean hasReadDialog(int id); + + public void readDialog(int id); + + public void unreadDialog(int id); /** * Add the quest from active quest list @@ -58,7 +64,11 @@ public interface IPlayer extends IEntityLivingBase * @param points The points to increase. Use negative values to decrease */ public void addFactionPoints(int faction, int points); - + /** + * @param faction The faction id + * @param points The new point value for this faction + */ + public void setFactionPoints(int faction, int points); /** * @param faction The faction id * @return points @@ -69,7 +79,11 @@ public interface IPlayer extends IEntityLivingBase * @param message The message you want to send */ public void sendMessage(String message); - + + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean underlined); + + public void sendMessage(String message, EnumChatFormatting color, boolean bold, boolean italic, boolean obfuscated, boolean strikethrough, boolean underlined); + /** * @return Return gamemode. 0: Survival, 1: Creative, 2: Adventure */ @@ -139,6 +153,8 @@ public interface IPlayer extends IEntityLivingBase * @param item The item to be removed from the players inventory */ public void removeAllItems(ScriptItemStack item); + + public void clearInventory(); /** @@ -170,6 +186,8 @@ public interface IPlayer extends IEntityLivingBase * @since 1.7.10d */ public ScriptPixelmonPlayerData getPixelmonData(); + + public Vec3 getLookingAtBlock(int maxDistance); public ITimers getTimers(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 9c7b14534..fe09a6df1 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -1,5 +1,8 @@ package noppes.npcs.scripted.interfaces; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -42,13 +45,27 @@ public interface IWorld { * @param item The block to be set */ public void setBlock(int x, int y, int z, ScriptItemStack item); - + + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @param block The block to be set + */ + public void setBlock(int x, int y, int z, Block 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); + + public Vec3 rayCastBlockPos(Vec3 pos, Vec3 look, int maxDistance); + + public Vec3 getNearestAir(Vec3 pos, int maxHeight); + + public boolean canSeeSky(int x, int y, int z); /** * @param name The name of the player to be returned @@ -180,6 +197,8 @@ public interface IWorld { public void explode(double x, double y, double z, float range, boolean fire, boolean grief); public ScriptPlayer[] getAllServerPlayers(); + + public String[] getPlayerNames(); /** * @since 1.7.10c @@ -199,7 +218,20 @@ public interface IWorld { * @return Returns the entity which was spawned */ public ScriptEntity spawnClone(int x, int y, int z, int tab, String name); - + + public boolean spawnEntity(Entity e); + + /** + * Create a new default faction + * @param name The name of the new faction. If the name already exists an '_' will be added at the end + * @return The faction object which was created + */ + public ScriptFaction createFaction(String name); + + public ScriptFaction getFactionFromName(String name); + + public ScriptFaction getFactionFromId(int id); + public ScriptScoreboard getScoreboard(); BlockPos getMCBlockPos(int x, int y, int z); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java index d10bd8dad..1041e3f17 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java @@ -46,6 +46,14 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ return role.owner != null; } + public boolean isFollowing() { + return role.isFollowing(); + } + + public void setIsFollowing(boolean following) { + if (role.owner != null && role.getDaysLeft() > 0) role.isFollowing = following; + } + /** * @since 1.7.10c * @return Returns days left diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 353afc2fb..1a128d214 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -46,6 +46,32 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ setSellOption(slot, currency, null, sold); } + /** + * @param slot + * @return The item being sold in this slot. + */ + public ScriptItemStack getSellOption(int slot) { + if (slot >= 18 || slot < 0) return null; + if (role.inventorySold.items.get(slot) == null) return null; + return new ScriptItemStack(role.inventorySold.items.get(slot)); + } + + /** + * @param slot + * @return a ScriptItemStack array of size 2 which contains the currency of this trade + */ + public ScriptItemStack[] getCurrency(int slot) { + if (slot >= 18 || slot < 0) return null; + ScriptItemStack[] currency = new ScriptItemStack[2]; + if (role.inventoryCurrency.items.get(slot) != null) { + currency[0] = new ScriptItemStack(role.inventoryCurrency.items.get(slot)); + } + if (role.inventoryCurrency.items.get(slot + 18) != null) { + currency[1] = new ScriptItemStack(role.inventoryCurrency.items.get(slot + 18)); + } + return currency; + } + /** * @param slot Slot number 0-17 */ @@ -70,6 +96,25 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ public String getMarket(){ return role.marketName; } + + public int getPurchaseNum(int slot) { + if(slot >= 18 || slot < 0) return -1; + return role.purchases[slot]; + } + + public void resetPurchaseNum() { + for (int i = 0; i < role.purchases.length; ++i) role.purchases[i] = 0; + } + + public void disableSlot(int slot) { + if(slot >= 18 || slot < 0) return; + role.disableSlot[slot] = 1; + } + + public void enableSlot(int slot) { + if(slot >= 18 || slot < 0) return; + role.disableSlot[slot] = 0; + } @Override public int getType(){ From b97d4eeeb28d337127cc100493ace3af3800250d Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Wed, 25 May 2022 18:38:54 -0500 Subject: [PATCH 02/16] added resetPurchaseNum(int slot) --- .../npcs/scripted/roles/ScriptRoleTrader.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 1a128d214..2abb3249a 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -97,20 +97,43 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ return role.marketName; } + /** + * @param slot + * @return the number of times an item has been sold on that slot + */ public int getPurchaseNum(int slot) { if(slot >= 18 || slot < 0) return -1; return role.purchases[slot]; } + /** + * Sets the purchase count of all slots to 0 + */ public void resetPurchaseNum() { for (int i = 0; i < role.purchases.length; ++i) role.purchases[i] = 0; } + /** + * sets the purchase num for that slot to 0 + * @param slot + */ + public void resetPurchaseNum(int slot) { + role.purchases[slot] = 0; + } + + /** + * prevent an item from being sold on that slot + * @param slot + */ public void disableSlot(int slot) { if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 1; } + /** + * allow an item to be sold on that slot + * @param slot + */ public void enableSlot(int slot) { if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 0; From aba637be14f9b11936ae64f2ac4631eb192b2d9b Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Wed, 25 May 2022 23:56:36 -0500 Subject: [PATCH 03/16] removed redundant faction functions Luis C.M. will add API.getFactions() which returns the FactionController. All these functions use the faction controller anyway. Also Luis PR already has entity.getDimension and world.spawnEntity --- .../noppes/npcs/scripted/ScriptWorld.java | 34 ------------------- .../npcs/scripted/entity/ScriptEntity.java | 4 --- .../npcs/scripted/interfaces/IEntity.java | 2 -- .../npcs/scripted/interfaces/IWorld.java | 13 ------- 4 files changed, 53 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index b2e7fe1cd..c84774456 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -420,40 +420,6 @@ public class ScriptWorld implements IWorld { return ScriptController.Instance.getScriptForEntity(entity); } - public boolean spawnEntity(Entity e) { - if (world.spawnEntityInWorld(e)) return true; - return false; - } - - /** - * Create a new default faction - * @param name The name of the new faction. If the name already exists an '_' will be added at the end - * @return The faction object which was created - */ - public ScriptFaction createFaction(String name) { - //System.out.println("Attempting to create new faction "+name); - int maxValue = 0xFFFFFF; - Random r = new Random(); - int randomColor = r.nextInt(maxValue + 1); - - Faction fac = new Faction(-1, name, randomColor, 1000); - FactionController.getInstance().saveFaction(fac); - - return new ScriptFaction(fac); - } - - public ScriptFaction getFactionFromName(String name) { - Faction f = FactionController.getInstance().getFactionFromName(name); - if (f == null) return null; - return new ScriptFaction(f); - } - - public ScriptFaction getFactionFromId(int id) { - Faction f = FactionController.getInstance().get(id); - if (f == null) return null; - return new ScriptFaction(f); - } - public ScriptScoreboard getScoreboard(){ return new ScriptScoreboard(); } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 5434300ad..2e3c734bf 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -318,10 +318,6 @@ public class ScriptEntity implements IEntity { public void setPos(IPos pos) { this.entity.setPosition((double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F)); } - - public int getDimension() { - return entity.dimension; - } /** * @param range The search range for entities around this entity diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java index 83618ef57..7e77cad95 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IEntity.java @@ -129,8 +129,6 @@ public interface IEntity { * @param z The z position */ public void setPosition(double x, double y, double z); - - public int getDimension(); /** * @param range The search range for entities around this entity diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index fe09a6df1..64d035d05 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -219,19 +219,6 @@ public interface IWorld { */ public ScriptEntity spawnClone(int x, int y, int z, int tab, String name); - public boolean spawnEntity(Entity e); - - /** - * Create a new default faction - * @param name The name of the new faction. If the name already exists an '_' will be added at the end - * @return The faction object which was created - */ - public ScriptFaction createFaction(String name); - - public ScriptFaction getFactionFromName(String name); - - public ScriptFaction getFactionFromId(int id); - public ScriptScoreboard getScoreboard(); BlockPos getMCBlockPos(int x, int y, int z); From 422dd3fc906401541f1f7cd0d6a770cf1ddb6090 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 01:43:17 -0500 Subject: [PATCH 04/16] added trader.slotdisabled to trader gui I just copied what was done to display the trader.insufficient and added trader.slotdisabled to en_US.lang --- .gitignore | 3 ++- .../java/noppes/npcs/client/gui/player/GuiNPCTrader.java | 4 ++++ .../java/noppes/npcs/containers/ContainerNPCTrader.java | 6 +++++- .../java/noppes/npcs/scripted/roles/ScriptRoleTrader.java | 8 +++++++- src/main/resources/assets/customnpcs/lang/en_US.lang | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ca28fe9ef..29bbc6b88 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ eclipse .project .settings bin -.metadata \ No newline at end of file +.metadata +*.bak diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java b/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java index 81ffe1346..6536f822f 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNPCTrader.java @@ -117,6 +117,10 @@ public class GuiNPCTrader extends GuiContainerNPCInterface{ this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title))/2, 131, 0xDD0000); GL11.glTranslatef(0, 0, -300); } + else if (!container.isSlotEnabled(slot, player)) { + String title = StatCollector.translateToLocal("trader.slotdisabled"); + this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title))/2, 131, 0x00DD00); + } else{ String title = StatCollector.translateToLocal("trader.sufficient"); this.fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title))/2, 131, 0x00DD00); diff --git a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java index 5459ccc0a..1165fea6f 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java +++ b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java @@ -62,6 +62,8 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ return null; if(!canBuy(i, entityplayer)) return null; + if (!isSlotEnabled(i, entityplayer)) + return null; NoppesUtilPlayer.consumeItem(entityplayer, role.inventoryCurrency.getStackInSlot(i), role.ignoreDamage, role.ignoreNBT); NoppesUtilPlayer.consumeItem(entityplayer, role.inventoryCurrency.getStackInSlot(i + 18), role.ignoreDamage, role.ignoreNBT); ItemStack soldItem = item.copy(); @@ -70,12 +72,14 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ return soldItem; } + public boolean isSlotEnabled(int slot, EntityPlayer player) { + return role.disableSlot[slot] == 0; + } public boolean canBuy(int slot, EntityPlayer player) { ItemStack currency = role.inventoryCurrency.getStackInSlot(slot); ItemStack currency2 = role.inventoryCurrency.getStackInSlot(slot + 18); if(currency == null && currency2 == null) return true; - if (role.disableSlot[slot] > 0) return false; if(currency == null){ currency = currency2; currency2 = null; diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 2abb3249a..0e496569c 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -1,10 +1,11 @@ package noppes.npcs.scripted.roles; +import foxz.utils.Market; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.RoleType; -import foxz.utils.Market; +import noppes.npcs.scripted.interfaces.IPlayer; public class ScriptRoleTrader extends ScriptRoleInterface{ private RoleTrader role; @@ -106,6 +107,11 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ return role.purchases[slot]; } + public int getPurchaseNum(int slot, IPlayer player) { + // TODO get purchase num by player + return -1; + } + /** * Sets the purchase count of all slots to 0 */ diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 14502512f..bf212b636 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -222,6 +222,7 @@ role.companion=Companion trader.insufficient=Insufficient Currency trader.sufficient=Sufficient Currency +trader.slotdisabled=Slot Disabled job.name=Job job.none=No Job From 84973a025aaa6b49a1109f0fee8ad056f8b49989 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 01:45:10 -0500 Subject: [PATCH 05/16] moved projectilesKeepTerrain to DataStats --- src/main/java/noppes/npcs/DataStats.java | 3 +++ src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 4 ---- src/main/java/noppes/npcs/entity/EntityProjectile.java | 2 +- src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/noppes/npcs/DataStats.java b/src/main/java/noppes/npcs/DataStats.java index 48672d31f..acb1c691d 100644 --- a/src/main/java/noppes/npcs/DataStats.java +++ b/src/main/java/noppes/npcs/DataStats.java @@ -47,6 +47,7 @@ public class DataStats { public int pEffAmp = 0; public String fireSound = "random.bow"; public boolean aimWhileShooting = false; + public boolean projectilesKeepTerrain = false; public EnumCreatureAttribute creatureType = EnumCreatureAttribute.UNDEFINED; @@ -102,6 +103,7 @@ public class DataStats { compound.setInteger("pEffAmp", pEffAmp); compound.setString("FiringSound", fireSound); compound.setBoolean("AimWhileShooting", aimWhileShooting); + compound.setBoolean("ProjectilesKeepTerrain", projectilesKeepTerrain); compound.setBoolean("ImmuneToFire", immuneToFire); compound.setBoolean("PotionImmune", potionImmune); @@ -160,6 +162,7 @@ public class DataStats { pEffAmp = compound.getInteger("pEffAmp"); fireSound = compound.getString("FiringSound"); aimWhileShooting = compound.getBoolean("AimWhileShooting"); + projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain"); immuneToFire = compound.getBoolean("ImmuneToFire"); potionImmune = compound.getBoolean("PotionImmune"); diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index a0b075600..0f8e81f60 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -139,7 +139,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public boolean updateClient = false; public boolean updateAI = false; - public boolean projectilesKeepTerrain = false; public FlyingMoveHelper flyMoveHelper = new FlyingMoveHelper(this); public PathNavigate flyNavigator = new PathNavigateFlying(this, worldObj); @@ -958,8 +957,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti linkedName = compound.getString("LinkedNpcName"); - projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain"); - if(!isRemote()) LinkedNpcController.Instance.loadNpcData(this); @@ -991,7 +988,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti compound.setLong("TotalTicksAlive", totalTicksAlive); compound.setInteger("ModRev", npcVersion); compound.setString("LinkedNpcName", linkedName); - compound.setBoolean("ProjectilesKeepTerrain", projectilesKeepTerrain); } public void updateHitbox() { diff --git a/src/main/java/noppes/npcs/entity/EntityProjectile.java b/src/main/java/noppes/npcs/entity/EntityProjectile.java index dad83d04c..e0a1d0b21 100644 --- a/src/main/java/noppes/npcs/entity/EntityProjectile.java +++ b/src/main/java/noppes/npcs/entity/EntityProjectile.java @@ -139,7 +139,7 @@ public class EntityProjectile extends EntityThrowable { if (isNPC) { this.npc = (EntityNPCInterface) this.thrower; this.getStatProperties(this.npc.stats); - this.destroyTerrain = !this.npc.projectilesKeepTerrain; + this.destroyTerrain = !this.npc.stats.projectilesKeepTerrain; } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 7775de977..dca330886 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -270,11 +270,11 @@ public class ScriptNpc extends ScriptLiving imp } public void setProjectilesKeepTerrain(boolean t) { - npc.projectilesKeepTerrain = t; + npc.stats.projectilesKeepTerrain = t; } public boolean getProjectilesKeepTerrain() { - return npc.projectilesKeepTerrain; + return npc.stats.projectilesKeepTerrain; } From 067dafdbfae0b0bb37ac45768c3893361a8c628b Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 01:47:51 -0500 Subject: [PATCH 06/16] removed setting npc.stats.canDespawn to false in follower role this was pointless what I actually want to do is disable despawning if the npc has an owner --- src/main/java/noppes/npcs/roles/JobFollower.java | 1 - src/main/java/noppes/npcs/roles/RoleFollower.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/noppes/npcs/roles/JobFollower.java b/src/main/java/noppes/npcs/roles/JobFollower.java index 7d6e6d65b..69e44850a 100644 --- a/src/main/java/noppes/npcs/roles/JobFollower.java +++ b/src/main/java/noppes/npcs/roles/JobFollower.java @@ -15,7 +15,6 @@ public class JobFollower extends JobInterface{ public JobFollower(EntityNPCInterface npc) { super(npc); - npc.stats.canDespawn = false; } @Override diff --git a/src/main/java/noppes/npcs/roles/RoleFollower.java b/src/main/java/noppes/npcs/roles/RoleFollower.java index 8c885820c..67a578f3c 100644 --- a/src/main/java/noppes/npcs/roles/RoleFollower.java +++ b/src/main/java/noppes/npcs/roles/RoleFollower.java @@ -35,7 +35,6 @@ public class RoleFollower extends RoleInterface{ super(npc); inventory = new NpcMiscInventory(3); rates = new HashMap(); - npc.stats.canDespawn = false; } @Override From bc85756476f78f00571622eb0a1e975fdded19d7 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 01:51:05 -0500 Subject: [PATCH 07/16] player.getLookingAtBlock returns IBlock --- .../noppes/npcs/scripted/ScriptWorld.java | 18 +++++--- .../npcs/scripted/entity/ScriptPlayer.java | 43 +++++++++++++------ .../npcs/scripted/interfaces/IPlayer.java | 2 +- .../npcs/scripted/interfaces/IWorld.java | 2 +- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index c84774456..f98026e3a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -3,7 +3,6 @@ package noppes.npcs.scripted; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Random; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -21,12 +20,9 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; -import noppes.npcs.controllers.Faction; -import noppes.npcs.controllers.FactionController; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.scripted.entity.ScriptEntity; @@ -98,13 +94,21 @@ public class ScriptWorld implements IWorld { } public void setBlock(int x, int y, int z, Block block){ - if(block == null || block == Blocks.air){ + if(block == null || block.isAir(world, x, y, z)){ removeBlock(x, y, z); return; } world.setBlock(x, y, z, block); } + 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); + return; + } + world.setBlock(x, y, z, block.getMCBlock()); + } + /** * @param x World position x * @param y World position y @@ -131,7 +135,7 @@ public class ScriptWorld implements IWorld { world.setBlock(x, y, z, Blocks.air); } - public Vec3 rayCastBlockPos(Vec3 pos, Vec3 look, int maxDistance) { + public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance) { Vec3 currentPos = pos; int rep = 0; while (rep++ < maxDistance + 10) { currentPos = currentPos.addVector(look.xCoord, look.yCoord, look.zCoord); @@ -145,7 +149,7 @@ public class ScriptWorld implements IWorld { , 0.5); //System.out.println("current distance check: "+distance+" on rep "+rep); if (distance > maxDistance) return null; - return currentPos; + return block; } //System.out.println("ScriptWorld:WARNING: Repeated a ray cast to many times"); return null; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 855188037..e0b1b3359 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -1,6 +1,10 @@ package noppes.npcs.scripted.entity; -import net.minecraft.entity.player.EntityPlayer; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -14,30 +18,41 @@ import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Vec3; import net.minecraft.world.WorldSettings; -import noppes.npcs.*; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.Server; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.containers.ContainerCustomGui; -import noppes.npcs.controllers.*; +import noppes.npcs.controllers.CustomGuiController; +import noppes.npcs.controllers.Dialog; +import noppes.npcs.controllers.DialogController; +import noppes.npcs.controllers.PixelmonHelper; +import noppes.npcs.controllers.PlayerData; +import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.PlayerDialogData; +import noppes.npcs.controllers.PlayerQuestData; +import noppes.npcs.controllers.Quest; +import noppes.npcs.controllers.QuestController; +import noppes.npcs.controllers.QuestData; import noppes.npcs.entity.EntityDialogNpc; -import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; -import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; -import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.data.IQuest; -import noppes.npcs.scripted.interfaces.*; +import noppes.npcs.scripted.interfaces.IBlock; +import noppes.npcs.scripted.interfaces.IContainer; +import noppes.npcs.scripted.interfaces.ICustomGui; +import noppes.npcs.scripted.interfaces.ICustomOverlay; +import noppes.npcs.scripted.interfaces.IPlayer; +import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.util.ValueUtil; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - public class ScriptPlayer extends ScriptLivingBase implements IPlayer { public T player; private PlayerData data; @@ -463,11 +478,11 @@ public class ScriptPlayer extends ScriptLivingBase return new ScriptPixelmonPlayerData(player); } - public Vec3 getLookingAtBlock(int maxDistance) { + public IBlock getLookingAtBlock(int maxDistance) { Vec3 posVec = Vec3.createVectorHelper(player.posX, player.posY+player.getEyeHeight(), player.posZ); Vec3 lookVec = player.getLookVec(); - return NpcAPI.Instance().getIWorld(player.dimension).rayCastBlockPos(posVec, lookVec, maxDistance); + return getWorld().rayCastBlock(posVec, lookVec, maxDistance); } public ITimers getTimers() { diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java index 6d1799193..cd47334be 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IPlayer.java @@ -187,7 +187,7 @@ public interface IPlayer extends IEntityLivingBase */ public ScriptPixelmonPlayerData getPixelmonData(); - public Vec3 getLookingAtBlock(int maxDistance); + public IBlock getLookingAtBlock(int maxDistance); public ITimers getTimers(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 64d035d05..7949d9349 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -61,7 +61,7 @@ public interface IWorld { */ public void removeBlock(int x, int y, int z); - public Vec3 rayCastBlockPos(Vec3 pos, Vec3 look, int maxDistance); + public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance); public Vec3 getNearestAir(Vec3 pos, int maxHeight); From 6698e8619c89ff2441df115dd376479eb1de6771 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 02:10:25 -0500 Subject: [PATCH 08/16] world.getNearestAir returns IPos and takes IPos as parameter --- .../noppes/npcs/scripted/ScriptWorld.java | 37 +++++++++++-------- .../npcs/scripted/interfaces/IWorld.java | 10 ++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index f98026e3a..07b932133 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -28,6 +28,7 @@ import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.scripted.entity.ScriptEntity; import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.interfaces.IBlock; +import noppes.npcs.scripted.interfaces.IPos; import noppes.npcs.scripted.interfaces.IWorld; public class ScriptWorld implements IWorld { @@ -67,6 +68,14 @@ public class ScriptWorld implements IWorld { return null; return new ScriptBlock(world, block, new BlockPos(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()); + } /** * @param x World position x @@ -155,35 +164,33 @@ public class ScriptWorld implements IWorld { return null; } - public Vec3 getNearestAir(Vec3 pos, int maxHeight) { + public IPos getNearestAir(IPos pos, int maxHeight) { if (pos == null) return null; - Vec3 currentPos = pos; + IPos currentPos = pos; IBlock block = null; int rep = 0; while (rep++ < maxHeight) { //check +x - currentPos = currentPos.addVector(1, 0, 0); - block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + currentPos = currentPos.add(1, 0, 0); + block = getBlock(currentPos); if (block == null) break; //check -x - currentPos = currentPos.addVector(-2, 0, 0); - block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + currentPos = currentPos.add(-2, 0, 0); + block = getBlock(currentPos); if (block == null) break; //check +z - currentPos = currentPos.addVector(1, 0, 1); - block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + currentPos = currentPos.add(1, 0, 1); + block = getBlock(currentPos); if (block == null) break; //check -z - currentPos = currentPos.addVector(0, 0, -2); - block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + currentPos = currentPos.add(0, 0, -2); + block = getBlock(currentPos); if (block == null) break; //check up 1 - currentPos = currentPos.addVector(0, 1, 1); - block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); + currentPos = currentPos.add(0, 1, 1); + block = getBlock(currentPos); if (block == null) break; } - Vec3 posInt = Vec3.createVectorHelper((int)currentPos.xCoord, - (int)currentPos.yCoord, (int)currentPos.zCoord); - return posInt; + return currentPos; } public boolean canSeeSky(int x, int y, int z) { diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 7949d9349..5071ffba3 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -28,6 +28,12 @@ public interface 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); + + /** + * @param pos + * @return The block at the given position. Returns null if there isn't a block + */ + public IBlock getBlock(IPos pos); /** * @param x World position x @@ -53,6 +59,8 @@ public interface IWorld { * @param block The block to be set */ public void setBlock(int x, int y, int z, Block block); + + public void setBlock(int x, int y, int z, IBlock block); /** * @param x World position x @@ -63,7 +71,7 @@ public interface IWorld { public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance); - public Vec3 getNearestAir(Vec3 pos, int maxHeight); + public IPos getNearestAir(IPos pos, int maxHeight); public boolean canSeeSky(int x, int y, int z); From 77ee4037207b59f57eeb8e2188076b42ffe46f54 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 03:00:49 -0500 Subject: [PATCH 09/16] RoleFollowers will not despawn if they have an owner RoleFollowers canDespawn field will be changed back to the value set by the player in the gui/api if they stop following a player --- src/main/java/noppes/npcs/DataStats.java | 7 +++++-- src/main/java/noppes/npcs/client/gui/SubGuiNpcRespawn.java | 1 + src/main/java/noppes/npcs/roles/RoleFollower.java | 2 ++ src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/DataStats.java b/src/main/java/noppes/npcs/DataStats.java index acb1c691d..e9c1e6313 100644 --- a/src/main/java/noppes/npcs/DataStats.java +++ b/src/main/java/noppes/npcs/DataStats.java @@ -27,6 +27,7 @@ public class DataStats { public int spawnCycle = 0; public boolean hideKilledBody = false; public boolean canDespawn = false; + public boolean playerSetCanDespawn = false; public Resistances resistances = new Resistances(); @@ -110,8 +111,9 @@ public class DataStats { compound.setBoolean("CanDrown", canDrown); compound.setBoolean("BurnInSun", burnInSun); compound.setBoolean("NoFallDamage", noFallDamage); - compound.setBoolean("CanDespawn", canDespawn); compound.setBoolean("AttackInvisible", attackInvisible); + compound.setBoolean("CanDespawn", canDespawn); + compound.setBoolean("PlayerSetCanDespawn", playerSetCanDespawn); return compound; } @@ -169,8 +171,9 @@ public class DataStats { canDrown = compound.getBoolean("CanDrown"); burnInSun = compound.getBoolean("BurnInSun"); noFallDamage = compound.getBoolean("NoFallDamage"); - canDespawn = compound.getBoolean("CanDespawn"); attackInvisible = compound.getBoolean("AttackInvisible"); + canDespawn = compound.getBoolean("CanDespawn"); + playerSetCanDespawn = compound.getBoolean("PlayerSetCanDespawn"); npc.setImmuneToFire(immuneToFire); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcRespawn.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcRespawn.java index 16d5f191c..0779ac282 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcRespawn.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcRespawn.java @@ -55,6 +55,7 @@ public class SubGuiNpcRespawn extends SubGuiInterface implements ITextfieldListe } else if(button.id == 1){ stats.canDespawn = button.getValue() == 1; + stats.playerSetCanDespawn = stats.canDespawn; } else if(button.id == 4){ stats.hideKilledBody = button.getValue() == 1; diff --git a/src/main/java/noppes/npcs/roles/RoleFollower.java b/src/main/java/noppes/npcs/roles/RoleFollower.java index 67a578f3c..c0f1960d2 100644 --- a/src/main/java/noppes/npcs/roles/RoleFollower.java +++ b/src/main/java/noppes/npcs/roles/RoleFollower.java @@ -104,6 +104,7 @@ public class RoleFollower extends RoleInterface{ daysHired = 0; hiredTime = 0; isFollowing = true; + npc.stats.canDespawn = npc.stats.playerSetCanDespawn; } public int getDaysLeft(){ @@ -150,6 +151,7 @@ public class RoleFollower extends RoleInterface{ if(ownerUUID == null || id == null || !ownerUUID.equals(id)) killed(); ownerUUID = id.toString(); + npc.stats.canDespawn = false; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index dca330886..550a1eaa2 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -867,6 +867,7 @@ public class ScriptNpc extends ScriptLiving imp public void setNaturallyDespawns(boolean canDespawn) { npc.stats.canDespawn = canDespawn; + npc.stats.playerSetCanDespawn = canDespawn; } public void giveItem(ScriptPlayer player, ScriptItemStack item){ From 3d02ce3ce0a0835c0b84510edf7563ddf020ca63 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 03:04:13 -0500 Subject: [PATCH 10/16] world.rayCastBlock uses double[] for parameters --- src/main/java/noppes/npcs/scripted/ScriptWorld.java | 13 +++++++------ .../noppes/npcs/scripted/entity/ScriptPlayer.java | 7 ++++--- .../noppes/npcs/scripted/interfaces/IWorld.java | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 07b932133..8cbc7457a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -144,17 +144,18 @@ public class ScriptWorld implements IWorld { world.setBlock(x, y, z, Blocks.air); } - public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance) { - Vec3 currentPos = pos; int rep = 0; + public IBlock rayCastBlock(double[] pos, double[] look, int maxDistance) { + if (pos.length != 3 || look.length != 3) return null; + Vec3 currentPos = Vec3.createVectorHelper(pos[0], pos[1], pos[2]); int rep = 0; while (rep++ < maxDistance + 10) { - currentPos = currentPos.addVector(look.xCoord, look.yCoord, look.zCoord); + currentPos = currentPos.addVector(look[0], look[1], look[2]); IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); //System.out.println("Checking block at ["+(int)currentPos.xCoord+","+(int)currentPos.yCoord+","+(int)currentPos.zCoord+"]"); if (block == null) continue; double distance = Math.pow( - Math.pow(currentPos.xCoord-pos.xCoord,2) - +Math.pow(currentPos.yCoord-pos.yCoord,2) - +Math.pow(currentPos.zCoord-pos.zCoord,2) + Math.pow(currentPos.xCoord-pos[0],2) + +Math.pow(currentPos.yCoord-pos[1],2) + +Math.pow(currentPos.zCoord-pos[2],2) , 0.5); //System.out.println("current distance check: "+distance+" on rep "+rep); if (distance > maxDistance) return null; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index e0b1b3359..a64bf92ad 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -479,10 +479,11 @@ public class ScriptPlayer extends ScriptLivingBase } public IBlock getLookingAtBlock(int maxDistance) { - Vec3 posVec = Vec3.createVectorHelper(player.posX, - player.posY+player.getEyeHeight(), player.posZ); Vec3 lookVec = player.getLookVec(); - return getWorld().rayCastBlock(posVec, lookVec, maxDistance); + return getWorld().rayCastBlock( + new double[] {player.posX, player.posY+player.getEyeHeight(), player.posZ}, + new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord}, + maxDistance); } public ITimers getTimers() { diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 5071ffba3..0fb1f4cb2 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -69,7 +69,7 @@ public interface IWorld { */ public void removeBlock(int x, int y, int z); - public IBlock rayCastBlock(Vec3 pos, Vec3 look, int maxDistance); + public IBlock rayCastBlock(double[] pos, double[] look, int maxDistance); public IPos getNearestAir(IPos pos, int maxHeight); From e7250158acdd367e064057e2eb803cf3655e46bb Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 03:52:44 -0500 Subject: [PATCH 11/16] Update ScriptFaction.java --- .../java/noppes/npcs/scripted/ScriptFaction.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptFaction.java b/src/main/java/noppes/npcs/scripted/ScriptFaction.java index 2fc999337..3c637f994 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptFaction.java +++ b/src/main/java/noppes/npcs/scripted/ScriptFaction.java @@ -99,19 +99,14 @@ public class ScriptFaction { return faction.isAggressiveToNpc(npc.npc); } - public int[] getFactionEnemies() { - if (faction.attackFactions == null) return null; - int[] r = new int[faction.attackFactions.size()]; - Object[] objects = faction.attackFactions.toArray(); - for (int i = 0; i < r.length; ++i) { - r[i] = (Integer)objects[i]; - } - return r; + public Integer[] getFactionEnemies() { + if (faction.attackFactions == null) return new Integer[0]; + return faction.attackFactions.toArray(new Integer[faction.attackFactions.size()]); } public boolean isEnemyFaction(int id) { if (faction.attackFactions == null) return false; - int[] enemies = getFactionEnemies(); + Integer[] enemies = getFactionEnemies(); for (int i = 0; i < enemies.length; ++i) { if (enemies[i] == id) return true; } From 3cf780d9a242447a5fc158200ccbee839726f1f7 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 15:57:24 -0500 Subject: [PATCH 12/16] add get reset disable purchase num by slot number and IPlayer needed to add get/setStringIntegerArrayMap to NBTTags so save the player purchases and disabled slots with a String int[] hashmap --- src/main/java/noppes/npcs/NBTTags.java | 43 +++++++++++ .../npcs/containers/ContainerNPCTrader.java | 4 +- .../java/noppes/npcs/roles/RoleTrader.java | 35 ++++++++- .../npcs/scripted/roles/ScriptRoleTrader.java | 72 ++++++++++++++++--- 4 files changed, 141 insertions(+), 13 deletions(-) diff --git a/src/main/java/noppes/npcs/NBTTags.java b/src/main/java/noppes/npcs/NBTTags.java index 85b7eb08b..cb39bab95 100644 --- a/src/main/java/noppes/npcs/NBTTags.java +++ b/src/main/java/noppes/npcs/NBTTags.java @@ -131,6 +131,34 @@ public class NBTTags { } return list; } + + public static HashMap getStringIntegerArrayMap(NBTTagList tagList) { + HashMap list = new HashMap(); + for(int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i); + list.put(nbttagcompound.getString("Slot"), nbttagcompound.getIntArray("Value")); + } + return list; + } + + /** + * @param tagList + * @param arraySize if an int array is not this length a new int array with this length is made + * @return + */ + public static HashMap getStringIntegerArrayMap(NBTTagList tagList, int arrayLength) { + HashMap list = new HashMap(); + for(int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i); + int[] a = nbttagcompound.getIntArray("Value"); + if (a.length != arrayLength) a = new int[arrayLength]; + list.put(nbttagcompound.getString("Slot"), a); + } + return list; + } + public static HashMap> getVectorMap(NBTTagList tagList) { HashMap> map = new HashMap>(); for(int i = 0; i < tagList.tagCount(); i++) @@ -336,6 +364,21 @@ public class NBTTags { } return nbttaglist; } + + public static NBTTagList nbtStringIntegerArrayMap(HashMap map) { + NBTTagList nbttaglist = new NBTTagList(); + if(map == null) + return nbttaglist; + for(String slot : map.keySet()) + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + nbttagcompound.setString("Slot", slot); + nbttagcompound.setIntArray("Value", map.get(slot)); + + nbttaglist.appendTag(nbttagcompound); + } + return nbttaglist; + } public static NBTBase nbtIntegerStringMap(HashMap map) { NBTTagList nbttaglist = new NBTTagList(); diff --git a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java index 1165fea6f..f0390478e 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java +++ b/src/main/java/noppes/npcs/containers/ContainerNPCTrader.java @@ -68,12 +68,12 @@ public class ContainerNPCTrader extends ContainerNpcInterface{ NoppesUtilPlayer.consumeItem(entityplayer, role.inventoryCurrency.getStackInSlot(i + 18), role.ignoreDamage, role.ignoreNBT); ItemStack soldItem = item.copy(); givePlayer(soldItem, entityplayer); - ++role.purchases[i]; + role.addPurchase(i, entityplayer); return soldItem; } public boolean isSlotEnabled(int slot, EntityPlayer player) { - return role.disableSlot[slot] == 0; + return role.isSlotEnabled(slot, player); } public boolean canBuy(int slot, EntityPlayer player) { ItemStack currency = role.inventoryCurrency.getStackInSlot(slot); diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index b6f21eda6..3c918dc57 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -1,17 +1,19 @@ package noppes.npcs.roles; +import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; +import foxz.utils.Market; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.NBTTags; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.NpcMiscInventory; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.entity.EntityNPCInterface; -import foxz.utils.Market; public class RoleTrader extends RoleInterface{ @@ -26,6 +28,8 @@ public class RoleTrader extends RoleInterface{ public int[] purchases; public int[] disableSlot; + public HashMap playerPurchases; + public HashMap playerDisableSlot; public RoleTrader(EntityNPCInterface npc) { super(npc); @@ -33,6 +37,8 @@ public class RoleTrader extends RoleInterface{ inventorySold = new NpcMiscInventory(18); purchases = new int[18]; disableSlot = new int[18]; + playerPurchases = new HashMap(); + playerDisableSlot = new HashMap(); } @Override @@ -53,6 +59,8 @@ public class RoleTrader extends RoleInterface{ nbttagcompound.setBoolean("TraderIgnoreNBT", ignoreNBT); nbttagcompound.setIntArray("Purchases", purchases); nbttagcompound.setIntArray("DisableSlot", disableSlot); + nbttagcompound.setTag("PlayerPurchases", NBTTags.nbtStringIntegerArrayMap(playerPurchases)); + nbttagcompound.setTag("PlayerDisableSlot", NBTTags.nbtStringIntegerArrayMap(playerDisableSlot)); return nbttagcompound; } @@ -75,15 +83,17 @@ public class RoleTrader extends RoleInterface{ ignoreDamage = nbttagcompound.getBoolean("TraderIgnoreDamage"); ignoreNBT = nbttagcompound.getBoolean("TraderIgnoreNBT"); purchases = nbttagcompound.getIntArray("Purchases"); - if (purchases == null || purchases.length < 18) { + if (purchases == null || purchases.length != 18) { purchases = new int[18]; for (int i = 0; i < purchases.length; ++i) purchases[i] = 0; } disableSlot = nbttagcompound.getIntArray("DisableSlot"); - if (disableSlot == null || disableSlot.length < 18) { + if (disableSlot == null || disableSlot.length != 18) { disableSlot = new int[18]; for (int i = 0; i < disableSlot.length; ++i) disableSlot[i] = 0; } + playerPurchases = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerPurchases", 10), 18); + playerDisableSlot = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerDisableSlot", 10), 18); } @Override @@ -107,5 +117,24 @@ public class RoleTrader extends RoleInterface{ } return false; } + + public void addPurchase(int slot, EntityPlayer player) { + if(slot >= 18 || slot < 0) return; + ++purchases[slot]; + ++getArrayByName(player.getDisplayName(), playerPurchases)[slot]; + } + + public boolean isSlotEnabled(int slot, EntityPlayer player) { + if(slot >= 18 || slot < 0) return false; + if (disableSlot[slot] > 0) return false; + if (getArrayByName(player.getDisplayName(), playerDisableSlot)[slot] > 0) return false; + return true; + } + + public int[] getArrayByName(String name, HashMap map) { + int[] a = map.get(name); + if (a == null) a = map.put(name, new int[18]); + return a; + } } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 0e496569c..5ea82236f 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -1,10 +1,12 @@ package noppes.npcs.scripted.roles; import foxz.utils.Market; +import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.IItemStack; import noppes.npcs.scripted.interfaces.IPlayer; public class ScriptRoleTrader extends ScriptRoleInterface{ @@ -20,7 +22,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ * @param currency2 Currency item number two * @param sold Item to be sold by this npc */ - public void setSellOption(int slot, ScriptItemStack currency, ScriptItemStack currency2, ScriptItemStack sold){ + public void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold){ if(sold == null || slot >= 18 || slot < 0) return; if(currency == null) @@ -43,7 +45,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ * @param currency Currency item * @param sold Item to be sold by this npc */ - public void setSellOption(int slot, ScriptItemStack currency, ScriptItemStack sold){ + public void setSellOption(int slot, IItemStack currency, IItemStack sold){ setSellOption(slot, currency, null, sold); } @@ -51,7 +53,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ * @param slot * @return The item being sold in this slot. */ - public ScriptItemStack getSellOption(int slot) { + public IItemStack getSellOption(int slot) { if (slot >= 18 || slot < 0) return null; if (role.inventorySold.items.get(slot) == null) return null; return new ScriptItemStack(role.inventorySold.items.get(slot)); @@ -61,7 +63,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ * @param slot * @return a ScriptItemStack array of size 2 which contains the currency of this trade */ - public ScriptItemStack[] getCurrency(int slot) { + public IItemStack[] getCurrency(int slot) { if (slot >= 18 || slot < 0) return null; ScriptItemStack[] currency = new ScriptItemStack[2]; if (role.inventoryCurrency.items.get(slot) != null) { @@ -77,8 +79,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ * @param slot Slot number 0-17 */ public void removeSellOption(int slot){ - if(slot >= 18 || slot < 0) - return; + if(slot >= 18 || slot < 0) return; role.inventoryCurrency.items.remove(slot); role.inventoryCurrency.items.remove(slot + 18); role.inventorySold.items.remove(slot); @@ -107,9 +108,14 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ return role.purchases[slot]; } + /** + * @param slot + * @param player + * @return the number of times this player has purchased from this trader + */ public int getPurchaseNum(int slot, IPlayer player) { - // TODO get purchase num by player - return -1; + if(slot >= 18 || slot < 0) return -1; + return role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot]; } /** @@ -124,9 +130,39 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ * @param slot */ public void resetPurchaseNum(int slot) { + if(slot >= 18 || slot < 0) return; role.purchases[slot] = 0; } + /** + * sets the purchase num for that slot and player to 0 + * @param slot + * @param player + */ + public void resetPurchaseNum(int slot, IPlayer player) { + if(slot >= 18 || slot < 0) return; + role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot] = 0; + } + + /** + * @param slot + * @return if this slot is enabled + */ + public boolean isSlotEnabled(int slot) { + if(slot >= 18 || slot < 0) return false; + return role.disableSlot[slot] > 0; + } + + /** + * @param slot + * @param player + * @return if this slot is enabled for this player + */ + public boolean isSlotEnabled(int slot, IPlayer player) { + if(slot >= 18 || slot < 0) return false; + return role.isSlotEnabled(slot, (EntityPlayer)player.getMCEntity()); + } + /** * prevent an item from being sold on that slot * @param slot @@ -136,6 +172,16 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ role.disableSlot[slot] = 1; } + /** + * disables the slot for this player + * @param slot + * @param player + */ + public void disableSlot(int slot, IPlayer player) { + if(slot >= 18 || slot < 0) return; + role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 1; + } + /** * allow an item to be sold on that slot * @param slot @@ -144,6 +190,16 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 0; } + + /** + * enables the slot for this player + * @param slot + * @param player + */ + public void enableSlot(int slot, IPlayer player) { + if(slot >= 18 || slot < 0) return; + role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 0; + } @Override public int getType(){ From a49dfff86ade6a77efbfe9566c4ef05846d295b3 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 20:44:44 -0500 Subject: [PATCH 13/16] added world.rayCastBlock(IPos, IPos, int) --- .../noppes/npcs/scripted/ScriptWorld.java | 32 +++++++++++++++---- .../npcs/scripted/interfaces/IWorld.java | 4 ++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 8cbc7457a..aa6f03472 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -144,18 +144,25 @@ public class ScriptWorld implements IWorld { world.setBlock(x, y, z, Blocks.air); } - public IBlock rayCastBlock(double[] pos, double[] look, int maxDistance) { - if (pos.length != 3 || look.length != 3) return null; - Vec3 currentPos = Vec3.createVectorHelper(pos[0], pos[1], pos[2]); int rep = 0; + /** + * starting at the start position, draw a line in the lookVector direction until a block is detected + * @param startPos + * @param lookVector should be a normalized direction vector + * @param maxDistance + * @return the first detected block but null if maxDistance is reached + */ + public IBlock rayCastBlock(double[] startPos, double[] lookVector, int maxDistance) { + if (startPos.length != 3 || lookVector.length != 3) return null; + Vec3 currentPos = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]); int rep = 0; while (rep++ < maxDistance + 10) { - currentPos = currentPos.addVector(look[0], look[1], look[2]); + currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]); IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord); //System.out.println("Checking block at ["+(int)currentPos.xCoord+","+(int)currentPos.yCoord+","+(int)currentPos.zCoord+"]"); if (block == null) continue; double distance = Math.pow( - Math.pow(currentPos.xCoord-pos[0],2) - +Math.pow(currentPos.yCoord-pos[1],2) - +Math.pow(currentPos.zCoord-pos[2],2) + Math.pow(currentPos.xCoord-startPos[0],2) + +Math.pow(currentPos.yCoord-startPos[1],2) + +Math.pow(currentPos.zCoord-startPos[2],2) , 0.5); //System.out.println("current distance check: "+distance+" on rep "+rep); if (distance > maxDistance) return null; @@ -165,6 +172,17 @@ public class ScriptWorld implements IWorld { return null; } + /** + * starting at the start position, draw a line in the lookVector direction until a block is detected + * @param startPos + * @param lookVector will normalize x, y, z to get a direction vector + * @param maxDistance + * @return the first detected block but null if maxDistance is reached + */ + public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance) { + return rayCastBlock(new double[] {startPos.getX(), startPos.getY(), startPos.getZ()}, lookVector.normalize(), maxDistance); + } + public IPos getNearestAir(IPos pos, int maxHeight) { if (pos == null) return null; IPos currentPos = pos; diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 0fb1f4cb2..58d05ab3a 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -69,7 +69,9 @@ public interface IWorld { */ public void removeBlock(int x, int y, int z); - public IBlock rayCastBlock(double[] pos, double[] look, int maxDistance); + public IBlock rayCastBlock(double[] startPos, double[] lookVector, int maxDistance); + + public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance); public IPos getNearestAir(IPos pos, int maxHeight); From 81033e5a9cb3015fde5ab54c63a1c5c227c67203 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 20:47:46 -0500 Subject: [PATCH 14/16] renamed getFactionEnemies to getEnemyFactionIds IFaction[] getFactionEnemies(); I think this should be implemented in PR #50 because IFaction is setup better there --- src/main/java/noppes/npcs/scripted/ScriptFaction.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptFaction.java b/src/main/java/noppes/npcs/scripted/ScriptFaction.java index 3c637f994..d2aa114f4 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptFaction.java +++ b/src/main/java/noppes/npcs/scripted/ScriptFaction.java @@ -99,14 +99,14 @@ public class ScriptFaction { return faction.isAggressiveToNpc(npc.npc); } - public Integer[] getFactionEnemies() { + public Integer[] getEnemyFactionIds() { if (faction.attackFactions == null) return new Integer[0]; return faction.attackFactions.toArray(new Integer[faction.attackFactions.size()]); } public boolean isEnemyFaction(int id) { if (faction.attackFactions == null) return false; - Integer[] enemies = getFactionEnemies(); + Integer[] enemies = getEnemyFactionIds(); for (int i = 0; i < enemies.length; ++i) { if (enemies[i] == id) return true; } @@ -120,4 +120,5 @@ public class ScriptFaction { public void removeFactionEnemy(int id) { faction.attackFactions.remove(id); } + } From 0d2011b2ba0dffb42cfc36f19207b6ebf68589ad Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Thu, 26 May 2022 20:55:11 -0500 Subject: [PATCH 15/16] added some doc comments --- .../noppes/npcs/scripted/ScriptWorld.java | 4 ++ .../npcs/scripted/interfaces/IWorld.java | 39 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index aa6f03472..447fb8ece 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -216,6 +216,10 @@ public class ScriptWorld implements IWorld { 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 diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 58d05ab3a..57e52c069 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -60,6 +60,12 @@ public interface IWorld { */ public void setBlock(int x, int y, int z, Block block); + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @param block The block to be set + */ public void setBlock(int x, int y, int z, IBlock block); /** @@ -69,13 +75,44 @@ public interface IWorld { */ public void removeBlock(int x, int y, int z); + /** + * starting at the start position, draw a line in the lookVector direction until a block is detected + * @param startPos + * @param lookVector should be a normalized direction vector + * @param maxDistance + * @return the first detected block but null if maxDistance is reached + */ public IBlock rayCastBlock(double[] startPos, double[] lookVector, int maxDistance); + /** + * starting at the start position, draw a line in the lookVector direction until a block is detected + * @param startPos + * @param lookVector will normalize x, y, z to get a direction vector + * @param maxDistance + * @return the first detected block but null if maxDistance is reached + */ public IBlock rayCastBlock(IPos startPos, IPos lookVector, int maxDistance); - public IPos getNearestAir(IPos pos, int maxHeight); + /** + * @param startPos + * @param maxHeight + * @return the position of the closest block of air to startPos + */ + public IPos getNearestAir(IPos startPos, int maxHeight); + /** + * @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 From f83487f67bec7b2a1d656fe56b37ddedf18ddc36 Mon Sep 17 00:00:00 2001 From: 1whohears <1whohears28@gmail.com> Date: Fri, 27 May 2022 11:28:01 -0500 Subject: [PATCH 16/16] removed setblock with the Minecraft block class as a parameter --- .../java/noppes/npcs/scripted/ScriptWorld.java | 8 -------- .../noppes/npcs/scripted/interfaces/IWorld.java | 16 +++------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 447fb8ece..846b20fbe 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -102,14 +102,6 @@ public class ScriptWorld implements IWorld { return null; } - public void setBlock(int x, int y, int z, Block block){ - if(block == null || block.isAir(world, x, y, z)){ - removeBlock(x, y, z); - return; - } - world.setBlock(x, y, z, block); - } - 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); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 57e52c069..0d3b053c4 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -1,12 +1,10 @@ package noppes.npcs.scripted.interfaces; -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import net.minecraft.world.WorldServer; -import noppes.npcs.scripted.*; +import noppes.npcs.scripted.ScriptEntityParticle; +import noppes.npcs.scripted.ScriptItemStack; +import noppes.npcs.scripted.ScriptScoreboard; import noppes.npcs.scripted.entity.ScriptEntity; import noppes.npcs.scripted.entity.ScriptPlayer; @@ -51,14 +49,6 @@ public interface IWorld { * @param item The block to be set */ public void setBlock(int x, int y, int z, ScriptItemStack item); - - /** - * @param x World position x - * @param y World position y - * @param z World position z - * @param block The block to be set - */ - public void setBlock(int x, int y, int z, Block block); /** * @param x World position x