Files
CustomNPC-Plus/src/main/java/noppes/npcs/roles/RoleTrader.java
T
1whohears a4361b8420 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
2022-05-24 03:06:16 -05:00

112 lines
3.5 KiB
Java

package noppes.npcs.roles;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
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{
public String marketName = "";
public NpcMiscInventory inventoryCurrency;
public NpcMiscInventory inventorySold;
public boolean ignoreDamage = false;
public boolean ignoreNBT = false;
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
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setString("TraderMarket", marketName);
writeNBT(nbttagcompound);
if (toSave && !npc.isRemote()) {
Market.save(this, marketName);
}
toSave = false;
return nbttagcompound;
}
public NBTTagCompound writeNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setTag("TraderCurrency", inventoryCurrency.getToNBT());
nbttagcompound.setTag("TraderSold", inventorySold.getToNBT());
nbttagcompound.setBoolean("TraderIgnoreDamage", ignoreDamage);
nbttagcompound.setBoolean("TraderIgnoreNBT", ignoreNBT);
nbttagcompound.setIntArray("Purchases", purchases);
nbttagcompound.setIntArray("DisableSlot", disableSlot);
return nbttagcompound;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
marketName = nbttagcompound.getString("TraderMarket");
readNBT(nbttagcompound);
try {
Market.load(this, marketName);
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
}
public void readNBT(NBTTagCompound nbttagcompound) {
inventoryCurrency.setFromNBT(nbttagcompound.getCompoundTag("TraderCurrency"));
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
public void interact(EntityPlayer player) {
npc.say(player, npc.advanced.getInteractLine());
try {
Market.load(this, marketName);
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
}
NoppesUtilServer.sendOpenGui(player, EnumGuiType.PlayerTrader, npc);
}
public boolean hasCurrency(ItemStack itemstack) {
if(itemstack == null)
return false;
for(ItemStack item : inventoryCurrency.items.values()){
if(item != null && NoppesUtilPlayer.compareItems(item, itemstack, ignoreDamage, ignoreNBT)){
return true;
}
}
return false;
}
}