mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 00:35:06 +00:00
Added setVisibleTo(player,visible) and isVisibleTo(player) to ScriptNpc
This commit is contained in:
1 parent
8a7f40189e
commit
d24422c3a1
5 files changed
+78
-5
No files matched your search
@@ -1,8 +1,15 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.StringUtils;
|
||||
@@ -43,6 +50,8 @@ public class DataDisplay {
|
||||
|
||||
public byte showBossBar = 0;
|
||||
|
||||
public ArrayList<UUID> invisibleToList = new ArrayList<>();
|
||||
|
||||
public DataDisplay(EntityNPCInterface npc){
|
||||
this.npc = npc;
|
||||
|
||||
@@ -112,6 +121,13 @@ public class DataDisplay {
|
||||
nbttagcompound.setBoolean("NoLivingAnimation", disableLivingAnimation);
|
||||
nbttagcompound.setByte("BossBar", showBossBar);
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(UUID uuid : invisibleToList){
|
||||
list.appendTag(new NBTTagString(uuid.toString()));
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("InvisibleToList", list);
|
||||
|
||||
return nbttagcompound;
|
||||
}
|
||||
public void readToNBT(NBTTagCompound nbttagcompound) {
|
||||
@@ -152,6 +168,13 @@ public class DataDisplay {
|
||||
disableLivingAnimation = nbttagcompound.getBoolean("NoLivingAnimation");
|
||||
showBossBar = nbttagcompound.getByte("BossBar");
|
||||
|
||||
invisibleToList.clear();
|
||||
NBTTagList tagList = (NBTTagList)nbttagcompound.getTag("InvisibleToList");
|
||||
for(int i = 0; i < tagList.tagCount(); i++){
|
||||
String nbtTagString = tagList.getStringTagAt(i);
|
||||
invisibleToList.add(UUID.fromString(nbtTagString));
|
||||
}
|
||||
|
||||
if(prevSkinType != skinType || !texture.equals(prevTexture))
|
||||
npc.textureLocation = null;
|
||||
npc.textureGlowLocation = null;
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.ModelPartConfig;
|
||||
import noppes.npcs.ModelPartData;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
@@ -294,6 +295,8 @@ public class ModelMPM extends ModelNPCMale{
|
||||
@Override
|
||||
public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7){
|
||||
EntityCustomNpc npc = (EntityCustomNpc) par1Entity;
|
||||
if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() != CustomItems.wand)
|
||||
return;
|
||||
|
||||
if(entityModel != null){
|
||||
if(!isArmor){
|
||||
@@ -311,7 +314,10 @@ public class ModelMPM extends ModelNPCMale{
|
||||
}
|
||||
}
|
||||
else{
|
||||
alpha = npc.isInvisible() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer)?0.15f:1;
|
||||
alpha = npc.isInvisible() && !npc.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) ? 0.15f : 1;
|
||||
if(npc.scriptInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) && Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() == CustomItems.wand)
|
||||
alpha = 0.15f;
|
||||
|
||||
setPlayerData(npc);
|
||||
currentlyPlayerTexture = true;
|
||||
setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
|
||||
|
||||
@@ -3,10 +3,7 @@ package noppes.npcs.entity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -95,6 +92,7 @@ import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.roles.RoleFollower;
|
||||
import noppes.npcs.roles.RoleInterface;
|
||||
import noppes.npcs.scripted.entity.ScriptNpc;
|
||||
import noppes.npcs.scripted.entity.ScriptPlayer;
|
||||
import noppes.npcs.scripted.event.ScriptEventAttack;
|
||||
import noppes.npcs.scripted.event.ScriptEventDamaged;
|
||||
import noppes.npcs.scripted.event.ScriptEventKilled;
|
||||
@@ -1599,9 +1597,16 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
@Override
|
||||
public boolean isInvisibleToPlayer(EntityPlayer player){
|
||||
if(display.invisibleToList != null && display.invisibleToList.contains(player.getPersistentID()))
|
||||
return true;
|
||||
|
||||
return display.visible == 1 && (player.getHeldItem() == null || player.getHeldItem().getItem() != CustomItems.wand);
|
||||
}
|
||||
|
||||
public boolean scriptInvisibleToPlayer(EntityPlayer player){
|
||||
return display.invisibleToList != null && display.invisibleToList.contains(player.getPersistentID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible(){
|
||||
return display.visible != 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.constants.EnumAnimation;
|
||||
@@ -31,6 +32,10 @@ import noppes.npcs.scripted.roles.ScriptRoleTrader;
|
||||
import noppes.npcs.scripted.roles.ScriptRoleTransporter;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> implements ICustomNpc {
|
||||
public EntityCustomNpc npc;
|
||||
|
||||
@@ -431,6 +436,24 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
public int getVisibleType(){
|
||||
return npc.display.visible;
|
||||
}
|
||||
|
||||
public void setVisibleTo(ScriptPlayer player, boolean visible) {
|
||||
UUID uuid = player.player.getPersistentID();
|
||||
ArrayList<UUID> uuidList = npc.display.invisibleToList;
|
||||
if(uuidList != null) {
|
||||
if (!uuidList.contains(uuid)) {
|
||||
if (!visible)
|
||||
npc.display.invisibleToList.add(uuid);
|
||||
} else if (visible) {
|
||||
npc.display.invisibleToList.remove(uuid);
|
||||
}
|
||||
}
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
|
||||
public boolean isVisibleTo(ScriptPlayer player) {
|
||||
return !npc.scriptInvisibleToPlayer(player.player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type The visibility type of the name, 0:visible, 1:invisible, 2:when-attacking
|
||||
|
||||
@@ -225,6 +225,22 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
|
||||
*/
|
||||
public int getVisibleType();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player The player this NPC becomes visible/invisible to
|
||||
* @param visible True if you want the NPC to be invisible to the player, false otherwise
|
||||
*/
|
||||
public void setVisibleTo(ScriptPlayer player, boolean visible);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player The player this NPC is visible/invisible to
|
||||
* @return False if the NPC has been toggled to be invisible to this player, true otherwise.
|
||||
* If setVisibleTo(player,visible) was not called to make this NPC invisible to the player at any point
|
||||
* in the NPC's life, this function will return true regardless of the value of isVisible().
|
||||
*/
|
||||
public boolean isVisibleTo(ScriptPlayer player);
|
||||
|
||||
/**
|
||||
* @param type The visibility type of the name, 0:visible, 1:invisible, 2:when-attacking
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user