Merge branch 'dev' into dev

This commit is contained in:
Kam authored and GitHub committed 2025-03-06 02:19:17 -05:00
commit 43c940f7ed
799 files changed
+49724 -13791

No files matched your search

File diff suppressed because it is too large. Load diff
+20 -12
View File
@@ -2,6 +2,7 @@ package noppes.npcs;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -14,23 +15,25 @@ import noppes.npcs.api.IWorld;
import noppes.npcs.blocks.tiles.TileNpcContainer;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.containers.*;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
public abstract class CommonProxy implements IGuiHandler {
public class CommonProxy implements IGuiHandler {
public boolean newVersionAvailable = false;
public int revision = 1;
public void load() {
CustomNpcs.Channel.register(new PacketHandlerServer());
CustomNpcs.ChannelPlayer.register(new PacketHandlerPlayer());
}
public PlayerData getPlayerData(EntityPlayer player) {
return null;
}
public AnimationData getClientAnimationData(Entity entity) {
return null;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if(ID > EnumGuiType.values().length)
@@ -67,9 +70,12 @@ public abstract class CommonProxy implements IGuiHandler {
if(gui == EnumGuiType.PlayerTrader)
return new ContainerNPCTrader(npc, player);
if(gui == EnumGuiType.PlayerAnvil)
if(gui == EnumGuiType.PlayerCarpentryBench)
return new ContainerCarpentryBench(player.inventory, player.worldObj, x, y, z);
if(gui == EnumGuiType.PlayerAnvil)
return new ContainerAnvilRepair(player.inventory, player.worldObj, x, y, z);
if(gui == EnumGuiType.SetupItemGiver)
return new ContainerNpcItemGiver(npc, player);
@@ -108,16 +114,16 @@ public abstract class CommonProxy implements IGuiHandler {
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
// TODO Auto-generated method stub
return null;
}
public void openGui(EntityNPCInterface npc, EnumGuiType gui) {
// TODO Auto-generated method stub
}
public void openGui(EntityNPCInterface npc, EnumGuiType gui, int x, int y, int z) {
// TODO Auto-generated method stub
}
@@ -126,12 +132,12 @@ public abstract class CommonProxy implements IGuiHandler {
}
public void openGui(EntityPlayer player, Object guiscreen) {
// TODO Auto-generated method stub
}
public void spawnParticle(EntityLivingBase player, String string, Object... ob) {
// TODO Auto-generated method stub
}
@@ -146,7 +152,7 @@ public abstract class CommonProxy implements IGuiHandler {
}
public void registerItem(Item item) {
// TODO Auto-generated method stub
}
@@ -159,7 +165,9 @@ public abstract class CommonProxy implements IGuiHandler {
}
public abstract void generateBigSmokeParticles(World world, int x, int y, int z, boolean signalFire);
public void generateBigSmokeParticles(World world, int x, int y, int z, boolean signalFire){
}
public String getAchievementDesc(Achievement achievement) {
return "";
+31 -16
View File
@@ -27,7 +27,10 @@ public class CustomItems {
public static Item moving;
public static Item mount;
public static Item teleporter;
public static Item tool;
public static Item scripted_item;
public static Item linked_item;
public static Item soulstoneEmpty;
public static Item soulstoneFull;
@@ -123,6 +126,11 @@ public class CustomItems {
public static Item spellDark;
public static Item spellHoly;
public static Item earthElement;
public static Item fireElement;
public static Item waterElement;
public static Item airElement;
public static Item staffWood;
public static Item staffStone;
public static Item staffIron;
@@ -164,6 +172,7 @@ public class CustomItems {
public static Block banner;
public static Block wallBanner;
public static Block tallLamp;
public static Block shortLamp;
public static Block blood;
public static Block book;
public static Block chair;
@@ -182,11 +191,11 @@ public class CustomItems {
public static Block beam;
public static Block crystal;
public static Block lamp;
public static Block lantern;
public static Block campfire;
public static Block candle;
public static Block lamp_unlit;
public static Block lantern_unlit;
public static Block campfire_unlit;
public static Block candle_unlit;
public static Block scripted;
@@ -210,6 +219,7 @@ public class CustomItems {
if(!ConfigMain.DisableExtraBlock){
GameRegistry.registerTileEntity(TileWallBanner.class, "TileNPCWallBanner");
GameRegistry.registerTileEntity(TileTallLamp.class, "TileNPCTallLamp");
GameRegistry.registerTileEntity(TileShortLamp.class, "TileNPCShortLamp");
GameRegistry.registerTileEntity(TileChair.class, "TileNPCChair");
GameRegistry.registerTileEntity(TileCrate.class, "TileNPCCrate");
GameRegistry.registerTileEntity(TileWeaponRack.class, "TileNPCWeaponRack");
@@ -237,9 +247,11 @@ public class CustomItems {
mount = new ItemMounter().setUnlocalizedName("npcMounter").setFull3D();
teleporter = new ItemTeleporter().setUnlocalizedName("npcTeleporter").setFull3D();
scripted_item = new ItemScripted().setUnlocalizedName("scripted_item").setFull3D();
linked_item = new ItemLinked().setUnlocalizedName("linked_item").setFull3D();
tool = new ItemNpcTool().setUnlocalizedName("npcTool").setFull3D();
redstoneBlock = new BlockNpcRedstone().setHardness(50.0F).setResistance(2000).setBlockName("npcRedstoneBlock").setBlockTextureName("customnpcs:npcRedstoneBlock").setCreativeTab(tab);
carpentyBench = new BlockCarpentryBench().setBlockName("npcCarpentyBench").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
carpentyBench = new BlockCarpentryBench().setBlockName("npcCarpentyBench").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypePiston).setCreativeTab(tabBlocks);
mailbox = new BlockMailbox().setBlockName("npcMailbox").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks);
waypoint = new BlockWaypoint().setBlockName("npcLocationBlock").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setBlockTextureName("customnpcs:npcWaypoint").setCreativeTab(tab);
border = new BlockBorder().setBlockName("npcBorder").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tab).setBlockTextureName("customnpcs:npcBorder");
@@ -274,17 +286,18 @@ public class CustomItems {
if(!ConfigMain.DisableExtraBlock){
blood = new BlockBlood().setBlockName("npcBloodBlock").setBlockTextureName("customnpcs:npcBloodBlock").setCreativeTab(tabBlocks);
banner = new BlockBanner().setBlockName("npcBanner").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks);
wallBanner = new BlockWallBanner().setBlockName("npcWallBanner").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks);
banner = new BlockBanner().setBlockName("npcBanner").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeCloth).setCreativeTab(tabBlocks);
wallBanner = new BlockWallBanner().setBlockName("npcWallBanner").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeCloth).setCreativeTab(tabBlocks);
tallLamp = new BlockTallLamp().setBlockName("npcTallLamp").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks);
chair = new BlockChair().setBlockName("npcChair").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
shortLamp = new BlockShortLamp().setBlockName("npcShortLamp").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks);
chair = new BlockChair().setBlockName("npcChair").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
crate = new BlockCrate().setBlockName("npcCrate").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
weaponsRack = new BlockWeaponRack().setBlockName("npcWeaponRack").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
couchWool = new BlockCouchWool().setBlockName("npcCouchWool").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
table = new BlockTable().setBlockName("npcTable").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
couchWood = new BlockCouchWood().setBlockName("npcCouchWood").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
lamp = new BlockLamp(true).setBlockName("npcLamp").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
candle = new BlockCandle(true).setBlockName("npcCandle").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
lantern = new BlockLantern(true).setBlockName("npcLamp").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setCreativeTab(tabBlocks).setBlockTextureName("customnpcs:lantern");;
candle = new BlockCandle(true).setBlockName("npcCandle").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone).setCreativeTab(tabBlocks).setBlockTextureName("customnpcs:candle");;
stool = new BlockStool().setBlockName("npcStool").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
Block placeholder = new BlockPlaceholder().setBlockName("npcPlaceholder").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabMisc);
bigsign = new BlockBigSign().setBlockName("npcBigSign").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood).setCreativeTab(tabBlocks);
@@ -299,13 +312,14 @@ public class CustomItems {
crystal = new BlockCrystal().setBlockName("npcCrystal").setBlockTextureName("customnpcs:npcCrystal").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeGlass).setCreativeTab(tabBlocks);
campfire_unlit = new BlockCampfire(false).setBlockName("npcCampfire").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone);
lamp_unlit = new BlockLamp(false).setBlockName("npcLamp").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood);
candle_unlit = new BlockCandle(false).setBlockName("npcCandle").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeWood);
lantern_unlit = new BlockLantern(false).setBlockName("npcLamp").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeMetal).setBlockTextureName("customnpcs:lantern");
candle_unlit = new BlockCandle(false).setBlockName("npcCandle").setHardness(5.0F).setResistance(10.0F).setStepSound(Block.soundTypeStone).setBlockTextureName("customnpcs:candle");
GameRegistry.registerBlock(blood, "npcBloodBlock");
GameRegistry.registerBlock(banner, ItemBlock.class, "npcBanner");
GameRegistry.registerBlock(wallBanner, ItemBlock.class, "npcWallBanner");
GameRegistry.registerBlock(tallLamp, ItemBlock.class, "npcTallLamp");
GameRegistry.registerBlock(shortLamp, ItemBlock.class, "npcShortLamp");
GameRegistry.registerBlock(chair, ItemBlock.class, "npcChair");
GameRegistry.registerBlock(crate, ItemBlock.class, "npcCrate");
GameRegistry.registerBlock(weaponsRack, ItemBlock.class, "npcWeaponRack");
@@ -324,15 +338,16 @@ public class CustomItems {
GameRegistry.registerBlock(pedestal, ItemBlock.class, "npcPedestal");
GameRegistry.registerBlock(crystal, ItemNpcColored.class, "npcCrystalBlock");
GameRegistry.registerBlock(campfire, "npcCampfire");
GameRegistry.registerBlock(lamp, "npcLamp");
GameRegistry.registerBlock(lantern, "npcLamp");
GameRegistry.registerBlock(candle, "npcCandle");
GameRegistry.registerBlock(campfire_unlit, "npcCampfireUnlit");
GameRegistry.registerBlock(candle_unlit, "npcLampUnlit");
GameRegistry.registerBlock(lamp_unlit, "npcCandleUnlit");
GameRegistry.registerBlock(lantern_unlit, "npcCandleUnlit");
Item.getItemFromBlock(banner).setHasSubtypes(true);
Item.getItemFromBlock(wallBanner).setHasSubtypes(true);
Item.getItemFromBlock(tallLamp).setHasSubtypes(true);
Item.getItemFromBlock(shortLamp).setHasSubtypes(true);
Item.getItemFromBlock(chair).setHasSubtypes(true);
Item.getItemFromBlock(crate).setHasSubtypes(true);
Item.getItemFromBlock(weaponsRack).setHasSubtypes(true);
@@ -743,10 +758,10 @@ public class CustomItems {
quest = new ItemNpcArmor(26957,ArmorMaterial.IRON,0,"mask").setMaxStackSize(64).setUnlocalizedName("npcBanditMask").setCreativeTab(CustomItems.tabArmor).setTextureName("customnpcs:npcBanditMask");
quest = new ItemNpcInterface(26958).setUnlocalizedName("npcBrokenArrow").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcBrokenArrow");
quest = new ItemNpcInterface(26959).setUnlocalizedName("npcEarthElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcEarthElement");
quest = new ItemNpcInterface(26960).setUnlocalizedName("npcWaterElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcWaterElement");
quest = new ItemNpcInterface(26961).setUnlocalizedName("npcFireElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcFireElement");
quest = new ItemNpcInterface(26962).setUnlocalizedName("npcAirElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcAirElement");
earthElement = new ItemNpcInterface(26959).setUnlocalizedName("npcEarthElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcEarthElement");
waterElement = new ItemNpcInterface(26960).setUnlocalizedName("npcWaterElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcWaterElement");
fireElement = new ItemNpcInterface(26961).setUnlocalizedName("npcFireElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcFireElement");
airElement = new ItemNpcInterface(26962).setUnlocalizedName("npcAirElement").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcAirElement");
quest = new ItemNpcInterface(26963).setUnlocalizedName("npcCarKey").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcCarKey");
quest = new ItemNpcInterface(26964).setUnlocalizedName("npcKey").setCreativeTab(CustomItems.tabMisc).setTextureName("customnpcs:npcKey");
+22 -14
View File
@@ -5,17 +5,17 @@ import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.network.FMLEventChannel;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import foxz.command.CommandNoppes;
import kamkeel.addon.AddonManager;
import kamkeel.command.CommandKamkeel;
import kamkeel.command.profile.CommandProfile;
import kamkeel.controllers.ProfileController;
import kamkeel.controllers.data.CNPCData;
import kamkeel.developer.Developer;
import kamkeel.npcs.addon.AddonManager;
import kamkeel.npcs.command.CommandKamkeel;
import kamkeel.npcs.command.profile.CommandProfile;
import kamkeel.npcs.controllers.ProfileController;
import kamkeel.npcs.controllers.data.profile.CNPCData;
import kamkeel.npcs.developer.Developer;
import kamkeel.npcs.network.PacketHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockIce;
import net.minecraft.block.BlockLeavesBase;
@@ -27,6 +27,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
import nikedemos.markovnames.generators.*;
import kamkeel.npcs.controllers.AttributeController;
import noppes.npcs.compat.PixelmonHelper;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.LoadConfiguration;
@@ -40,7 +41,7 @@ import noppes.npcs.scripted.NpcAPI;
import java.io.File;
import java.util.Set;
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.9.4-beta1")
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.10-beta5")
public class CustomNpcs {
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
@@ -54,9 +55,6 @@ public class CustomNpcs {
public static boolean FreezeNPCs = false;
public static FMLEventChannel Channel;
public static FMLEventChannel ChannelPlayer;
public static final MarkovGenerator[] MARKOV_GENERATOR = new MarkovGenerator[10];
public static boolean InitIgnore = false;
@@ -86,8 +84,7 @@ public class CustomNpcs {
@EventHandler
public void load(FMLPreInitializationEvent ev) {
Channel = NetworkRegistry.INSTANCE.newEventDrivenChannel("CustomNPCs");
ChannelPlayer = NetworkRegistry.INSTANCE.newEventDrivenChannel("CustomNPCsPlayer");
PacketHandler.Instance = new PacketHandler();
MinecraftServer server = MinecraftServer.getServer();
String dir = "";
@@ -178,6 +175,7 @@ public class CustomNpcs {
// Load Mod Support
PixelmonHelper.load();
new AddonManager();
new AttributeController();
}
@EventHandler
@@ -194,6 +192,7 @@ public class CustomNpcs {
MARKOV_GENERATOR[8] = new MarkovCustomNPCsClassic(3);
MARKOV_GENERATOR[9] = new MarkovSpanish(3);
PacketHandler.Instance.registerChannels();
}
@EventHandler
@@ -202,6 +201,8 @@ public class CustomNpcs {
ChunkController.Instance.clear();
FactionController.getInstance().load();
// VisibilityController.instance = new VisibilityController();
new MagicController();
MagicController.getInstance().load();
new PlayerDataController();
new TagController();
new TransportController();
@@ -210,6 +211,11 @@ public class CustomNpcs {
new LinkedNpcController();
new AnimationController();
LinkedItemController.getInstance().load();
// Custom Effects
CustomEffectController.getInstance().load();
// Profile Controller
new ProfileController();
ProfileController.registerProfileType(new CNPCData());
@@ -249,6 +255,7 @@ public class CustomNpcs {
ServerTagMapController.Instance = new ServerTagMapController();
}
@EventHandler
public void stopped(FMLServerStoppedEvent event){
ServerCloneController.Instance = null;
@@ -262,7 +269,8 @@ public class CustomNpcs {
public void serverstart(FMLServerStartingEvent event) {
event.registerServerCommand(new CommandNoppes());
event.registerServerCommand(new CommandKamkeel());
event.registerServerCommand(new CommandProfile());
if(ConfigMain.ProfilesEnabled)
event.registerServerCommand(new CommandProfile());
}
private void registerNpc(Class<? extends Entity> cl, String name) {
@@ -2,7 +2,7 @@ package noppes.npcs;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import kamkeel.developer.Developer;
import kamkeel.npcs.developer.Developer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import org.apache.logging.log4j.LogManager;
@@ -17,6 +17,10 @@ import java.util.List;
public class CustomNpcsPermissions{
// Open GUI
public static final Permission NPC_GUI = new Permission("customnpcs.npc.gui");
public static final Permission PAINTBRUSH_GUI = new Permission("customnpcs.npc.paintbrush");
// Builder
public static final Permission NPC_BUILD = new Permission("customnpcs.npc.build");
// Modify NPC
public static final Permission NPC_DELETE = new Permission("customnpcs.npc.delete");
@@ -49,6 +53,8 @@ public class CustomNpcsPermissions{
public static final Permission GLOBAL_NATURALSPAWN = new Permission("customnpcs.global.naturalspawn");
public static final Permission GLOBAL_TAG = new Permission("customnpcs.global.tag");
public static final Permission GLOBAL_ANIMATION = new Permission("customnpcs.global.animation");
public static final Permission GLOBAL_MAGIC = new Permission("customnpcs.global.magic");
public static final Permission GLOBAL_EFFECT = new Permission("customnpcs.global.effect");
public static final Permission SPAWNER_MOB = new Permission("customnpcs.spawner.mob");
public static final Permission SPAWNER_CREATE = new Permission("customnpcs.spawner.create");
@@ -82,6 +88,15 @@ public class CustomNpcsPermissions{
public static final Permission SCRIPT_ITEM = new Permission("customnpcs.script.item");
public static final Permission SCRIPT_BLOCK = new Permission("customnpcs.script.block");
// Profiles
public static final Permission PROFILE_ADMIN = new Permission("customnpcs.profile.admin");
public static final Permission PROFILE_CREATE = new Permission("customnpcs.profile.create");
public static final Permission PROFILE_DELETE = new Permission("customnpcs.profile.delete");
public static final Permission PROFILE_RENAME = new Permission("customnpcs.profile.rename");
public static final Permission PROFILE_CHANGE = new Permission("customnpcs.profile.change");
public static final Permission PROFILE_REGION_BYPASS = new Permission("customnpcs.profile.region-bypass");
public static final Permission PROFILE_MAX = new Permission("customnpcs.profile.max.*");
public static CustomNpcsPermissions Instance;
private Class<?> bukkit;
private Method getPlayer;
+21 -21
View File
@@ -11,7 +11,7 @@ import java.util.List;
public class DataAI {
private EntityNPCInterface npc;
public int onAttack = 0; //0:fight 1:panic 2:retreat 3:nothing
public int doorInteract = 2;
public int findShelter = 2;
@@ -31,13 +31,13 @@ public class DataAI {
public int useRangeMelee = 0;
public int tacticalRadius = 8;
public int tacticalChance = 5;
public int movementType = 0;
public int movementType = 0; // 0 - Ground , 1 - Flying
public double flySpeed = 1.0D;
public double flyGravity = 0.0D;
public boolean hasFlyLimit = true;
public int flyHeightLimit = 2;
public EnumAnimation animationType = EnumAnimation.NONE;
public EnumStandingType standingType = EnumStandingType.RotateBody;
public EnumMovingType movingType = EnumMovingType.Standing;
@@ -59,7 +59,7 @@ public class DataAI {
this.npc = npc;
}
public void readToNBT(NBTTagCompound compound) {
public void readToNBT(NBTTagCompound compound) {
canSwim = compound.getBoolean("CanSwim");
reactsToFire = compound.getBoolean("ReactsToFire");
avoidsWater = compound.getBoolean("AvoidsWater");
@@ -79,21 +79,21 @@ public class DataAI {
movingPause = compound.getBoolean("MovingPause");
npcInteracting = compound.getBoolean("npcInteracting");
stopAndInteract = compound.getBoolean("stopAndInteract");
animationType = EnumAnimation.values()[compound.getInteger("MoveState") % EnumAnimation.values().length];
standingType = EnumStandingType.values()[compound.getInteger("StandingState") % EnumStandingType.values().length];
movingType = EnumMovingType.values()[compound.getInteger("MovingState") % EnumMovingType.values().length];
tacticalVariant = EnumNavType.values()[compound.getInteger("TacticalVariant") % EnumNavType.values().length];
combatPolicy = EnumCombatPolicy.values()[compound.getInteger("CombatPolicy") % EnumCombatPolicy.values().length];
orientation = compound.getInteger("Orientation");
bodyOffsetY = compound.getFloat("PositionOffsetY");
bodyOffsetZ = compound.getFloat("PositionOffsetZ");
bodyOffsetX = compound.getFloat("PositionOffsetX");
walkingRange = compound.getInteger("WalkingRange");
setWalkingSpeed(compound.getInteger("MoveSpeed"));
setMovingPath(NBTTags.getIntegerArraySet(compound.getTagList("MovingPathNew",10)));
movingPos = compound.getInteger("MovingPos");
movingPattern = compound.getInteger("MovingPatern");
@@ -121,7 +121,7 @@ public class DataAI {
startPos = compound.getIntArray("StartPosNew");
if (startPos == null || startPos.length != 3){
startPos = new int[] {
startPos = new int[] {
MathHelper.floor_double(npc.posX),
MathHelper.floor_double(npc.posY),
MathHelper.floor_double(npc.posZ) };
@@ -154,14 +154,14 @@ public class DataAI {
compound.setInteger("MovingState", movingType.ordinal());
compound.setInteger("TacticalVariant", tacticalVariant.ordinal());
compound.setInteger("CombatPolicy", combatPolicy.ordinal());
compound.setInteger("Orientation", orientation);
compound.setFloat("PositionOffsetX", bodyOffsetX);
compound.setFloat("PositionOffsetY", bodyOffsetY);
compound.setFloat("PositionOffsetZ", bodyOffsetZ);
compound.setInteger("WalkingRange", walkingRange);
compound.setInteger("MoveSpeed", moveSpeed);
compound.setTag("MovingPathNew", NBTTags.nbtIntegerArraySet(movingPath));
compound.setInteger("MovingPos", movingPos);
compound.setInteger("MovingPatern", movingPattern);
@@ -173,9 +173,9 @@ public class DataAI {
compound.setInteger("FlyHeightLimit", flyHeightLimit);
npc.setAvoidWater(avoidsWater);
compound.setIntArray("StartPosNew", npc.getStartPos());
return compound;
}
@@ -190,7 +190,7 @@ public class DataAI {
if(!movingPath.isEmpty())
startPos = movingPath.get(0);
}
public int[] getCurrentMovingPath(){
List<int[]> list = getMovingPath();
if(list.size() == 1){
@@ -206,14 +206,14 @@ public class DataAI {
}
else if(movingPos >= list.size()){
return list.get(list.size() - (movingPos % list.size()) - 2);
}
}
}
}
return list.get(movingPos);
}
public void incrementMovingPath(){
List<int[]> list = getMovingPath();
if(list.size() == 1){
@@ -229,7 +229,7 @@ public class DataAI {
movingPos = movingPos % size;
}
}
public void decreaseMovingPath() {
List<int[]> list = getMovingPath();
@@ -254,12 +254,12 @@ public class DataAI {
int[] pos = getCurrentMovingPath();
return npc.getDistanceSq(pos[0] + 0.5, pos[1], pos[2] + 0.5);
}
public void setWalkingSpeed(double speed){
this.moveSpeed = (int)speed;
npc.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(npc.getSpeed());
}
public int getWalkingSpeed(){
return this.moveSpeed;
}
+1 -1
View File
@@ -82,7 +82,7 @@ public class DataAdvanced {
compound.setString("SoulStonePlayerName", soulStonePlayerName);
compound.setInteger("MinFactionPointsToSoulStone", minFactionPointsToSoulStone);
if(tagUUIDs.size() > 0){
if(!tagUUIDs.isEmpty()){
NBTTagList nbtTagList = new NBTTagList();
for (UUID uuid : tagUUIDs) {
nbtTagList.appendTag(new NBTTagString(uuid.toString()));
+15 -15
View File
@@ -24,14 +24,14 @@ public class DataInventory implements IInventory {
public HashMap<Integer,ItemStack> weapons = new HashMap<Integer, ItemStack>();
public HashMap<Integer,ItemStack> prevWeapons = new HashMap<Integer, ItemStack>();
public HashMap<Integer,ItemStack> armor = new HashMap<Integer, ItemStack>();
public int minExp = 0;
public int maxExp = 0;
public int lootMode = 0;
private EntityNPCInterface npc;
public DataInventory(EntityNPCInterface npc){
this.npc = npc;
}
@@ -43,7 +43,7 @@ public class DataInventory implements IInventory {
nbttagcompound.setTag("Weapons", NBTTags.nbtItemStackList(getWeapons()));
nbttagcompound.setTag("DoubleDropChance", NBTTags.nbtIntegerDoubleMap(dropchance));
nbttagcompound.setInteger("LootMode", lootMode);
return nbttagcompound;
}
public void readEntityFromNBT(NBTTagCompound nbttagcompound){
@@ -187,7 +187,7 @@ public class DataInventory implements IInventory {
npc.worldObj.spawnEntityInWorld(item);
}
}
public EntityItem getEntityItem(ItemStack itemstack) {
if (itemstack == null) {
return null;
@@ -205,13 +205,13 @@ public class DataInventory implements IInventory {
return entityitem;
}
public ItemStack armorItemInSlot(int i) {
return getArmor().get(i);
}
@Override
public int getSizeInventory() {
// TODO Auto-generated method stub
return 15;
}
@Override
@@ -243,7 +243,7 @@ public class DataInventory implements IInventory {
var3 = getArmor();
i = 2;
}
ItemStack var4 = null;
if (var3.get(par1) != null)
{
@@ -355,17 +355,17 @@ public class DataInventory implements IInventory {
}
@Override
public void markDirty() {
// TODO Auto-generated method stub
}
@Override
public void openInventory() {
// TODO Auto-generated method stub
}
@Override
public void closeInventory() {
// TODO Auto-generated method stub
}
}
+65 -56
View File
@@ -2,12 +2,16 @@ package noppes.npcs;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.*;
import noppes.npcs.constants.EnumParticleType;
import noppes.npcs.constants.EnumPotionType;
import noppes.npcs.controllers.data.MagicData;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.ValueUtil;
import java.util.HashSet;
import java.util.UUID;
public class DataStats {
private float attackStrength = 5;
@@ -27,6 +31,7 @@ public class DataStats {
public boolean playerSetCanDespawn = false;
public Resistances resistances = new Resistances();
public MagicData magicData = new MagicData();
public boolean ignoreCobweb = false;
public boolean immuneToFire = false;
@@ -119,75 +124,79 @@ public class DataStats {
compound.setBoolean("PlayerSetCanDespawn", playerSetCanDespawn);
compound.setInteger("CollidesWith",collidesWith);
magicData.writeToNBT(compound);
return compound;
}
public void readToNBT(NBTTagCompound compound) {
resistances.readToNBT(compound.getCompoundTag("Resistances"));
setMaxHealth(compound.getDouble("MaxHealth"));
hideKilledBody = compound.getBoolean("HideBodyWhenKilled");
aggroRange = compound.getInteger("AggroRange");
respawnTime = compound.getInteger("RespawnTime");
spawnCycle = compound.getInteger("SpawnCycle");
creatureType = EnumCreatureAttribute.values()[compound.getInteger("CreatureType") % EnumPotionType.values().length];
ignoreCobweb = compound.getBoolean("IgnoreCobweb");
healthRegen = compound.getFloat("HealthRegen");
combatRegen = compound.getFloat("CombatRegen");
resistances.readToNBT(compound.getCompoundTag("Resistances"));
setMaxHealth(compound.getDouble("MaxHealth"));
hideKilledBody = compound.getBoolean("HideBodyWhenKilled");
aggroRange = compound.getInteger("AggroRange");
respawnTime = compound.getInteger("RespawnTime");
spawnCycle = compound.getInteger("SpawnCycle");
creatureType = EnumCreatureAttribute.values()[compound.getInteger("CreatureType") % EnumPotionType.values().length];
ignoreCobweb = compound.getBoolean("IgnoreCobweb");
healthRegen = compound.getFloat("HealthRegen");
combatRegen = compound.getFloat("CombatRegen");
setAttackStrength(compound.getFloat("AttackStrenght"));
attackSpeed = compound.getInteger("AttackSpeed");
swingWarmUp = ValueUtil.clamp(compound.getInteger("SwingWarmup"), 0, 1000);
attackRange = compound.getInteger("AttackRange");
knockback = compound.getInteger("KnockBack");
potionType = EnumPotionType.values()[compound.getInteger("PotionEffect") % EnumPotionType.values().length];
potionDuration = compound.getInteger("PotionDuration");
potionAmp = compound.getInteger("PotionAmp");
setAttackStrength(compound.getFloat("AttackStrenght"));
attackSpeed = compound.getInteger("AttackSpeed");
swingWarmUp = ValueUtil.clamp(compound.getInteger("SwingWarmup"), 0, 1000);
attackRange = compound.getInteger("AttackRange");
knockback = compound.getInteger("KnockBack");
potionType = EnumPotionType.values()[compound.getInteger("PotionEffect") % EnumPotionType.values().length];
potionDuration = compound.getInteger("PotionDuration");
potionAmp = compound.getInteger("PotionAmp");
rangedRange = compound.getInteger("MaxFiringRange");
fireRate = compound.getInteger("FireRate");
minDelay = ValueUtil.clamp(compound.getInteger("minDelay"), 1, 9999);
maxDelay = ValueUtil.clamp(compound.getInteger("maxDelay"), 1, 9999);
burstCount = compound.getInteger("BurstCount");
shotCount = ValueUtil.clamp(compound.getInteger("ShotCount"), 1, 10);
accuracy = compound.getInteger("Accuracy");
rangedRange = compound.getInteger("MaxFiringRange");
fireRate = compound.getInteger("FireRate");
minDelay = ValueUtil.clamp(compound.getInteger("minDelay"), 1, 9999);
maxDelay = ValueUtil.clamp(compound.getInteger("maxDelay"), 1, 9999);
burstCount = compound.getInteger("BurstCount");
shotCount = ValueUtil.clamp(compound.getInteger("ShotCount"), 1, 10);
accuracy = compound.getInteger("Accuracy");
pDamage = compound.getFloat("pDamage");
pImpact = compound.getInteger("pImpact");
pSize = compound.getInteger("pSize");
pSpeed = compound.getInteger("pSpeed");
pArea = compound.getInteger("pArea");
pDur = compound.getInteger("pDur");
pPhysics = compound.getBoolean("pPhysics");
pXlr8 = compound.getBoolean("pXlr8");
pGlows = compound.getBoolean("pGlows");
pExplode = compound.getBoolean("pExplode");
pRender3D = compound.getBoolean("pRender3D");
pSpin = compound.getBoolean("pSpin");
pStick = compound.getBoolean("pStick");
pEffect = EnumPotionType.values()[compound.getInteger("pEffect") % EnumPotionType.values().length];
pTrail = EnumParticleType.values()[compound.getInteger("pTrail") % EnumParticleType.values().length];
pEffAmp = compound.getInteger("pEffAmp");
fireSound = compound.getString("FiringSound");
aimWhileShooting = compound.getBoolean("AimWhileShooting");
projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain");
pDamage = compound.getFloat("pDamage");
pImpact = compound.getInteger("pImpact");
pSize = compound.getInteger("pSize");
pSpeed = compound.getInteger("pSpeed");
pArea = compound.getInteger("pArea");
pDur = compound.getInteger("pDur");
pPhysics = compound.getBoolean("pPhysics");
pXlr8 = compound.getBoolean("pXlr8");
pGlows = compound.getBoolean("pGlows");
pExplode = compound.getBoolean("pExplode");
pRender3D = compound.getBoolean("pRender3D");
pSpin = compound.getBoolean("pSpin");
pStick = compound.getBoolean("pStick");
pEffect = EnumPotionType.values()[compound.getInteger("pEffect") % EnumPotionType.values().length];
pTrail = EnumParticleType.values()[compound.getInteger("pTrail") % EnumParticleType.values().length];
pEffAmp = compound.getInteger("pEffAmp");
fireSound = compound.getString("FiringSound");
aimWhileShooting = compound.getBoolean("AimWhileShooting");
projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain");
immuneToFire = compound.getBoolean("ImmuneToFire");
potionImmune = compound.getBoolean("PotionImmune");
drowningType = compound.getInteger("DrowningType");
immuneToFire = compound.getBoolean("ImmuneToFire");
potionImmune = compound.getBoolean("PotionImmune");
drowningType = compound.getInteger("DrowningType");
burnInSun = compound.getBoolean("BurnInSun");
noFallDamage = compound.getBoolean("NoFallDamage");
attackInvisible = compound.getBoolean("AttackInvisible");
canDespawn = compound.getBoolean("CanDespawn");
playerSetCanDespawn = compound.getBoolean("PlayerSetCanDespawn");
burnInSun = compound.getBoolean("BurnInSun");
noFallDamage = compound.getBoolean("NoFallDamage");
attackInvisible = compound.getBoolean("AttackInvisible");
canDespawn = compound.getBoolean("CanDespawn");
playerSetCanDespawn = compound.getBoolean("PlayerSetCanDespawn");
magicData.readToNBT(compound);
npc.setImmuneToFire(immuneToFire);
npc.setImmuneToFire(immuneToFire);
if(compound.hasKey("CollidesWith"))
if (compound.hasKey("CollidesWith"))
collidesWith = compound.getInteger("CollidesWith");
else
collidesWith = 1;
}
}
public float getAttackStrength(){
return attackStrength;
+174 -40
View File
@@ -15,12 +15,16 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.world.WorldEvent;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.entity.IProjectile;
import noppes.npcs.api.entity.*;
import noppes.npcs.api.event.IAnimationEvent;
import noppes.npcs.api.event.IPlayerEvent;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.api.handler.data.IProfile;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemLinked;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.CustomGuiController;
@@ -32,7 +36,6 @@ import noppes.npcs.entity.EntityProjectile;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.*;
import noppes.npcs.scripted.event.PlayerEvent.*;
import noppes.npcs.scripted.item.ScriptCustomItem;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
@@ -41,79 +44,147 @@ public class EventHooks {
public EventHooks() {
}
public static void onScriptItemInit(IItemCustom handler) {
if (!((ScriptCustomItem) handler).isClient()) {
ItemEvent.InitEvent event = new ItemEvent.InitEvent(handler);
((ScriptCustomItem) handler).callScript(EnumScriptType.INIT, event);
public static void onScriptItemInit(IItemCustomizable item) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
if (handler != null && !handler.isClient()) {
ItemEvent.InitEvent event = new ItemEvent.InitEvent(item);
handler.callScript(EnumScriptType.INIT, event);
NpcAPI.EVENT_BUS.post(event);
}
}
public static void onScriptItemUpdate(IItemCustom handler, EntityLivingBase player) {
if (!((ScriptCustomItem) handler).isClient()) {
ItemEvent.UpdateEvent event = new ItemEvent.UpdateEvent(handler, NpcAPI.Instance().getIEntity(player));
((ScriptCustomItem) handler).callScript(EnumScriptType.TICK, event);
public static void onScriptItemUpdate(IItemCustomizable item, EntityLivingBase player) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
if (handler != null && !handler.isClient()) {
ItemEvent.UpdateEvent event = new ItemEvent.UpdateEvent(item, NpcAPI.Instance().getIEntity(player));
handler.callScript(EnumScriptType.TICK, event);
NpcAPI.EVENT_BUS.post(event);
}
}
public static boolean onScriptItemTossed(IItemCustom handler, EntityPlayer player, EntityItem entity) {
ItemEvent.TossedEvent event = new ItemEvent.TossedEvent(handler, (IPlayer)NpcAPI.Instance().getIEntity(player), NpcAPI.Instance().getIEntity(entity));
((ScriptCustomItem) handler).callScript(EnumScriptType.TOSSED, event);
public static boolean onScriptItemTossed(IItemCustomizable item, EntityPlayer player, EntityItem entity) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.TossedEvent event = new ItemEvent.TossedEvent(item, (IPlayer)NpcAPI.Instance().getIEntity(player), NpcAPI.Instance().getIEntity(entity));
if (handler != null) {
handler.callScript(EnumScriptType.TOSSED, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemPickedUp(IItemCustom handler, EntityPlayer player) {
ItemEvent.PickedUpEvent event = new ItemEvent.PickedUpEvent(handler, (IPlayer)NpcAPI.Instance().getIEntity(player));
((ScriptCustomItem) handler).callScript(EnumScriptType.PICKEDUP, event);
public static boolean onScriptItemPickedUp(IItemCustomizable item, EntityPlayer player) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.PickedUpEvent event = new ItemEvent.PickedUpEvent(item, (IPlayer)NpcAPI.Instance().getIEntity(player));
if (handler != null) {
handler.callScript(EnumScriptType.PICKEDUP, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemSpawn(IItemCustom handler, EntityItem entity) {
ItemEvent.SpawnEvent event = new ItemEvent.SpawnEvent(handler, NpcAPI.Instance().getIEntity(entity));
((ScriptCustomItem) handler).callScript(EnumScriptType.SPAWN, event);
public static boolean onScriptItemSpawn(IItemCustomizable item, EntityItem entity) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.SpawnEvent event = new ItemEvent.SpawnEvent(item, NpcAPI.Instance().getIEntity(entity));
if (handler != null) {
handler.callScript(EnumScriptType.SPAWN, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemInteract(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.InteractEvent event) {
((ScriptCustomItem) handler).callScript(EnumScriptType.INTERACT, event);
public static boolean onScriptItemInteract(IItemCustomizable item, noppes.npcs.scripted.event.ItemEvent.InteractEvent event) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
if (handler != null) {
handler.callScript(EnumScriptType.INTERACT, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemRightClick(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.RightClickEvent event) {
((ScriptCustomItem) handler).callScript(EnumScriptType.RIGHT_CLICK, event);
public static boolean onScriptItemRightClick(IItemCustomizable item, noppes.npcs.scripted.event.ItemEvent.RightClickEvent event) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
if (handler != null) {
handler.callScript(EnumScriptType.RIGHT_CLICK, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onScriptItemAttack(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) {
((ScriptCustomItem) handler).callScript(EnumScriptType.ATTACK, event);
public static boolean onScriptItemAttack(IItemCustomizable item, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
if (handler != null) {
handler.callScript(EnumScriptType.ATTACK, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onStartUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.StartUsingItem event = new ItemEvent.StartUsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.START_USING_ITEM, event);
public static boolean onStartUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.StartUsingItem event = new ItemEvent.StartUsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.START_USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.UsingItem event = new ItemEvent.UsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.USING_ITEM, event);
public static boolean onUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.UsingItem event = new ItemEvent.UsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onStopUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.StopUsingItem event = new ItemEvent.StopUsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.STOP_USING_ITEM, event);
public static boolean onStopUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.StopUsingItem event = new ItemEvent.StopUsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.STOP_USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onFinishUsingCustomItem(IItemCustom handler, IPlayer player, int duration) {
ItemEvent.FinishUsingItem event = new ItemEvent.FinishUsingItem(handler, player, duration);
((ScriptCustomItem) handler).callScript(EnumScriptType.FINISH_USING_ITEM, event);
public static boolean onFinishUsingCustomItem(IItemCustomizable item, IPlayer player, int duration) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.FinishUsingItem event = new ItemEvent.FinishUsingItem(item, player, duration);
if (handler != null) {
handler.callScript(EnumScriptType.FINISH_USING_ITEM, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static void onRepairCustomItem(IItemCustomizable item, IPlayer player, IItemStack left, IItemStack right, float anvilBreakChance) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.RepairItem event = new ItemEvent.RepairItem(item, player, left, right, anvilBreakChance);
if (handler != null) {
handler.callScript(EnumScriptType.REPAIR_ITEM, event);
}
NpcAPI.EVENT_BUS.post(event);
}
public static void onBreakCustomItem(IItemCustomizable item, IPlayer player) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
ItemEvent.BreakItem event = new ItemEvent.BreakItem(item, player);
if (handler != null) {
handler.callScript(EnumScriptType.BREAK_ITEM, event);
}
NpcAPI.EVENT_BUS.post(event);
}
public static void onLinkedItemVersionChange(IItemLinked item, int version, int prevVersion) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
LinkedItemEvent.VersionChangeEvent event = new LinkedItemEvent.VersionChangeEvent(item, version, prevVersion);
if (handler != null) {
handler.callScript(EnumScriptType.LINKED_ITEM_VERSION, event);
}
NpcAPI.EVENT_BUS.post(event);
}
public static void onLinkedItemBuild(IItemLinked item) {
INpcScriptHandler handler = (INpcScriptHandler) item.getScriptHandler();
LinkedItemEvent.BuildEvent event = new LinkedItemEvent.BuildEvent(item);
if (handler != null) {
handler.callScript(EnumScriptType.LINKED_ITEM_BUILD, event);
}
NpcAPI.EVENT_BUS.post(event);
}
public static void onNPCInit(EntityNPCInterface npc) {
if(npc == null || npc.wrappedNPC == null)
return;
@@ -803,4 +874,67 @@ public class EventHooks {
handler.callScript(EnumScriptType.PARTY_DISBAND, event);
NpcAPI.EVENT_BUS.post(event);
}
private static boolean postAnimationEvent(IAnimationEvent event) {
IScriptHandler handler;
IAnimatable animatable = event.getAnimation().getParent().getEntity();
if (animatable instanceof ICustomNpc<?>) {
EntityNPCInterface npc = (EntityNPCInterface) ((ICustomNpc<?>) animatable).getMCEntity();
handler = npc.script;
} else {
handler = ScriptController.Instance.playerScripts;
}
if (handler.isClient())
return false;
handler.callScript(event.getHookName(), (Event) event);
return NpcAPI.EVENT_BUS.post((Event) event);
}
public static boolean onAnimationStarted(IAnimation animation) {
if (animation.getParent() == null || animation.getParent().getEntity() == null) {
return false;
}
return postAnimationEvent(new AnimationEvent.Started(animation));
}
public static void onAnimationEnded(IAnimation animation) {
if (animation.getParent() == null || animation.getParent().getEntity() == null) {
return;
}
postAnimationEvent(new AnimationEvent.Ended(animation));
}
public static void onAnimationFrameEntered(IAnimation animation, IFrame frame) {
if (frame == null || animation.getParent() == null || animation.getParent().getEntity() == null) {
return;
}
postAnimationEvent(new AnimationEvent.FrameEvent.Entered(animation, frame));
}
public static void onAnimationFrameExited(IAnimation animation, IFrame frame) {
if (frame == null || animation.getParent() == null || animation.getParent().getEntity() == null) {
return;
}
postAnimationEvent(new AnimationEvent.FrameEvent.Exited(animation, frame));
}
public static boolean onProfileChange(PlayerDataScript handler, IPlayer player, IProfile profile, int slot) {
PlayerEvent.ProfileEvent.Changed event = new PlayerEvent.ProfileEvent.Changed(player, profile, slot, profile.getCurrentSlotId());
handler.callScript(EnumScriptType.PROFILE_CHANGE, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onProfileRemove(PlayerDataScript handler, IPlayer player, IProfile profile, int slot) {
PlayerEvent.ProfileEvent.Removed event = new PlayerEvent.ProfileEvent.Removed(player, profile, slot);
handler.callScript(EnumScriptType.PROFILE_REMOVE, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onProfileCreate(PlayerDataScript handler, IPlayer player, IProfile profile, int slot) {
PlayerEvent.ProfileEvent.Create event = new PlayerEvent.ProfileEvent.Create(player, profile, slot);
handler.callScript(EnumScriptType.PROFILE_CREATE, event);
return NpcAPI.EVENT_BUS.post(event);
}
}
+3 -3
View File
@@ -81,10 +81,10 @@ public class LogWriter {
logger.setLevel(Level.ALL);
info(new Date().toString());
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@@ -223,4 +223,4 @@ class NPCStamp
public Date makeDate = new Date();
public Date recentDate = new Date();
public int counter = 1;
};
};
+29 -4
View File
@@ -1,10 +1,7 @@
package noppes.npcs;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.*;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.data.IScriptHandler;
@@ -12,6 +9,19 @@ import java.util.*;
public class NBTTags {
public static int TAG_End = 0;
public static int TAG_Byte = 1;
public static int TAG_Short = 2;
public static int TAG_Int = 3;
public static int TAG_Long = 4;
public static int TAG_Float = 5;
public static int TAG_Double = 6;
public static int TAG_Byte_Array = 7;
public static int TAG_String = 8;
public static int TAG_List = 9;
public static int TAG_Compound = 10;
public static int TAG_Int_Array = 11;
public static HashMap<Integer, ItemStack> getItemStackList(
NBTTagList tagList) {
HashMap<Integer, ItemStack> list = new HashMap<Integer, ItemStack>();
@@ -585,4 +595,19 @@ public class NBTTags {
return list;
}
public static int getIntAt(NBTTagList tagList, int index)
{
if (index >= 0 && index < tagList.tagCount())
{
NBTBase nbtbase = tagList.getCompoundTagAt(index);
if (nbtbase.getId() == 3)
{
return ((NBTTagInt)nbtbase).func_150287_d();
}
}
return 0;
}
}
+2 -2
View File
@@ -181,8 +181,8 @@ public class NPCSpawning {
if(spawnEntity instanceof EntityCustomNpc){
EntityCustomNpc npc = (EntityCustomNpc) spawnEntity;
npc.stats.spawnCycle = 3;
npc.ai.returnToStart = false;
npc.ai.startPos = new int[]{x,y, z};
npc.ais.returnToStart = false;
npc.ais.startPos = new int[]{x,y, z};
npc.updateAI = true;
npc.updateClient = true;
npc.getNavigator().clearPathEntity();
+29 -33
View File
@@ -1,8 +1,14 @@
package noppes.npcs;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumSoundOperation;
import kamkeel.npcs.network.packets.data.*;
import kamkeel.npcs.network.packets.data.gui.GuiClosePacket;
import kamkeel.npcs.network.packets.data.gui.IsGuiOpenPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
@@ -133,11 +139,11 @@ public class NoppesUtilPlayer {
}
}
Server.sendData(player, EnumPacketClient.DISABLE_MOUSE_INPUT, time, stringedIds.toString());
PacketHandler.Instance.sendToPlayer(new DisableMouseInputPacket(time, stringedIds.toString()), player);
}
public static void swingPlayerArm(EntityPlayerMP player){
Server.sendData(player, EnumPacketClient.SWING_PLAYER_ARM);
PacketHandler.Instance.sendToPlayer(new SwingPlayerArmPacket(), player);
}
private static void followerBuy(RoleFollower role,IInventory currencyInv,EntityPlayerMP player, EntityNPCInterface npc){
@@ -251,16 +257,6 @@ public class NoppesUtilPlayer {
bankData.openBankGui(player, npc, bank.id, container.slot);
}
public static void sendData(EnumPlayerPacket enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
try {
if(!Server.fillBuffer(buffer, enu, obs))
return;
CustomNpcs.ChannelPlayer.sendToServer(new FMLProxyPacket(buffer,"CustomNPCsPlayer"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void dialogSelected(int dialogId, int optionId, EntityPlayerMP player, EntityNPCInterface npc) {
Dialog dialog = DialogController.Instance.dialogs.get(dialogId);
@@ -286,23 +282,23 @@ public class NoppesUtilPlayer {
if(npc.roleInterface != null)
npc.roleInterface.interact(player);
else
Server.sendData(player, EnumPacketClient.GUI_CLOSE);
GuiClosePacket.closeGUI(player, -1 , new NBTTagCompound());
}
else if(option.optionType == EnumOptionType.DialogOption){
NoppesUtilServer.openDialog(player, npc, option.getDialog(), optionId+1);
}
else if(option.optionType == EnumOptionType.CommandBlock){
Server.sendData(player, EnumPacketClient.GUI_CLOSE);
GuiClosePacket.closeGUI(player, -1 , new NBTTagCompound());
NoppesUtilServer.runCommand(player, npc.getCommandSenderName(), option.command);
}
else
Server.sendData(player, EnumPacketClient.GUI_CLOSE);
GuiClosePacket.closeGUI(player, -1 , new NBTTagCompound());
}
public static void updateQuestLogData(ByteBuf buffer, EntityPlayerMP player) throws IOException {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
NBTTagCompound compound = Server.readNBT(buffer);
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
HashMap<String,String> questAlerts = NBTTags.getStringStringMap(compound.getTagList("Alerts", 10));
for (Map.Entry<String,String> entry : questAlerts.entrySet()) {
Quest quest = getQuestFromStringKey(entry.getKey());
@@ -311,7 +307,7 @@ public class NoppesUtilPlayer {
}
}
String trackedQuestString = Server.readString(buffer);
String trackedQuestString = ByteBufUtils.readString(buffer);
Quest trackedQuest = getQuestFromStringKey(trackedQuestString);
if (trackedQuest != null) {
playerData.questData.trackQuest(trackedQuest);
@@ -328,7 +324,7 @@ public class NoppesUtilPlayer {
public static void updatePartyQuestLogData(ByteBuf buffer, EntityPlayerMP player) throws IOException {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
String trackedQuestString = Server.readString(buffer);
String trackedQuestString = ByteBufUtils.readString(buffer);
Quest trackedQuest = getQuestFromStringKey(trackedQuestString);
if (trackedQuest != null) {
playerData.questData.trackParty(playerData.getPlayerParty());
@@ -384,7 +380,7 @@ public class NoppesUtilPlayer {
}
compound.setTag("ObjectiveList",nbtTagList);
Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound);
PacketHandler.Instance.sendToPlayer(new OverlayQuestTrackingPacket(compound), player);
}
}
@@ -407,8 +403,7 @@ public class NoppesUtilPlayer {
nbtTagList.appendTag(new NBTTagString(objective.getAdditionalText()));
}
compound.setTag("ObjectiveList",nbtTagList);
Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound);
PacketHandler.Instance.sendToPlayer(new OverlayQuestTrackingPacket(compound), player);
}
}
@@ -418,13 +413,14 @@ public class NoppesUtilPlayer {
}
QuestLogData data = new QuestLogData();
data.setData(player);
Server.sendData(player, EnumPacketClient.GUI_DATA, data.writeNBT());
GuiDataPacket.sendGuiData(player, data.writeNBT());
}
public static void sendTrackedQuest(EntityPlayerMP player) {
QuestLogData data = new QuestLogData();
data.setTrackedQuestKey(player);
Server.sendData(player, EnumPacketClient.PARTY_DATA, data.writeTrackedQuest());
PartyDataPacket.sendPartyData(player, data.writeTrackedQuest());
}
public static boolean questCompletion(EntityPlayerMP player, int questId) {
@@ -626,7 +622,7 @@ public class NoppesUtilPlayer {
}
playerData.save();
Server.sendData((EntityPlayerMP)player, EnumPacketClient.QUEST_COMPLETION, data.quest.writeToNBT(new NBTTagCompound()));
QuestCompletionPacket.sendQuestComplete((EntityPlayerMP)player, data.quest.writeToNBT(new NBTTagCompound()));
}
if(quest.type == EnumQuestType.Item && partyOptions.objectiveRequirement == EnumPartyObjectives.Shared){
@@ -740,7 +736,7 @@ public class NoppesUtilPlayer {
}
}
public static void isGUIOpen(EntityPlayerMP player){
Server.sendData(player, EnumPacketClient.ISGUIOPEN);
PacketHandler.Instance.sendToPlayer(new IsGuiOpenPacket(), player);
}
public static List<ItemStack> countStacks(IInventory inv, boolean ignoreDamage, boolean ignoreNBT) {
@@ -773,30 +769,30 @@ public class NoppesUtilPlayer {
public static void playSoundTo(EntityPlayerMP player, int id, ScriptSound sound) {
NBTTagCompound compound = sound.writeToNBT();
if (sound.sourceEntity == null || player.worldObj.provider.dimensionId == sound.sourceEntity.getDimension()) {
Server.sendData(player, EnumPacketClient.PLAY_SOUND_TO, id, compound);
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.PLAY_SOUND_TO, id, compound), player);
}
}
public static void playSoundTo(EntityPlayerMP player, ScriptSound sound) {
NBTTagCompound compound = sound.writeToNBT();
if (sound.sourceEntity == null || player.worldObj.provider.dimensionId == sound.sourceEntity.getDimension()) {
Server.sendData(player, EnumPacketClient.PLAY_SOUND_TO_NO_ID, compound);
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.PLAY_SOUND_TO_NO_ID, compound), player);
}
}
public static void stopSoundFor(EntityPlayerMP player, int id) {
Server.sendData(player, EnumPacketClient.STOP_SOUND_FOR, id);
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.STOP_SOUND_FOR, id), player);
}
public static void pauseSoundsFor(EntityPlayerMP player) {
Server.sendData(player, EnumPacketClient.PAUSE_SOUNDS);
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.PAUSE_SOUNDS), player);
}
public static void continueSoundsFor(EntityPlayerMP player) {
Server.sendData(player, EnumPacketClient.CONTINUE_SOUNDS);
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.CONTINUE_SOUNDS), player);
}
public static void stopSoundsFor(EntityPlayerMP player) {
Server.sendData(player, EnumPacketClient.STOP_SOUNDS);
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.STOP_SOUNDS), player);
}
}
+280 -142
View File
@@ -1,6 +1,23 @@
package noppes.npcs;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.ParticlePacket;
import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket;
import kamkeel.npcs.network.packets.data.gui.GuiClosePacket;
import kamkeel.npcs.network.packets.data.gui.GuiErrorPacket;
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
import kamkeel.npcs.network.packets.data.gui.GuiTeleporterPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
import kamkeel.npcs.network.packets.data.npc.DeleteNpcPacket;
import kamkeel.npcs.network.packets.data.npc.DialogPacket;
import kamkeel.npcs.network.packets.data.npc.EditNpcPacket;
import kamkeel.npcs.network.packets.data.npc.RolePacket;
import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.command.server.CommandBlockLogic;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@@ -13,7 +30,6 @@ import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
@@ -27,9 +43,9 @@ import net.minecraft.world.World;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumPlayerData;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.containers.ContainerManageBanks;
import noppes.npcs.containers.ContainerManageRecipes;
import noppes.npcs.controllers.*;
@@ -41,43 +57,56 @@ import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptSound;
import noppes.npcs.scripted.event.DialogEvent;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.*;
import java.util.zip.GZIPOutputStream;
import static kamkeel.npcs.network.packets.data.large.ScrollDataPacket.sendScrollData;
public class NoppesUtilServer {
private static HashMap<String,Quest> editingQuests = new HashMap<String,Quest>();
public static void setEditingNpc(EntityPlayer player, EntityNPCInterface npc){
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
data.editingNpc = npc;
if(npc != null)
Server.sendDataChecked((EntityPlayerMP)player, EnumPacketClient.EDIT_NPC, npc.getEntityId());
}
public static EntityNPCInterface getEditingNpc(EntityPlayer player){
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
return data.editingNpc;
public static IPlayer getIPlayer(EntityPlayer p) {
return (IPlayer) NpcAPI.Instance().getIEntity(p);
}
public static UUID getUUID(Entity entity) {
return entity instanceof EntityPlayer ? ((EntityPlayer) entity).getGameProfile().getId() : entity.getUniqueID();
}
public static boolean isScriptableItem(Item item){
return item == CustomItems.scripted_item || item == CustomItems.linked_item;
}
public static void setEditingNpc(EntityPlayer player, EntityNPCInterface npc){
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
data.editingNpc = npc;
if(npc != null)
PacketHandler.Instance.sendToPlayer(new EditNpcPacket(npc.getEntityId()), (EntityPlayerMP)player);
}
public static EntityNPCInterface getEditingNpc(EntityPlayer player){
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
return data.editingNpc;
}
public static void setEditingQuest(EntityPlayer player, Quest quest) {
editingQuests.put(player.getCommandSenderName(), quest);
}
public static void setEditingQuest(EntityPlayer player, Quest quest) {
editingQuests.put(player.getCommandSenderName(), quest);
}
public static Quest getEditingQuest(EntityPlayer player){
return editingQuests.get(player.getCommandSenderName());
return editingQuests.get(player.getCommandSenderName());
}
public static void sendRoleData(EntityPlayer player, EntityNPCInterface npc){
if(npc.advanced.role == EnumRoleType.None)
return;
NBTTagCompound comp = new NBTTagCompound();
npc.roleInterface.writeToNBT(comp);
comp.setInteger("EntityId", npc.getEntityId());
comp.setInteger("Role", npc.advanced.role.ordinal());
Server.sendData((EntityPlayerMP)player, EnumPacketClient.ROLE, comp);
if(npc.advanced.role == EnumRoleType.None)
return;
NBTTagCompound comp = new NBTTagCompound();
npc.roleInterface.writeToNBT(comp);
comp.setInteger("EntityId", npc.getEntityId());
comp.setInteger("Role", npc.advanced.role.ordinal());
PacketHandler.Instance.sendToPlayer(new RolePacket(comp), (EntityPlayerMP)player);
}
public static void sendFactionDataAll(EntityPlayerMP player) {
@@ -85,7 +114,7 @@ public class NoppesUtilServer {
for(Faction faction : FactionController.getInstance().factions.values()){
map.put(faction.name, faction.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendAnimationDataAll(EntityPlayerMP player) {
@@ -93,7 +122,7 @@ public class NoppesUtilServer {
for(Animation animation : AnimationController.getInstance().animations.values()){
map.put(animation.name, animation.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendTagDataAll(EntityPlayerMP player) {
@@ -101,7 +130,7 @@ public class NoppesUtilServer {
for(Tag tag : TagController.getInstance().tags.values()){
map.put(tag.name, tag.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendBankDataAll(EntityPlayerMP player) {
@@ -109,7 +138,7 @@ public class NoppesUtilServer {
for(Bank bank : BankController.getInstance().banks.values()){
map.put(bank.name, bank.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static NBTTagCompound writeItem(ItemStack item, NBTTagCompound nbt){
@@ -184,11 +213,12 @@ public class NoppesUtilServer {
if(npc instanceof EntityDialogNpc || dia.id < 0){
dialog.hideNPC = true;
Server.sendData((EntityPlayerMP)player, EnumPacketClient.DIALOG_DUMMY, npc.getCommandSenderName(), dialog.writeToNBT(new NBTTagCompound()));
PacketHandler.Instance.sendToPlayer(new DialogPacket(npc.getCommandSenderName(), -1, dialog.writeToNBT(new NBTTagCompound())), (EntityPlayerMP)player);
}
else
Server.sendData((EntityPlayerMP)player, EnumPacketClient.DIALOG, npc.getEntityId(), dialog.writeToNBT(new NBTTagCompound()));
dia.factionOptions.addPoints(player);
PacketHandler.Instance.sendToPlayer(new DialogPacket("Real", npc.getEntityId(), dialog.writeToNBT(new NBTTagCompound())), (EntityPlayerMP)player);
dia.factionOptions.addPoints(player);
if(dialog.hasQuest())
PlayerQuestController.addActiveQuest(new QuestData(dialog.getQuest()),player);
if(!dialog.command.isEmpty()){
@@ -263,9 +293,6 @@ public class NoppesUtilServer {
player.destroyCurrentEquippedItem();
}
public static DataOutputStream getDataOutputStream(ByteArrayOutputStream stream) throws IOException{
return new DataOutputStream(new GZIPOutputStream(stream));
}
public static void sendOpenGui(EntityPlayer player,
EnumGuiType gui, EntityNPCInterface npc) {
sendOpenGui(player, gui, npc, 0, 0, 0);
@@ -289,14 +316,14 @@ public class NoppesUtilServer {
return;
}
else{
Server.sendDataChecked((EntityPlayerMP)player, EnumPacketClient.GUI, gui.ordinal(), i, j, k);
GuiOpenPacket.openGUI((EntityPlayerMP)player, gui, i, j, k);
}
ArrayList<String> list = getScrollData(player, gui, npc);
if(list == null || list.isEmpty())
return;
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SCROLL_LIST, list);
}
ScrollListPacket.sendList((EntityPlayerMP)player, list, EnumScrollData.OPTIONAL);
}
public static void sendOpenGuiNoDelay(final EntityPlayer player,
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
@@ -311,13 +338,13 @@ public class NoppesUtilServer {
return;
}
else{
Server.sendDataChecked((EntityPlayerMP)player, EnumPacketClient.GUI, gui.ordinal(), i, j, k);
GuiOpenPacket.openGUI((EntityPlayerMP)player, gui, i, j, k);
}
ArrayList<String> list = getScrollData(player, gui, npc);
if(list == null || list.isEmpty())
return;
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SCROLL_LIST, list);
ScrollListPacket.sendList((EntityPlayerMP)player, list, EnumScrollData.OPTIONAL);
}
@@ -352,17 +379,12 @@ public class NoppesUtilServer {
}
return null;
}
public static void spawnParticle(Entity entity,String particle,int dimension){
Server.sendAssociatedData(entity, EnumPacketClient.PARTICLE, entity.posX, entity.posY, entity.posZ, entity.height, entity.width, entity.yOffset, particle);
public static void spawnParticle(Entity entity,String particle, int dimension){
PacketHandler.Instance.sendTracking(new ParticlePacket(entity.posX, entity.posY, entity.posZ, entity.height, entity.width, entity.yOffset, particle), entity);
}
public static void spawnScriptedParticle(NBTTagCompound compound, int dimensionId){
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
if (player.worldObj.provider.dimensionId == dimensionId) {
Server.sendData((EntityPlayerMP) player, EnumPacketClient.SCRIPTED_PARTICLE, compound);
}
}
PacketHandler.Instance.sendToDimension(new ScriptedParticlePacket(compound), dimensionId);
}
public static void playSound(int id, ScriptSound sound) {
@@ -408,7 +430,7 @@ public class NoppesUtilServer {
}
public static void deleteNpc(EntityNPCInterface npc,EntityPlayer player) {
Server.sendAssociatedData(npc, EnumPacketClient.DELETE_NPC, npc.getEntityId());
PacketHandler.Instance.sendTracking(new DeleteNpcPacket(npc.getEntityId()), npc);
}
public static void createMobSpawner(int x, int y, int z, NBTTagCompound comp, EntityPlayer player) {
@@ -432,7 +454,7 @@ public class NoppesUtilServer {
for(QuestCategory category : QuestController.Instance.categories.values()){
map.put(category.title, category.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendPlayerData(EnumPlayerData type, EntityPlayerMP player, String name) throws IOException {
@@ -505,14 +527,14 @@ public class NoppesUtilServer {
}
}
NoppesUtilServer.sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void removePlayerData(ByteBuf buffer, EntityPlayerMP player) throws IOException {
int id = buffer.readInt();
if(EnumPlayerData.values().length <= id)
return;
String name = Server.readString(buffer);
String name = ByteBufUtils.readString(buffer);
EnumPlayerData type = EnumPlayerData.values()[id];
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(name);
PlayerData playerdata = null;
@@ -538,7 +560,6 @@ public class NoppesUtilServer {
playerdata.setNBT(new NBTTagCompound());
sendPlayerData(type, player, name);
playerdata.save();
return;
}
}
@@ -585,36 +606,17 @@ public class NoppesUtilServer {
for(RecipeCarpentry recipe : RecipeController.Instance.globalRecipes.values()){
map.put(recipe.name, recipe.id);
}
}
} else if (size == 4){
for(RecipeCarpentry recipe : RecipeController.Instance.carpentryRecipes.values()){
map.put(recipe.name, recipe.id);
}
}
else{
for(RecipeCarpentry recipe : RecipeController.Instance.anvilRecipes.values()){
map.put(recipe.name, recipe.id);
}
for(RecipeAnvil recipe : RecipeController.Instance.anvilRecipes.values()){
map.put(recipe.name, recipe.id);
}
}
sendScrollData(player, map);
}
public static void sendScrollData(EntityPlayerMP player, Map<String,Integer> map){
Map<String, Integer> send = new HashMap<String, Integer>();
for(String key : map.keySet()){
send.put(key, map.get(key));
if(send.size() == 100){
Server.sendData(player, EnumPacketClient.SCROLL_DATA_PART, send);
send = new HashMap<String, Integer>();
}
}
Server.sendData(player, EnumPacketClient.SCROLL_DATA, send);
}
public static void sendScrollGroup(EntityPlayerMP player, Map<String,Integer> map){
Map<String, Integer> send = new HashMap<String, Integer>();
for(String key : map.keySet()){
send.put(key, map.get(key));
if(send.size() == 100){
Server.sendData(player, EnumPacketClient.SCROLL_GROUP_PART, send);
send = new HashMap<String, Integer>();
}
}
Server.sendData(player, EnumPacketClient.SCROLL_GROUP, send);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendDialogData(EntityPlayerMP player, DialogCategory category) {
@@ -624,7 +626,7 @@ public class NoppesUtilServer {
for(Dialog dialog : category.dialogs.values()){
map.put(dialog.title, dialog.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendDialogGroup(EntityPlayerMP player, DialogCategory category) {
@@ -635,7 +637,7 @@ public class NoppesUtilServer {
map.put(dialog.title, dialog.id);
}
sendScrollGroup(player, map);
sendScrollData(player, map, EnumScrollData.DIALOG_GROUP);
}
public static void sendQuestData(EntityPlayerMP player, QuestCategory category) {
@@ -645,7 +647,7 @@ public class NoppesUtilServer {
for(Quest quest : category.quests.values()){
map.put(quest.title, quest.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendQuestGroup(EntityPlayerMP player, QuestCategory category) {
@@ -656,15 +658,31 @@ public class NoppesUtilServer {
map.put(quest.title, quest.id);
}
sendScrollGroup(player, map);
sendScrollData(player, map, EnumScrollData.QUEST_GROUP);
}
public static void sendCustomEffectDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) {
map.put(effect.name, effect.id);
}
ScrollDataPacket.sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendLinkedItemDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (LinkedItem linkedItem : LinkedItemController.getInstance().linkedItems.values()) {
map.put(linkedItem.name, linkedItem.id);
}
ScrollDataPacket.sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendTransportCategoryData(EntityPlayerMP player) {
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(TransportCategory category : TransportController.getInstance().categories.values()){
map.put(category.title, category.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendTransportData(EntityPlayerMP player, int categoryid) {
@@ -675,7 +693,7 @@ public class NoppesUtilServer {
for(TransportLocation transport : category.locations.values()){
map.put(transport.name, transport.id);
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
@@ -690,11 +708,25 @@ public class NoppesUtilServer {
NBTTagCompound compound = option.writeNBT();
compound.setInteger("Position", pos);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI_DATA, compound);
GuiDataPacket.sendGuiData((EntityPlayerMP)player, compound);
}
}
public static void sendMagicInfo(EntityPlayerMP player, boolean cycles) {
HashMap<String,Integer> map = new HashMap<String,Integer>();
if(cycles){
for(Magic magic : MagicController.getInstance().magics.values()){
map.put(magic.name, magic.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC);
} else {
for(MagicCycle magicCycle : MagicController.getInstance().cycles.values()){
map.put(magicCycle.name, magicCycle.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC_CYCLES);
}
}
public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException {
return setNpcDialog(slot, dialogId, getEditingNpc(player));
}
@@ -727,13 +759,13 @@ public class NoppesUtilServer {
public static void setClonerGui(EntityPlayerMP player, int x, int y, int z){
if(player == null)
return;
Server.sendData(player, EnumPacketClient.CLONER, x, y, z);
GuiOpenPacket.openGUI(player, EnumGuiType.Cloner, x, y, z);
}
public static void setTeleporterGUI(EntityPlayerMP player){
if(player == null)
return;
Server.sendData(player, EnumPacketClient.TELEPORTER);
PacketHandler.Instance.sendToPlayer(new GuiTeleporterPacket(), player);
}
public static void setRecipeGui(EntityPlayerMP player, RecipeCarpentry recipe){
@@ -744,14 +776,24 @@ public class NoppesUtilServer {
ContainerManageRecipes container = (ContainerManageRecipes) player.openContainer;
container.setRecipe(recipe);
Server.sendData(player, EnumPacketClient.GUI_DATA, recipe.writeNBT());
GuiDataPacket.sendGuiData((EntityPlayerMP)player, recipe.writeNBT());
}
public static void setRecipeAnvilGui(EntityPlayerMP player, RecipeAnvil recipe){
if(recipe == null)
return;
if(!(player.openContainer instanceof ContainerManageRecipes))
return;
ContainerManageRecipes container = (ContainerManageRecipes) player.openContainer;
container.setRecipe(recipe);
GuiDataPacket.sendGuiData((EntityPlayerMP)player, recipe.writeNBT());
}
public static void sendBank(EntityPlayerMP player,Bank bank) {
NBTTagCompound compound = new NBTTagCompound();
bank.writeEntityToNBT(compound);
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
GuiDataPacket.sendGuiData((EntityPlayerMP)player, compound);
if(player.openContainer instanceof ContainerManageBanks){
((ContainerManageBanks)player.openContainer).setBank(bank);
@@ -773,18 +815,18 @@ public class NoppesUtilServer {
map.put(s + " : " + npc.display.name, npc.getEntityId());
}
sendScrollData(player, map);
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendGuiError(EntityPlayer player, int i) {
Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI_ERROR, i, new NBTTagCompound());
GuiErrorPacket.errorGUI((EntityPlayerMP)player, i, new NBTTagCompound());
}
public static void sendGuiClose(EntityPlayerMP player, int i, NBTTagCompound comp) {
if(player.openContainer != player.inventoryContainer){
player.openContainer = player.inventoryContainer;
}
Server.sendData(player, EnumPacketClient.GUI_CLOSE, i, comp);
GuiClosePacket.closeGUI(player, i, comp);
}
public static Entity spawnCloneWithProtection(NBTTagCompound compound, int x, int y,
@@ -798,7 +840,7 @@ public class NoppesUtilServer {
entity.setPosition((double) x + 0.5, (double) y, (double) z + 0.5);
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.ais.startPos = new int[]{MathHelper.floor_double(npc.posX),MathHelper.floor_double(npc.posY),MathHelper.floor_double(npc.posZ)};
npc.ticksExisted = 0;
npc.totalTicksAlive = 0;
}
@@ -817,7 +859,7 @@ 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.ais.startPos = new int[]{MathHelper.floor_double(npc.posX),MathHelper.floor_double(npc.posY),MathHelper.floor_double(npc.posZ)};
npc.ticksExisted = 0;
npc.totalTicksAlive = 0;
}
@@ -826,7 +868,7 @@ public class NoppesUtilServer {
public static Entity spawnClone(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
Entity entity = NoppesUtilServer.getEntityFromNBT(compound,x,y,z,worldObj);
Entity entity = getEntityFromNBT(compound,x,y,z,worldObj);
if(entity == null){
return null;
}
@@ -845,48 +887,6 @@ public class NoppesUtilServer {
return entity;
}
}
public static void sendPlayerDataCompound(EntityPlayerMP player, NBTTagCompound compound, boolean sync) {
try {
byte[] bytes = CompressedStreamTools.compress(compound);
// Split byte array into chunks and send each chunk
int chunkSize = 16000;
int totalChunks = (int) Math.ceil((double) bytes.length / chunkSize);
for (int i = 0; i < totalChunks; i++) {
int start = i * chunkSize;
int length = Math.min(bytes.length - start, chunkSize);
byte[] chunk = new byte[length];
System.arraycopy(bytes, start, chunk, 0, length);
Server.sendData(player, EnumPacketClient.LARGE_NBT_PART, (Object) chunk);
}
// Send end packet
Server.sendData(player, EnumPacketClient.SYNC_PLAYER, sync);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void sendDBCCompound(EntityPlayerMP player, NBTTagCompound compound) {
try {
byte[] bytes = CompressedStreamTools.compress(compound);
// Split byte array into chunks and send each chunk
int chunkSize = 16000;
int totalChunks = (int) Math.ceil((double) bytes.length / chunkSize);
for (int i = 0; i < totalChunks; i++) {
int start = i * chunkSize;
int length = Math.min(bytes.length - start, chunkSize);
byte[] chunk = new byte[length];
System.arraycopy(bytes, start, chunk, 0, length);
Server.sendData(player, EnumPacketClient.LARGE_NBT_PART, (Object) chunk);
}
// Send end packet
Server.sendData(player, EnumPacketClient.DBC_FORM);
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean isOp(EntityPlayer player) {
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
@@ -991,4 +991,142 @@ public class NoppesUtilServer {
sb.append(seconds).append(" second").append(seconds == 1 ? "" : "s");
return sb.toString();
}
/**
* Retrieves the player's data from the existing PlayerDataController and sends
* a large packet to the client containing all the maps, including categories.
*/
public static void sendPlayerDataInfo(String playerName, EntityPlayerMP player) {
PlayerData playerdata;
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
if(pl == null)
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
else
playerdata = PlayerDataController.Instance.getPlayerData(pl);
// Assemble quest maps:
Map<String, Integer> questActiveMap = new HashMap<>();
Map<String, Integer> questFinishedMap = new HashMap<>();
Map<String, Integer> questCategoriesMap = new HashMap<>();
QuestController qc = QuestController.Instance;
PlayerQuestData qData = playerdata.questData;
for (Integer questId : qData.activeQuests.keySet()) {
if(!qc.quests.containsKey(questId))
continue;
Quest quest = qc.quests.get(questId);
questActiveMap.put(quest.category.title + ": " + quest.title, questId);
if (!questCategoriesMap.containsKey(quest.category.title))
questCategoriesMap.put(quest.category.title, quest.category.id);
}
for (Integer questId : qData.finishedQuests.keySet()) {
if(!qc.quests.containsKey(questId))
continue;
Quest quest = qc.quests.get(questId);
questFinishedMap.put(quest.category.title + ": " + quest.title, questId);
if (!questCategoriesMap.containsKey(quest.category.title))
questCategoriesMap.put(quest.category.title, quest.category.id);
}
// Assemble dialog maps:
Map<String, Integer> dialogReadMap = new HashMap<>();
Map<String, Integer> dialogCategoriesMap = new HashMap<>();
PlayerDialogData dData = playerdata.dialogData;
for (Integer dialogId : dData.dialogsRead) {
if(!DialogController.Instance.dialogs.containsKey(dialogId))
continue;
Dialog dialog = DialogController.Instance.dialogs.get(dialogId);
dialogReadMap.put(dialog.category.title + ": " + dialog.title, dialogId);
if (!dialogCategoriesMap.containsKey(dialog.category.title))
dialogCategoriesMap.put(dialog.category.title, dialog.category.id);
}
// Assemble transport maps:
Map<String, Integer> transportLocationsMap = new HashMap<>();
Map<String, Integer> transportCategoriesMap = new HashMap<>();
PlayerTransportData tData = playerdata.transportData;
TransportController tc = TransportController.getInstance();
for (Integer id : tData.transports) {
TransportLocation location = tc.getTransport(id);
if(location == null)
continue;
transportLocationsMap.put(location.category.title + ": " + location.name, id);
if (!transportCategoriesMap.containsKey(location.category.title))
transportCategoriesMap.put(location.category.title, location.category.id);
}
// Assemble bank map:
Map<String, Integer> bankMap = new HashMap<>();
PlayerBankData bData = playerdata.bankData;
BankController bc = BankController.getInstance();
for (Integer bankId : bData.banks.keySet()) {
if(!bc.banks.containsKey(bankId))
continue;
Bank bank = bc.banks.get(bankId);
bankMap.put(bank.name, bankId);
}
// Assemble faction map:
Map<String, Integer> factionMap = new HashMap<>();
PlayerFactionData fData = playerdata.factionData;
FactionController fc = FactionController.getInstance();
for (Integer factionId : fData.factionData.keySet()) {
if(!fc.factions.containsKey(factionId))
continue;
Faction faction = fc.factions.get(factionId);
factionMap.put(faction.name + "(" + fData.getFactionPoints(factionId) + ")", factionId);
}
// Send the full packet with categories, active/finished data, dialogs, transports, banks, and factions.
PlayerDataInfoPacket packet = new PlayerDataInfoPacket(playerName,
questCategoriesMap, questActiveMap, questFinishedMap,
dialogCategoriesMap, dialogReadMap,
transportCategoriesMap, transportLocationsMap,
bankMap, factionMap);
PacketHandler.Instance.sendToPlayer(packet, player);
}
/**
* Removes a specific data entry from the player's data.
*
* The tabType parameter is used as follows:
* 0: Quest – remove from both activeQuests and finishedQuests.
* 1: Dialog – remove from dialogsRead.
* 2: Transport – remove from transports.
* 3: Bank – remove from banks.
* 4: Factions – remove from factionData.
*
* The selectedKey is expected to be the string representation of the entry's ID.
*/
public static void removePlayerDataInfo(String playerName, int tabType, int value, EntityPlayerMP player) {
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
PlayerData playerdata;
EnumPlayerData enumPlayerData = EnumPlayerData.values()[tabType];
if(pl == null)
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
else
playerdata = PlayerDataController.Instance.getPlayerData(pl);
if(enumPlayerData == EnumPlayerData.Quest) { // Quest removal
playerdata.questData.activeQuests.remove(value);
playerdata.questData.finishedQuests.remove(value);
}
if(enumPlayerData == EnumPlayerData.Dialog){ // Dialog removal
playerdata.dialogData.dialogsRead.remove(value);
}
if(enumPlayerData == EnumPlayerData.Transport) { // Transport removal
playerdata.transportData.transports.remove(value);
}
if(enumPlayerData == EnumPlayerData.Bank) { // Bank removal
playerdata.bankData.banks.remove(value);
}
if(enumPlayerData == EnumPlayerData.Factions) { // Faction removal
playerdata.factionData.factionData.remove(value);
}
playerdata.save();
if(pl != null) {
SyncController.syncPlayer((EntityPlayerMP) pl);
}
}
}
@@ -1,338 +0,0 @@
package noppes.npcs;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import io.netty.buffer.ByteBuf;
import kamkeel.addon.DBCAddon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemEditableBook;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemWritableBook;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import noppes.npcs.blocks.tiles.TileBigSign;
import noppes.npcs.blocks.tiles.TileBook;
import noppes.npcs.constants.*;
import noppes.npcs.containers.ContainerMail;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.PlayerQuestController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.*;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleCompanion;
import java.io.IOException;
import java.util.Iterator;
import java.util.UUID;
public class PacketHandlerPlayer{
@SubscribeEvent
public void onServerPacket(ServerCustomPacketEvent event) {
EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity;
ByteBuf buffer = event.packet.payload();
try {
player(buffer, player, EnumPlayerPacket.values()[buffer.readInt()]);
} catch (IOException e) {
LogWriter.except(e);
}
}
private void player(ByteBuf buffer, EntityPlayerMP player, EnumPlayerPacket type) throws IOException {
if(type == EnumPlayerPacket.MarkData){
String uuid = Server.readString(buffer);
if(uuid == null)
return;
Entity entity = NoppesUtilServer.getEntityFromUUID(player.worldObj, UUID.fromString(uuid));
if(!(entity instanceof EntityNPCInterface))
return;
MarkData data = MarkData.get((EntityNPCInterface) entity);
}
else if(type == EnumPlayerPacket.CompanionTalentExp){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
return;
int id = buffer.readInt();
int exp = buffer.readInt();
RoleCompanion role = (RoleCompanion) npc.roleInterface;
if(exp <= 0 || !role.canAddExp(-exp) || id < 0 || id >= EnumCompanionTalent.values().length) //should never happen unless hacking
return;
EnumCompanionTalent talent = EnumCompanionTalent.values()[id];
role.addExp(-exp);
role.addTalentExp(talent, exp);
}
else if(type == EnumPlayerPacket.CompanionOpenInv){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner())
return;
NoppesUtilServer.sendOpenGui(player, EnumGuiType.CompanionInv, npc);
}
else if(type == EnumPlayerPacket.KeyPressed) {
if(ScriptController.Instance.languages.isEmpty()) {
return;
}
int button = buffer.readInt();
boolean isCtrlPressed = buffer.readBoolean();
boolean isShiftPressed = buffer.readBoolean();
boolean isAltPressed = buffer.readBoolean();
boolean isMetaPressed = buffer.readBoolean();
boolean buttonDown = buffer.readBoolean();
String ints = Server.readString(buffer);
String[] split = ints.split(",");
int[] keysDown;
if(ints.length() > 0) {
keysDown = new int[split.length];
try {
for (int i = 0; i < split.length; i++) {
keysDown[i] = Integer.parseInt(split[i]);
}
}
catch (NumberFormatException ignored){
}
} else {
keysDown = new int[0];
}
EventHooks.onPlayerKeyPressed(player, button, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, buttonDown, keysDown);
}
else if(type == EnumPlayerPacket.MouseClicked) {
if(ScriptController.Instance.languages.isEmpty()) {
return;
}
int button = buffer.readInt();
int mouseWheel = buffer.readInt();
boolean buttonDown = buffer.readBoolean();
boolean isCtrlPressed = buffer.readBoolean();
boolean isShiftPressed = buffer.readBoolean();
boolean isAltPressed = buffer.readBoolean();
boolean isMetaPressed = buffer.readBoolean();
String ints = Server.readString(buffer);
String[] split = ints.split(",");
int[] keysDown;
if(ints.length() > 0) {
keysDown = new int[split.length];
try {
for (int i = 0; i < split.length; i++) {
keysDown[i] = Integer.parseInt(split[i]);
}
}
catch (NumberFormatException ignored){
}
} else {
keysDown = new int[0];
}
EventHooks.onPlayerMouseClicked(player, button, mouseWheel, buttonDown, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keysDown);
}
else if(type == EnumPlayerPacket.FollowerHire){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Follower)
return;
NoppesUtilPlayer.hireFollower(player, npc);
}
else if(type == EnumPlayerPacket.FollowerExtend){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Follower)
return;
NoppesUtilPlayer.extendFollower(player, npc);
Server.sendData(player, EnumPacketClient.GUI_DATA, npc.roleInterface.writeToNBT(new NBTTagCompound()));
}
else if(type == EnumPlayerPacket.FollowerState){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Follower)
return;
NoppesUtilPlayer.changeFollowerState(player,npc);
Server.sendData(player, EnumPacketClient.GUI_DATA, npc.roleInterface.writeToNBT(new NBTTagCompound()));
}
else if(type == EnumPlayerPacket.RoleGet){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role == EnumRoleType.None)
return;
Server.sendData(player, EnumPacketClient.GUI_DATA, npc.roleInterface.writeToNBT(new NBTTagCompound()));
}
else if(type == EnumPlayerPacket.Transport){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Transporter)
return;
NoppesUtilPlayer.transport(player, npc, Server.readString(buffer));
}
else if(type == EnumPlayerPacket.BankUpgrade){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
return;
NoppesUtilPlayer.bankUpgrade(player, npc);
}
else if(type == EnumPlayerPacket.BankUnlock){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
return;
NoppesUtilPlayer.bankUnlock(player, npc);
}
else if(type == EnumPlayerPacket.BankSlotOpen){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null || npc.advanced.role != EnumRoleType.Bank)
return;
int slot = buffer.readInt();
int bankId = buffer.readInt();
BankData data = PlayerDataController.Instance.getBankData(player,bankId).getBankOrDefault(bankId);
data.openBankGui(player, npc, bankId, slot);
}
else if(type == EnumPlayerPacket.Dialog){
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if(npc == null)
return;
NoppesUtilPlayer.dialogSelected(buffer.readInt(), buffer.readInt(), player, npc);
}
else if(type == EnumPlayerPacket.CheckQuestCompletion){
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
PlayerQuestData questData = PlayerDataController.Instance.getPlayerData(player).questData;
Party playerParty = playerData.getPlayerParty();
if(playerParty != null)
PartyController.Instance().checkQuestCompletion(playerParty, null);
questData.checkQuestCompletion(playerData, null);
}
else if(type == EnumPlayerPacket.QuestLog){
NoppesUtilPlayer.sendQuestLogData(player);
}
else if(type == EnumPlayerPacket.TrackedQuest){
NoppesUtilPlayer.sendTrackedQuest(player);
}
else if(type == EnumPlayerPacket.FactionsGet){
PlayerFactionData data = PlayerDataController.Instance.getPlayerData(player).factionData;
Server.sendData(player, EnumPacketClient.GUI_DATA, data.getPlayerGuiData());
}
else if(type == EnumPlayerPacket.MailGet){
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Server.sendData(player, EnumPacketClient.GUI_DATA, data.saveNBTData(new NBTTagCompound()));
}
else if(type == EnumPlayerPacket.MailDelete){
long time = buffer.readLong();
String username = Server.readString(buffer);
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Iterator<PlayerMail> it = data.playermail.iterator();
while(it.hasNext()){
PlayerMail mail = it.next();
if(mail.time == time && mail.sender.equals(username)){
it.remove();
}
}
Server.sendData(player, EnumPacketClient.GUI_DATA, data.saveNBTData(new NBTTagCompound()));
}
else if(type == EnumPlayerPacket.MailSend){
if(!(player.openContainer instanceof ContainerMail))
return;
String username = PlayerDataController.Instance.hasPlayer(Server.readString(buffer));
if(username.isEmpty()){
NoppesUtilServer.sendGuiError(player, 0);
return;
}
PlayerMail mail = new PlayerMail();
//String s = player.func_145748_c_().getFormattedText();
String s = player.getDisplayName();
if(!s.equals(player.getCommandSenderName()))
s += "(" + player.getCommandSenderName() + ")";
mail.readNBT(Server.readNBT(buffer));
mail.sender = s;
mail.items = ((ContainerMail)player.openContainer).mail.items;
if(mail.subject.isEmpty()){
NoppesUtilServer.sendGuiError(player, 1);
return;
}
PlayerDataController.Instance.addPlayerMessage(username, mail);
NBTTagCompound comp = new NBTTagCompound();
comp.setString("username", username);
NoppesUtilServer.sendGuiClose(player, 1,comp);
}
else if(type == EnumPlayerPacket.MailboxOpenMail){
long time = buffer.readLong();
String username = Server.readString(buffer);
player.closeContainer();
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Iterator<PlayerMail> it = data.playermail.iterator();
while(it.hasNext()){
PlayerMail mail = it.next();
if(mail.time == time && mail.sender.equals(username)){
ContainerMail.staticmail = mail;
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerMailman.ordinal(), player.worldObj, 0, 0, 0);
break;
}
}
}
else if(type == EnumPlayerPacket.MailRead){
long time = buffer.readLong();
String username = Server.readString(buffer);
PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData;
Iterator<PlayerMail> it = data.playermail.iterator();
while(it.hasNext()){
PlayerMail mail = it.next();
if(mail.time == time && mail.sender.equals(username)){
mail.beenRead = true;
if(mail.hasQuest())
PlayerQuestController.addActiveQuest(new QuestData(mail.getQuest()), player);
}
}
}
else if(type == EnumPlayerPacket.SignSave) {
int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
if (player.worldObj.blockExists(x, y, z)) {
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
if(!(tile instanceof TileBigSign))
return;
TileBigSign sign = (TileBigSign) tile;
if (sign.canEdit) {
sign.setText(Server.readString(buffer));
sign.canEdit = false;
player.worldObj.markBlockForUpdate(x, y, z);
}
}
}
else if(type == EnumPlayerPacket.SaveBook) {
int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
if (player.worldObj.blockExists(x, y, z)) {
TileEntity tileentity = player.worldObj.getTileEntity(x, y, z);
if (!(tileentity instanceof TileBook))
return;
TileBook tile = (TileBook) tileentity;
if (tile.book.getItem() == Items.written_book)
return;
boolean sign = buffer.readBoolean();
ItemStack book = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer));
if (book == null)
return;
if (book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())) {
tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
}
if (book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())) {
tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName()));
tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title")));
tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
tile.book.func_150996_a(Items.written_book);
}
}
}
else if(type == EnumPlayerPacket.ScreenSize){
int width = buffer.readInt(), height = buffer.readInt();
PlayerDataController.Instance.getPlayerData(player).screenSize.setSize(width,height);
}
}
}
File diff suppressed because it is too large. Load diff
@@ -9,17 +9,14 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import net.minecraftforge.event.entity.player.*;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.items.ItemScripted;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.ItemEvent;
@@ -40,15 +37,15 @@ public class ScriptItemEventHandler {
for (HashMap<Integer, ItemStack> inventory : inventories) {
for (ItemStack stack : inventory.values()) {
if (stack != null && stack.getItem() == CustomItems.scripted_item) {
if (stack != null && NoppesUtilServer.isScriptableItem(stack.getItem())) {
IItemStack istack = NpcAPI.Instance().getIItemStack(stack);
EventHooks.onScriptItemUpdate((IItemCustom) istack, event.entityLiving);
EventHooks.onScriptItemUpdate((IItemCustomizable) istack, event.entityLiving);
}
}
}
} else if(event.entityLiving.getHeldItem() != null && event.entityLiving.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
} else if(event.entityLiving.getHeldItem() != null && NoppesUtilServer.isScriptableItem(event.entityLiving.getHeldItem().getItem()) && !event.isCanceled()) {
IItemStack itemStack = NpcAPI.Instance().getIItemStack(event.entityLiving.getHeldItem());
EventHooks.onScriptItemUpdate((IItemCustom) itemStack, event.entityLiving);
EventHooks.onScriptItemUpdate((IItemCustomizable) itemStack, event.entityLiving);
}
}
@@ -59,9 +56,10 @@ public class ScriptItemEventHandler {
if(event.player.worldObj instanceof WorldServer) {
try {
if (event.entityItem.getEntityItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.entityItem.getEntityItem());
event.setCanceled(EventHooks.onScriptItemTossed(isw, event.player, event.entityItem));
if (NoppesUtilServer.isScriptableItem(event.entityItem.getEntityItem().getItem()) && !event.isCanceled()) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.entityItem.getEntityItem());
if(isw instanceof IItemCustomizable)
event.setCanceled(EventHooks.onScriptItemTossed((IItemCustomizable) isw, event.player, event.entityItem));
}
} catch (Exception e) {}
}
@@ -74,9 +72,10 @@ public class ScriptItemEventHandler {
if(event.player.worldObj instanceof WorldServer) {
try {
if (event.player.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.player.getHeldItem());
EventHooks.onScriptItemPickedUp(isw, event.player);
if (NoppesUtilServer.isScriptableItem(event.player.getHeldItem().getItem()) && !event.isCanceled()) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.player.getHeldItem());
if(isw instanceof IItemCustomizable)
EventHooks.onScriptItemPickedUp((IItemCustomizable) isw, event.player);
}
} catch(Exception e) {}
}
@@ -89,8 +88,13 @@ public class ScriptItemEventHandler {
ItemStack stack = entity.getEntityItem();
try {
if (stack.stackSize > 0 && stack.getItem() == CustomItems.scripted_item && EventHooks.onScriptItemSpawn(ItemScripted.GetWrapper(stack), entity)) {
event.setCanceled(true);
if (stack.stackSize > 0 && NoppesUtilServer.isScriptableItem(stack.getItem())) {
IItemStack isw = NpcAPI.Instance().getIItemStack(stack);
if(isw instanceof IItemCustomizable){
if(EventHooks.onScriptItemSpawn((IItemCustomizable) isw, entity)){
event.setCanceled(true);
}
}
}
} catch(Exception e) {}
}
@@ -103,13 +107,15 @@ public class ScriptItemEventHandler {
if(!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) {
try {
if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem());
ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIEntity(event.target));
event.setCanceled(EventHooks.onScriptItemInteract(isw, eve));
if (NoppesUtilServer.isScriptableItem(event.entityPlayer.getHeldItem().getItem()) && !event.isCanceled()) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.entityPlayer.getHeldItem());
if(isw instanceof IItemCustomizable){
ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent((IItemCustomizable) isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIEntity(event.target));
event.setCanceled(EventHooks.onScriptItemInteract((IItemCustomizable) isw, eve));
ItemEvent.RightClickEvent rightClickEvent = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 1, NpcAPI.Instance().getIEntity(event.target));
event.setCanceled(EventHooks.onScriptItemRightClick(isw, rightClickEvent));
ItemEvent.RightClickEvent rightClickEvent = new ItemEvent.RightClickEvent((IItemCustomizable) isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 1, NpcAPI.Instance().getIEntity(event.target));
event.setCanceled(EventHooks.onScriptItemRightClick((IItemCustomizable) isw, rightClickEvent));
}
}
} catch(Exception e) {}
}
@@ -134,10 +140,12 @@ public class ScriptItemEventHandler {
return;
}
try {
if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem());
ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 0, null);
event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve));
if (NoppesUtilServer.isScriptableItem(event.entityPlayer.getHeldItem().getItem()) && !event.isCanceled()) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.entityPlayer.getHeldItem());
if(isw instanceof IItemCustomizable){
ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent((IItemCustomizable) isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 0, null);
event.setCanceled(EventHooks.onScriptItemRightClick((IItemCustomizable) isw, eve));
}
}
} catch(Exception e) {}
}
@@ -148,10 +156,12 @@ public class ScriptItemEventHandler {
handler.hadInteract = true;
try {
if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem());
ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock((IWorld) NpcAPI.Instance().getIWorld(event.world), event.x, event.y, event.z));
event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve));
if (NoppesUtilServer.isScriptableItem(event.entityPlayer.getHeldItem().getItem()) && !event.isCanceled()) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.entityPlayer.getHeldItem());
if(isw instanceof IItemCustomizable){
ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent((IItemCustomizable) isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock((IWorld) NpcAPI.Instance().getIWorld(event.world), event.x, event.y, event.z));
event.setCanceled(EventHooks.onScriptItemRightClick((IItemCustomizable) isw, eve));
}
}
} catch(Exception e) {}
}
@@ -164,9 +174,12 @@ public class ScriptItemEventHandler {
return;
if(event.entityPlayer.worldObj instanceof WorldServer) {
IItemCustom handler = ItemScripted.GetWrapper(event.item);
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
event.setCanceled(EventHooks.onStartUsingCustomItem(handler, IPlayer, event.duration));
IItemStack isw = NpcAPI.Instance().getIItemStack(event.item);
if(isw instanceof IItemCustomizable){
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
event.setCanceled(EventHooks.onStartUsingCustomItem((IItemCustomizable) isw, IPlayer, event.duration));
}
}
}
@SubscribeEvent
@@ -174,10 +187,13 @@ public class ScriptItemEventHandler {
if(event.entityPlayer == null || event.entityPlayer.worldObj == null)
return;
if(event.entityPlayer.worldObj instanceof WorldServer && event.item.getItem() == CustomItems.scripted_item) {
IItemCustom handler = ItemScripted.GetWrapper(event.item);
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
event.setCanceled(EventHooks.onUsingCustomItem(handler, IPlayer, event.duration));
if(event.entityPlayer.worldObj instanceof WorldServer && NoppesUtilServer.isScriptableItem(event.item.getItem())) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.item);
if(isw instanceof IItemCustomizable){
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
event.setCanceled(EventHooks.onUsingCustomItem((IItemCustomizable) isw, IPlayer, event.duration));
}
}
}
@SubscribeEvent
@@ -185,10 +201,12 @@ public class ScriptItemEventHandler {
if(event.entityPlayer == null || event.entityPlayer.worldObj == null)
return;
if(event.entityPlayer.worldObj instanceof WorldServer && event.item.getItem() == CustomItems.scripted_item) {
IItemCustom handler = ItemScripted.GetWrapper(event.item);
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
event.setCanceled(EventHooks.onStopUsingCustomItem(handler, IPlayer, event.duration));
if(event.entityPlayer.worldObj instanceof WorldServer && NoppesUtilServer.isScriptableItem(event.item.getItem())) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.item);
if(isw instanceof IItemCustomizable){
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
event.setCanceled(EventHooks.onStopUsingCustomItem((IItemCustomizable) isw, IPlayer, event.duration));
}
}
}
@SubscribeEvent
@@ -196,10 +214,32 @@ public class ScriptItemEventHandler {
if(event.entityPlayer == null || event.entityPlayer.worldObj == null)
return;
if(event.entityPlayer.worldObj instanceof WorldServer && event.item.getItem() == CustomItems.scripted_item) {
IItemCustom handler = ItemScripted.GetWrapper(event.item);
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
EventHooks.onFinishUsingCustomItem(handler, IPlayer, event.duration);
if(event.entityPlayer.worldObj instanceof WorldServer && NoppesUtilServer.isScriptableItem(event.item.getItem())) {
IItemStack isw = NpcAPI.Instance().getIItemStack(event.item);
if(isw instanceof IItemCustomizable){
IPlayer IPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
EventHooks.onFinishUsingCustomItem((IItemCustomizable) isw, IPlayer, event.duration);
}
}
}
@SubscribeEvent
public void invoke(AnvilRepairEvent repairEvent) {
IItemStack output = NpcAPI.Instance().getIItemStack(repairEvent.output);
if (output instanceof IItemCustomizable) {
IPlayer player = (IPlayer) NpcAPI.Instance().getIEntity(repairEvent.entityPlayer);
IItemStack left = NpcAPI.Instance().getIItemStack(repairEvent.left);
IItemStack right = NpcAPI.Instance().getIItemStack(repairEvent.right);
float breakChance = repairEvent.breakChance;
EventHooks.onRepairCustomItem((IItemCustomizable) output, player, left, right, breakChance);
}
}
@SubscribeEvent
public void invoke(PlayerDestroyItemEvent destroyItemEvent) {
IItemStack itemStack = NpcAPI.Instance().getIItemStack(destroyItemEvent.original);
if (itemStack instanceof IItemCustomizable) {
IPlayer player = (IPlayer) NpcAPI.Instance().getIEntity(destroyItemEvent.entityPlayer);
EventHooks.onBreakCustomItem((IItemCustomizable) itemStack, player);
}
}
}
@@ -5,7 +5,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import kamkeel.controllers.ProfileController;
import kamkeel.npcs.controllers.SyncController;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -22,17 +22,20 @@ import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.event.world.BlockEvent;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.api.item.IItemCustomizable;
import kamkeel.npcs.controllers.AttributeController;
import kamkeel.npcs.util.AttributeAttackUtil;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.*;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.items.ItemNpcTool;
import noppes.npcs.quests.QuestItem;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptCustomItem;
import static noppes.npcs.config.ConfigMain.TrackedQuestUpdateFrequency;
@@ -47,25 +50,28 @@ public class ScriptPlayerEventHandler {
if (event.side == Side.SERVER && event.phase == TickEvent.Phase.START) {
EntityPlayer player = event.player;
if (player.ticksExisted%10 == 0) {
if (player.ticksExisted % 10 == 0) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
EventHooks.onPlayerTick(handler, scriptPlayer);
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
ItemStack item = player.inventory.getStackInSlot(i);
if(item != null && item.getItem() == CustomItems.scripted_item){
ScriptCustomItem isw = (ScriptCustomItem) NpcAPI.Instance().getIItemStack(item);
if(item != null && NoppesUtilServer.isScriptableItem(item.getItem())){
IItemCustomizable isw = (IItemCustomizable) NpcAPI.Instance().getIItemStack(item);
EventHooks.onScriptItemUpdate(isw, player);
}
}
if(ConfigMain.AttributesEnabled)
AttributeController.getTracker(player).updateIfChanged(player);
}
if (PlayerDataController.Instance != null) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if(playerData.updateClient) {
NoppesUtilServer.sendPlayerDataCompound((EntityPlayerMP)player, playerData.getSyncNBT(), true);
SyncController.syncPlayerData((EntityPlayerMP)player, true);
playerData.updateClient = false;
}
@@ -73,6 +79,16 @@ public class ScriptPlayerEventHandler {
playerData.timers.update();
}
if(player.ticksExisted % 10 == 0)
SyncController.syncEffects((EntityPlayerMP) player);
// TODO: Fix Config
// player.ticksExisted % ConfigDBCGameplay.CheckEffectsTick == 0
if (player.ticksExisted % 10 == 0)
CustomEffectController.Instance.runEffects(player);
if (player.ticksExisted % 20 == 0)
CustomEffectController.Instance.decrementEffects(player);
Party party = playerData.getPlayerParty();
boolean trackingPartyQuest = playerData.questData.getTrackedQuest() != null && party != null && party.getQuest() != null && party.getQuest().getId() == playerData.questData.getTrackedQuest().getId();
@@ -145,6 +161,11 @@ public class ScriptPlayerEventHandler {
if(event.getPlayer() == null || event.getPlayer().worldObj == null)
return;
if(event.getPlayer().getHeldItem() != null && event.getPlayer().getHeldItem().getItem() instanceof ItemNpcTool){
event.setCanceled(true);
return;
}
if(!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.getPlayer());
@@ -424,6 +445,8 @@ public class ScriptPlayerEventHandler {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
if(event.entityLiving instanceof EntityPlayer) {
try {
CustomEffectController.getInstance().killEffects((EntityPlayer) event.entityLiving);
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityLiving);
EventHooks.onPlayerDeath(handler,scriptPlayer, event.source, source);
} catch (Exception ignored) {}
@@ -452,7 +475,11 @@ public class ScriptPlayerEventHandler {
}
if(event.source.getEntity() instanceof EntityPlayer) {
noppes.npcs.scripted.event.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.AttackEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.source.getEntity()), event.entityLiving, event.ammount, event.source);
float attackAmount = event.ammount;
if(ConfigMain.AttributesEnabled)
attackAmount = AttributeAttackUtil.calculateOutgoing((EntityPlayer) event.source.getEntity(), event.ammount);
noppes.npcs.scripted.event.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.AttackEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.source.getEntity()), event.entityLiving, attackAmount, event.source);
cancel = cancel || EventHooks.onPlayerAttack(handler, pevent1);
}
event.setCanceled(cancel);
@@ -468,6 +495,16 @@ public class ScriptPlayerEventHandler {
boolean cancel = event.isCanceled();
Entity source = NoppesUtilServer.GetDamageSource(event.source);
PlayerDataScript handler = ScriptController.Instance.playerScripts;
// Player to Player Interaction
if(ConfigMain.AttributesEnabled){
if(event.entityLiving instanceof EntityPlayer && source instanceof EntityPlayer){
event.ammount = AttributeAttackUtil.calculateDamagePlayer((EntityPlayer) event.entityLiving, (EntityPlayer) source, event.ammount);
} else if (!(event.entityLiving instanceof EntityNPCInterface) && source instanceof EntityPlayer){
event.ammount = AttributeAttackUtil.calculateOutgoing((EntityPlayer) source, event.ammount);
}
}
if(event.entityLiving instanceof EntityPlayer) {
noppes.npcs.scripted.event.PlayerEvent.DamagedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.DamagedEvent((IPlayer)NpcAPI.Instance().getIEntity((EntityPlayer)event.entityLiving), source, event.ammount, event.source);
cancel = EventHooks.onPlayerDamaged(handler, pevent);
+5 -84
View File
@@ -1,18 +1,10 @@
package noppes.npcs;
import com.google.common.base.Charsets;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.village.MerchantRecipeList;
import noppes.npcs.constants.EnumPacketClient;
import java.io.IOException;
import java.util.Arrays;
@@ -20,47 +12,6 @@ import java.util.List;
import java.util.Map;
public class Server {
public static void sendData(final EntityPlayerMP player, final EnumPacketClient enu, final Object... obs) {
sendDataChecked(player, enu, obs);
}
public static boolean sendDataChecked(EntityPlayerMP player, EnumPacketClient type, Object... obs) {
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
try {
if(!fillBuffer(buffer, type, obs))
return false;
CustomNpcs.Channel.sendTo(new FMLProxyPacket(buffer, "CustomNPCs"), player);
} catch (IOException e) {
LogWriter.error(type + " Errored", e);
}
return true;
}
public static void sendAssociatedData(final Entity entity, final EnumPacketClient enu, final Object... obs) {
ByteBuf buffer = Unpooled.buffer();
try {
if(!fillBuffer(buffer, enu, obs))
return;
TargetPoint point = new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 60);
CustomNpcs.Channel.sendToAllAround(new FMLProxyPacket(buffer,"CustomNPCs"), point);
} catch (IOException e) {
e.printStackTrace();
LogWriter.error(enu + " Errored", e);
}
}
public static void sendToAll(EnumPacketClient enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
try {
if(!fillBuffer(buffer, enu, obs))
return;
CustomNpcs.Channel.sendToAll(new FMLProxyPacket(buffer,"CustomNPCs"));
} catch (IOException e) {
e.printStackTrace();
LogWriter.error(enu + " Errored", e);
}
}
public static boolean fillBuffer(ByteBuf buffer, Enum enu, Object... obs) throws IOException{
buffer.writeInt(enu.ordinal());
for(Object ob : obs){
@@ -73,7 +24,7 @@ public class Server {
for(String key : map.keySet()){
int value = map.get(key);
buffer.writeInt(value);
writeString(buffer, key);
ByteBufUtils.writeString(buffer, key);
}
}
else if(ob instanceof MerchantRecipeList)
@@ -82,7 +33,7 @@ public class Server {
List<String> list = (List<String>) ob;
buffer.writeInt(list.size());
for(String s : list)
writeString(buffer, s);
ByteBufUtils.writeString(buffer, s);
}
else if(ob instanceof Enum)
buffer.writeInt(((Enum<?>) ob).ordinal());
@@ -91,7 +42,7 @@ public class Server {
else if(ob instanceof Boolean)
buffer.writeBoolean((Boolean) ob);
else if(ob instanceof String)
writeString(buffer, (String) ob);
ByteBufUtils.writeString(buffer, (String) ob);
else if(ob instanceof Float)
buffer.writeFloat((Float) ob);
else if(ob instanceof Long)
@@ -105,7 +56,7 @@ public class Server {
buffer.writeBytes(byteArray);
}
else if(ob instanceof NBTTagCompound)
writeNBT(buffer, (NBTTagCompound) ob);
ByteBufUtils.writeNBT(buffer, (NBTTagCompound) ob);
}
if(buffer.array().length >= 32767){
LogWriter.error("Packet " + enu + " was too big to be send");
@@ -114,34 +65,4 @@ public class Server {
}
return true;
}
public static void writeNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException {
byte[] bytes = CompressedStreamTools.compress(compound);
buffer.writeShort((short)bytes.length);
buffer.writeBytes(bytes);
}
public static NBTTagCompound readNBT(ByteBuf buffer) throws IOException {
byte[] bytes = new byte[buffer.readShort()];
buffer.readBytes(bytes);
return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L));
}
public static void writeString(ByteBuf buffer, String s){
byte[] bytes = s.getBytes(Charsets.UTF_8);
buffer.writeShort((short)bytes.length);
buffer.writeBytes(bytes);
}
public static String readString(ByteBuf buffer){
try{
byte[] bytes = new byte[buffer.readShort()];
buffer.readBytes(bytes);
return new String(bytes, Charsets.UTF_8);
}
catch(IndexOutOfBoundsException ex){
return null;
}
}
}
@@ -3,6 +3,17 @@ package noppes.npcs;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumSoundOperation;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.packets.data.ClonerPacket;
import kamkeel.npcs.network.packets.data.MarkDataPacket;
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
import kamkeel.npcs.network.packets.data.VillagerListPacket;
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
import kamkeel.npcs.network.packets.data.large.SyncPacket;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@@ -11,41 +22,38 @@ import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import noppes.npcs.blocks.tiles.TileBanner;
import noppes.npcs.blocks.tiles.ITileIcon;
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.*;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPartyObjectives;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.controllers.PartyController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.controllers.data.*;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.items.ItemExcalibur;
import noppes.npcs.items.ItemShield;
import noppes.npcs.items.ItemSoulstoneEmpty;
import noppes.npcs.quests.QuestItem;
import noppes.npcs.quests.QuestKill;
import noppes.npcs.roles.RoleFollower;
@@ -95,8 +103,7 @@ public class ServerEventsHandler {
return;
PlayerData data = PlayerDataController.Instance.getPlayerData(event.entityPlayer);
ServerCloneController.Instance.cleanTags(compound);
if(!Server.sendDataChecked((EntityPlayerMP)event.entityPlayer, EnumPacketClient.CLONE, compound))
event.entityPlayer.addChatMessage(new ChatComponentText("Entity too big to clone"));
PacketHandler.Instance.sendToPlayer(new ClonerPacket(compound), (EntityPlayerMP)event.entityPlayer);
data.cloned = compound;
if (event.target instanceof EntityNPCInterface) {
NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface) event.target);
@@ -108,8 +115,8 @@ public class ServerEventsHandler {
return;
NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface)event.target);
event.setCanceled(true);
Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.GUI, EnumGuiType.Script.ordinal());
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
GuiOpenPacket.openGUI((EntityPlayerMP)event.entityPlayer, EnumGuiType.Script, 0, 0, 0);
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "SCRIPTER", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface)(event.target)).display.getName(), (int)(event.target).posX, (int)(event.target).posY, (int)(event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName()));
}
}
@@ -134,7 +141,7 @@ public class ServerEventsHandler {
if (merchantrecipelist != null)
{
Server.sendData(player, EnumPacketClient.VILLAGER_LIST, merchantrecipelist);
PacketHandler.Instance.sendToPlayer(new VillagerListPacket(merchantrecipelist), player);
}
}
}
@@ -194,48 +201,20 @@ public class ServerEventsHandler {
}
if(block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
int i = 0;
for(RecipeCarpentry recipe : controller.globalRecipes.values()){
list.appendTag(recipe.writeNBT());
i++;
if(i % 10 == 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
list = new NBTTagList();
}
}
if(i % 10 != 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
}
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_WORKBENCH);
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
SyncController.workbenchNBT()
), (EntityPlayerMP) player);
}
if(block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote){
RecipeController controller = RecipeController.Instance;
NBTTagList list = new NBTTagList();
int i = 0;
for(RecipeCarpentry recipe : controller.anvilRecipes.values()){
list.appendTag(recipe.writeNBT());
i++;
if(i % 10 == 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
list = new NBTTagList();
}
}
if(i % 10 != 0){
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("recipes", list);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_ADD, compound);
}
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNCRECIPES_CARPENTRYBENCH);
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
SyncController.carpentryNBT()
), (EntityPlayerMP) player);
}
if((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK){
ItemStack item = player.inventory.getCurrentItem();
@@ -245,10 +224,10 @@ public class ServerEventsHandler {
int meta = player.worldObj.getBlockMetadata(event.x, event.y, event.z);
if(meta >= 7)
y--;
TileBanner tile = (TileBanner)player.worldObj.getTileEntity(event.x, y, event.z);
ITileIcon tile = (ITileIcon)player.worldObj.getTileEntity(event.x, y, event.z);
if(!tile.canEdit()){
if(item.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)){
tile.time = System.currentTimeMillis();
tile.setTime(System.currentTimeMillis());
if(player.worldObj.isRemote)
player.addChatComponentMessage(new ChatComponentTranslation("availability.editIcon"));
}
@@ -256,20 +235,7 @@ public class ServerEventsHandler {
}
if(!player.worldObj.isRemote){
if(block == CustomItems.banner || block == CustomItems.wallBanner){
// If sneaking and using shear
if(player.isSneaking() && item.getItem() == Items.shears){
int currentVariantIndex = tile.variant.ordinal();
int nextVariantIndex = (currentVariantIndex + 1) % EnumBannerVariant.values().length;
tile.variant = EnumBannerVariant.values()[nextVariantIndex];
player.worldObj.markBlockForUpdate(event.x, y, event.z);
event.setCanceled(true);
return;
}
}
tile.icon = item.copy();
tile.setIcon(item.copy());
player.worldObj.markBlockForUpdate(event.x, y, event.z);
event.setCanceled(true);
}
@@ -327,7 +293,7 @@ public class ServerEventsHandler {
ItemStack item = player.getCurrentEquippedItem();
if(item == null || item.getItem() != CustomItems.excalibur)
return;
Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_MUSIC, "customnpcs:songs.excalibur");
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.PLAY_MUSIC, "customnpcs:songs.excalibur"), (EntityPlayerMP)player);
player.addChatMessage(new ChatComponentTranslation("<" + StatCollector.translateToLocal(item.getItem().getUnlocalizedName() + ".name") + "> " + ItemExcalibur.quotes[player.getRNG().nextInt(ItemExcalibur.quotes.length)]));
}
@@ -504,12 +470,33 @@ public class ServerEventsHandler {
@SubscribeEvent
public void playerTracking(PlayerEvent.StartTracking event){
if(!(event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote)
if(!(event.target instanceof EntityPlayerMP || event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote)
return;
MarkData data = MarkData.get((EntityNPCInterface) event.target);
if(data.marks.isEmpty())
return;
Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT());
AnimationData animationData = AnimationData.getData(event.target);
if (animationData != null && animationData.isClientAnimating()) {
AnimationData playerAnimData = AnimationData.getData(event.entityPlayer);
if (playerAnimData != null) {
Animation currentAnimation = animationData.currentClientAnimation;
NBTTagCompound compound = currentAnimation.writeToNBT();
playerAnimData.viewAnimation(currentAnimation, animationData, compound,
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
}
}
if (event.target instanceof EntityNPCInterface) {
MarkData data = MarkData.get((EntityNPCInterface) event.target);
if (data.marks.isEmpty())
return;
PacketHandler.Instance.sendToPlayer(new MarkDataPacket(event.target.getEntityId(), data.getNBT()), (EntityPlayerMP)event.entityPlayer);
}
}
@SubscribeEvent
public void entityTick(LivingEvent.LivingUpdateEvent event) {
AnimationData data = AnimationData.getData(event.entityLiving);
if (data != null) {
data.increaseTime();
}
}
}
@@ -4,13 +4,13 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import kamkeel.controllers.ProfileController;
import kamkeel.npcs.controllers.ProfileController;
import kamkeel.npcs.controllers.SyncController;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import noppes.npcs.client.AnalyticsTracking;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.PlayerData;
import java.net.InetAddress;
@@ -53,7 +53,8 @@ public class ServerTickHandler {
}
SyncController.syncPlayer(player);
ProfileController.login(player);
SyncController.syncEffects(player);
ProfileController.Instance.login(player);
}
@SubscribeEvent
@@ -46,7 +46,7 @@ public class VersionCompatibility {
}
if(npc.npcVersion < 12){
CompatabilityFix(compound, npc.advanced.writeToNBT(new NBTTagCompound()));
CompatabilityFix(compound, npc.ai.writeToNBT(new NBTTagCompound()));
CompatabilityFix(compound, npc.ais.writeToNBT(new NBTTagCompound()));
CompatabilityFix(compound, npc.stats.writeToNBT(new NBTTagCompound()));
CompatabilityFix(compound, npc.display.writeToNBT(new NBTTagCompound()));
CompatabilityFix(compound, npc.inventory.writeEntityToNBT(new NBTTagCompound()));
@@ -101,7 +101,7 @@ public class VersionCompatibility {
int z = ((NBTTagInt) list.removeTag(2)).func_150287_d();
int y = ((NBTTagInt) list.removeTag(1)).func_150287_d();
int x = ((NBTTagInt) list.removeTag(0)).func_150287_d();
compound.setIntArray("StartPosNew", new int[]{x,y,z});
}
}
@@ -112,7 +112,7 @@ public class VersionCompatibility {
bo = comp.getBoolean("HealthRegen");
comp.setInteger("HealthRegen", bo?1:0);
compound.setTag("TransformStats", comp);
}
npc.npcVersion = ModRev;
}
@@ -200,7 +200,7 @@ public class VersionCompatibility {
if(compatibilty.getVersion() == ModRev)
return;
CompatabilityFix(compound, compatibilty.writeToNBT(new NBTTagCompound()));
compatibilty.setVersion(ModRev);
}
private static void CompatabilityFix(NBTTagCompound compound,
@@ -1,6 +1,6 @@
package noppes.npcs.ai;
import kamkeel.addon.DBCAddon;
import kamkeel.npcs.addon.DBCAddon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -80,7 +80,7 @@ public class EntityAIAmbushTarget extends EntityAIBase
{
boolean shouldHide = this.targetEntity.getDistanceSqToEntity(this.theEntity) > this.distance;
boolean isSeen = this.theEntity.canSee(targetEntity);
return (!this.theEntity.getNavigator().noPath() && shouldHide) || (!isSeen && (shouldHide || this.theEntity.ai.directLOS));
return (!this.theEntity.getNavigator().noPath() && shouldHide) || (!isSeen && (shouldHide || this.theEntity.ais.directLOS));
}
/**
@@ -90,7 +90,7 @@ public class EntityAIAmbushTarget extends EntityAIBase
{
this.theEntity.getNavigator().tryMoveToXYZ(this.shelterX, this.shelterY, this.shelterZ, this.movementSpeed);
}
/**
* Resets the task
*/
@@ -114,9 +114,9 @@ public class EntityAIAmbushTarget extends EntityAIBase
{
this.theEntity.getLookHelper().setLookPositionWithEntity(targetEntity, 30.0F, 30.0F);
}
private Vec3 findHidingSpot()
{
{
Random random = this.theEntity.getRNG();
Vec3 idealPos = null;
@@ -131,7 +131,7 @@ public class EntityAIAmbushTarget extends EntityAIBase
double j = MathHelper.floor_double(this.theEntity.posX + x) + 0.5D;
double k = MathHelper.floor_double(this.theEntity.boundingBox.minY + y);
double l = MathHelper.floor_double(this.theEntity.posZ + z) + 0.5D;
if (this.theWorld.getBlock((int)j, (int)k, (int)l).isOpaqueCube() && !this.theWorld.getBlock((int)j, (int)k + 1, (int)l).isOpaqueCube() && !this.theWorld.getBlock((int)j, (int)k + 2, (int)l).isOpaqueCube())
{
Vec3 vec1 = Vec3.createVectorHelper(this.targetEntity.posX, this.targetEntity.posY + (double)this.targetEntity.getEyeHeight(), this.targetEntity.posZ);
@@ -148,7 +148,7 @@ public class EntityAIAmbushTarget extends EntityAIBase
}
}
}
if (idealPos != null)
{
return idealPos;
@@ -24,21 +24,21 @@ public class EntityAIAnimation extends EntityAIBase
isDead = !npc.isEntityAlive();
if(isDead)
return npc.currentAnimation != EnumAnimation.LYING;
if(npc.stats.aimWhileShooting && npc.isAttacking())
return npc.currentAnimation != EnumAnimation.AIMING;
if(npc.ai.animationType == EnumAnimation.NONE)
if(npc.ais.animationType == EnumAnimation.NONE)
return npc.currentAnimation != EnumAnimation.NONE;
isAttacking = npc.isAttacking();
if(npc.ai.returnToStart)
if(npc.ais.returnToStart)
isAtStartpoint = npc.isVeryNearAssignedPlace();
hasPath = !npc.getNavigator().noPath();
if(npc.ai.movingType == EnumMovingType.Standing && hasNavigation() && npc.currentAnimation.getWalkingAnimation() == 0){
if(npc.ais.movingType == EnumMovingType.Standing && hasNavigation() && npc.currentAnimation.getWalkingAnimation() == 0){
return npc.currentAnimation != EnumAnimation.NONE;
}
return npc.currentAnimation != npc.ai.animationType;
return npc.currentAnimation != npc.ais.animationType;
}
@Override
@@ -47,21 +47,21 @@ public class EntityAIAnimation extends EntityAIBase
setAnimation(EnumAnimation.AIMING);
return;
}
EnumAnimation type = npc.ai.animationType;
EnumAnimation type = npc.ais.animationType;
if(isDead)
type = EnumAnimation.LYING;
else if(npc.ai.movingType == EnumMovingType.Standing && npc.ai.animationType.getWalkingAnimation() == 0 && hasNavigation())
else if(npc.ais.movingType == EnumMovingType.Standing && npc.ais.animationType.getWalkingAnimation() == 0 && hasNavigation())
type = EnumAnimation.NONE;
setAnimation(type);
}
private void setAnimation(EnumAnimation animation){
npc.setCurrentAnimation(animation);
npc.updateHitbox();
npc.setPosition(npc.posX, npc.posY, npc.posZ);
}
private boolean hasNavigation() {
return (isAttacking || npc.ai.returnToStart && !isAtStartpoint && !npc.isFollower() || hasPath);
return (isAttacking || npc.ais.returnToStart && !isAtStartpoint && !npc.isFollower() || hasPath);
}
}
@@ -1,6 +1,6 @@
package noppes.npcs.ai;
import kamkeel.addon.DBCAddon;
import kamkeel.npcs.addon.DBCAddon;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIBase;
@@ -47,14 +47,14 @@ public class EntityAIAttackTarget extends EntityAIBase
else if (!entitylivingbase.isEntityAlive()){
return false;
}
else if (this.npc.inventory.getProjectile() != null && this.npc.ai.useRangeMelee == 0){
else if (this.npc.inventory.getProjectile() != null && this.npc.ais.useRangeMelee == 0){
return false;
}
double var2 = this.npc.getDistanceSq(entitylivingbase.posX, entitylivingbase.boundingBox.minY, entitylivingbase.posZ);
double var3 = this.npc.ai.distanceToMelee * this.npc.ai.distanceToMelee;
double var3 = this.npc.ais.distanceToMelee * this.npc.ais.distanceToMelee;
if (this.npc.ai.useRangeMelee == 1 && var2 > var3){
if (this.npc.ais.useRangeMelee == 1 && var2 > var3){
return false;
}
else{
@@ -81,7 +81,7 @@ public class EntityAIAttackTarget extends EntityAIBase
if(npc.getDistanceToEntity(entityTarget) > npc.stats.aggroRange)
return false;
if (this.npc.ai.useRangeMelee == 1 && npc.getDistanceSqToEntity(entityTarget) > (this.npc.ai.distanceToMelee * this.npc.ai.distanceToMelee))
if (this.npc.ais.useRangeMelee == 1 && npc.getDistanceSqToEntity(entityTarget) > (this.npc.ais.distanceToMelee * this.npc.ais.distanceToMelee))
return false;
return this.npc.isWithinHomeDistance(MathHelper.floor_double(entityTarget.posX), MathHelper.floor_double(entityTarget.posY), MathHelper.floor_double(entityTarget.posZ));
@@ -94,7 +94,7 @@ public class EntityAIAttackTarget extends EntityAIBase
if(!navOverride)
this.npc.getNavigator().setPath(this.entityPathEntity, 1.3D);
this.field_75445_i = 0;
if (this.npc.getRangedTask() != null && this.npc.ai.useRangeMelee == 2)
if (this.npc.getRangedTask() != null && this.npc.ais.useRangeMelee == 2)
{
this.npc.getRangedTask().navOverride(true);
}
@@ -109,7 +109,7 @@ public class EntityAIAttackTarget extends EntityAIBase
this.entityTarget = null;
this.npc.setAttackTarget(null);
this.npc.getNavigator().clearPathEntity();
if (this.npc.getRangedTask() != null && this.npc.ai.useRangeMelee == 2)
if (this.npc.getRangedTask() != null && this.npc.ais.useRangeMelee == 2)
{
this.npc.getRangedTask().navOverride(false);
}
@@ -19,7 +19,7 @@ public class EntityAIAvoidTarget extends EntityAIBase
private EntityNPCInterface theEntity;
private Entity closestLivingEntity;
private float distanceFromEntity;
private float health;
/** The PathEntity of our entity */
@@ -27,7 +27,7 @@ public class EntityAIAvoidTarget extends EntityAIBase
/** The PathNavigate of our entity */
private PathNavigate entityPathNavigate;
/** The class of the entity we should avoid */
private Class targetEntityClass;
@@ -46,14 +46,14 @@ public class EntityAIAvoidTarget extends EntityAIBase
public boolean shouldExecute()
{
EntityLivingBase target = this.theEntity.getAttackTarget();
if (target == null)
{
return false;
}
targetEntityClass = target.getClass();
if (this.targetEntityClass == EntityPlayer.class)
{
this.closestLivingEntity = this.theEntity.worldObj.getClosestPlayerToEntity(this.theEntity, (double)this.distanceFromEntity);
@@ -75,7 +75,7 @@ public class EntityAIAvoidTarget extends EntityAIBase
this.closestLivingEntity = (Entity)var1.get(0);
}
if (!this.theEntity.getEntitySenses().canSee(this.closestLivingEntity) && this.theEntity.ai.directLOS)
if (!this.theEntity.getEntitySenses().canSee(this.closestLivingEntity) && this.theEntity.ais.directLOS)
{
return false;
}
@@ -83,10 +83,10 @@ public class EntityAIAvoidTarget extends EntityAIBase
{
Vec3 var2 = RandomPositionGeneratorAlt.findRandomTargetBlockAwayFrom(this.theEntity, 16, 7, Vec3.createVectorHelper(this.closestLivingEntity.posX, this.closestLivingEntity.posY, this.closestLivingEntity.posZ));
boolean var3 = this.theEntity.inventory.getProjectile() == null || this.theEntity.ai.useRangeMelee == 2;
boolean var3 = this.theEntity.inventory.getProjectile() == null || this.theEntity.ais.useRangeMelee == 2;
boolean var4 = var3 ? this.health == this.theEntity.getHealth() : this.theEntity.getRangedTask() != null && !this.theEntity.getRangedTask().hasFired();
if (var2 == null)
{
return false;
@@ -95,7 +95,7 @@ public class EntityAIAvoidTarget extends EntityAIBase
{
return false;
}
else if (this.theEntity.ai.tacticalVariant == EnumNavType.HitNRun && var4)
else if (this.theEntity.ais.tacticalVariant == EnumNavType.HitNRun && var4)
{
return false;
}
@@ -145,13 +145,13 @@ public class EntityAIAvoidTarget extends EntityAIBase
{
this.theEntity.getNavigator().setSpeed(1.0D);
}
if (this.theEntity.ai.tacticalVariant == EnumNavType.HitNRun)
if (this.theEntity.ais.tacticalVariant == EnumNavType.HitNRun)
{
float dist = this.theEntity.getDistanceToEntity(this.closestLivingEntity);
if (dist > this.distanceFromEntity || dist < this.theEntity.ai.tacticalRadius)
if (dist > this.distanceFromEntity || dist < this.theEntity.ais.tacticalRadius)
{
this.health = this.theEntity.getHealth();
}
}
}
}
}
@@ -26,9 +26,9 @@ public class EntityAIFollow extends EntityAIBase
return false;
return distance > npc.followRange();
}
public boolean excute(){
if(!npc.isEntityAlive() || !npc.isFollower() || npc.isAttacking() || (owner = npc.getOwner()) == null || npc.ai.animationType == EnumAnimation.SITTING)
if(!npc.isEntityAlive() || !npc.isFollower() || npc.isAttacking() || (owner = npc.getOwner()) == null || npc.ais.animationType == EnumAnimation.SITTING)
return false;
distance = npc.getDistanceSqToEntity(owner);
return true;
@@ -62,7 +62,7 @@ public class EntityAIFollow extends EntityAIBase
speed = 3;
if (this.npc.getNavigator().tryMoveToEntityLiving(owner, speed) || distance < 225.0D)
return;
int i = MathHelper.floor_double(this.owner.posX) - 2;
int j = MathHelper.floor_double(this.owner.posZ) - 2;
int k = MathHelper.floor_double(this.owner.boundingBox.minY);
+13 -13
View File
@@ -28,15 +28,15 @@ public class EntityAILook extends EntityAIBase{
public boolean shouldExecute(){
return !npc.isAttacking() && npc.getNavigator().noPath() && !npc.isPlayerSleeping() && npc.isEntityAlive();
}
/**
* Execute a one shot task or start executing a continuous task
*/
@Override
public void startExecuting(){
rotatebody = npc.ai.standingType == EnumStandingType.RotateBody || npc.ai.standingType == EnumStandingType.HeadRotation;
rotatebody = npc.ais.standingType == EnumStandingType.RotateBody || npc.ais.standingType == EnumStandingType.HeadRotation;
}
/**
* Resets the task
*/
@@ -44,13 +44,13 @@ public class EntityAILook extends EntityAIBase{
public void resetTask(){
rotatebody = false;
}
/**
* Updates the task
*/
@Override
public void updateTask(){
if(npc.ai.standingType == EnumStandingType.Stalking){
public void updateTask(){
if(npc.ais.standingType == EnumStandingType.Stalking){
EntityPlayer player = npc.worldObj.getClosestPlayerToEntity(npc, 16);
if(player == null)
rotatebody = true;
@@ -75,14 +75,14 @@ public class EntityAILook extends EntityAIBase{
npc.getLookHelper().setLookPositionWithEntity(closest, 10F, npc.getVerticalFaceSpeed());
return;
}
}
if(rotatebody){
if(idle == 0 && npc.getRNG().nextFloat() < 0.02F){
double var1 = (Math.PI * 2D) * this.npc.getRNG().nextDouble();
if(npc.ai.standingType == EnumStandingType.HeadRotation)
var1 = Math.PI / 180 * npc.ai.orientation + Math.PI * 0.2 + Math.PI * 0.6 * this.npc.getRNG().nextDouble();
if(npc.ais.standingType == EnumStandingType.HeadRotation)
var1 = Math.PI / 180 * npc.ais.orientation + Math.PI * 0.2 + Math.PI * 0.6 * this.npc.getRNG().nextDouble();
this.lookX = Math.cos(var1);
this.lookZ = Math.sin(var1);
this.idle = 20 + this.npc.getRNG().nextInt(20);
@@ -92,9 +92,9 @@ public class EntityAILook extends EntityAIBase{
npc.getLookHelper().setLookPosition(npc.posX + lookX, npc.posY + npc.getEyeHeight(), npc.posZ + lookZ, 10F, npc.getVerticalFaceSpeed());
}
}
if(npc.ai.standingType == EnumStandingType.NoRotation){
npc.rotationYawHead = npc.rotationYaw = npc.renderYawOffset = npc.ai.orientation;
if(npc.ais.standingType == EnumStandingType.NoRotation){
npc.rotationYawHead = npc.rotationYaw = npc.renderYawOffset = npc.ais.orientation;
}
}
}
@@ -21,16 +21,16 @@ public class EntityAIMovingPath extends EntityAIBase
*/
@Override
public boolean shouldExecute(){
if (npc.isAttacking() || npc.isInteracting() || npc.getRNG().nextInt(40) != 0 && npc.ai.movingPause || !npc.getNavigator().noPath() || npc.isInteracting())
if (npc.isAttacking() || npc.isInteracting() || npc.getRNG().nextInt(40) != 0 && npc.ais.movingPause || !npc.getNavigator().noPath() || npc.isInteracting())
return false;
List<int[]> list = npc.ai.getMovingPath();
List<int[]> list = npc.ais.getMovingPath();
if(list.size() < 2)
return false;
npc.ai.incrementMovingPath();
pos = npc.ai.getCurrentMovingPath();
npc.ais.incrementMovingPath();
pos = npc.ais.getCurrentMovingPath();
return true;
}
@@ -40,7 +40,7 @@ public class EntityAIMovingPath extends EntityAIBase
@Override
public boolean continueExecuting(){
if(npc.isAttacking() || npc.isInteracting()){
npc.ai.decreaseMovingPath();
npc.ais.decreaseMovingPath();
return false;
}
return !this.npc.getNavigator().noPath();
@@ -54,16 +54,16 @@ public class EntityAIRangedAttack extends EntityAIBase
EntityLivingBase var1 = this.entityHost.getAttackTarget();
if (var1 == null || !var1.isEntityAlive()) return false;
if(entityHost.getDistanceToEntity(var1) > entityHost.stats.aggroRange) return false;
if (this.entityHost.inventory.getProjectile() == null) return false;
double var2 = this.entityHost.getDistanceSq(var1.posX, var1.boundingBox.minY, var1.posZ);
double var3 = this.entityHost.ai.distanceToMelee * this.entityHost.ai.distanceToMelee;
if (this.entityHost.ai.useRangeMelee >= 1 && var2 <= var3) return false;
double var3 = this.entityHost.ais.distanceToMelee * this.entityHost.ais.distanceToMelee;
if (this.entityHost.ais.useRangeMelee >= 1 && var2 <= var3) return false;
else
{
this.attackTarget = var1;
@@ -91,7 +91,7 @@ public class EntityAIRangedAttack extends EntityAIBase
this.hasFired = false;
this.rangedAttackTime = this.entityHost.stats.minDelay / 2;
}
/**
* Updates the task
*/
@@ -101,7 +101,7 @@ public class EntityAIRangedAttack extends EntityAIBase
double var1 = this.entityHost.getDistanceSq(this.attackTarget.posX, this.attackTarget.boundingBox.minY, this.attackTarget.posZ);
float field_82642_h = this.entityHost.stats.rangedRange * this.entityHost.stats.rangedRange;
if (!navOverride && this.entityHost.ai.directLOS)
if (!navOverride && this.entityHost.ais.directLOS)
{
if (this.entityHost.getEntitySenses().canSee(this.attackTarget))
{
@@ -111,7 +111,7 @@ public class EntityAIRangedAttack extends EntityAIBase
{
this.field_75318_f = 0;
}
int v = this.entityHost.ai.tacticalVariant == EnumNavType.Default ? 20 : 5;
int v = this.entityHost.ais.tacticalVariant == EnumNavType.Default ? 20 : 5;
if (var1 <= (double)field_82642_h && this.field_75318_f >= v)
{
this.entityHost.getNavigator().clearPathEntity();
@@ -123,10 +123,10 @@ public class EntityAIRangedAttack extends EntityAIBase
}
this.rangedAttackTime = Math.max(this.rangedAttackTime - 1, 0);
if (this.rangedAttackTime <= 0)
{
if (var1 <= (double)field_82642_h && (this.entityHost.getEntitySenses().canSee(this.attackTarget) || this.entityHost.ai.canFireIndirect == 2))
if (var1 <= (double)field_82642_h && (this.entityHost.getEntitySenses().canSee(this.attackTarget) || this.entityHost.ais.canFireIndirect == 2))
{
if (this.field_70846_g++ <= this.entityHost.stats.burstCount)
{
@@ -138,34 +138,34 @@ public class EntityAIRangedAttack extends EntityAIBase
this.hasFired = true;
this.rangedAttackTime = (this.entityHost.stats.maxDelay - MathHelper.floor_float(this.entityHost.getRNG().nextFloat() * (this.entityHost.stats.maxDelay - this.entityHost.stats.minDelay)));
}
if (this.field_70846_g > 1)
{
boolean indirect = false;
switch(this.entityHost.ai.canFireIndirect)
switch(this.entityHost.ais.canFireIndirect)
{
case 1 : indirect = var1 > (double)field_82642_h / 2; break;
case 2 : indirect = !this.entityHost.getEntitySenses().canSee(this.attackTarget);
}
this.rangedAttackEntityHost.attackEntityWithRangedAttack(this.attackTarget, indirect ? 1 : 0);
if (this.entityHost.currentAnimation != EnumAnimation.AIMING)
{
this.entityHost.swingItem();
}
}
}
}
}
}
public boolean hasFired()
{
return this.hasFired;
}
public void navOverride(boolean nav){
this.navOverride = nav;
this.setMutexBits(this.navOverride ? AiMutex.PATHING : AiMutex.LOOK + AiMutex.PASSIVE);
}
}
}
@@ -29,25 +29,25 @@ public class EntityAIReturn extends EntityAIBase
* Returns whether the EntityAIBase should begin execution.
*/
public boolean shouldExecute() {
if (!npc.ai.returnToStart){
if (!npc.ais.returnToStart){
return false;
}
if(npc.hasOwner() || npc.isKilled() || npc.isInteracting()){
return false;
}
if (npc.ai.findShelter == 0 && (!npc.worldObj.isDaytime() || npc.worldObj.isRaining()) && !npc.worldObj.provider.hasNoSky){
if (npc.ais.findShelter == 0 && (!npc.worldObj.isDaytime() || npc.worldObj.isRaining()) && !npc.worldObj.provider.hasNoSky){
if (npc.worldObj.canBlockSeeTheSky((int)npc.getStartXPos(), (int)npc.getStartYPos(), (int)npc.getStartZPos()) || npc.worldObj.getFullBlockLightValue((int)npc.getStartXPos(), (int)npc.getStartYPos(), (int)npc.getStartZPos()) <= 8){
return false;
}
}
else if (npc.ai.findShelter == 1 && npc.worldObj.isDaytime()){
else if (npc.ais.findShelter == 1 && npc.worldObj.isDaytime()){
if (npc.worldObj.canBlockSeeTheSky((int)npc.getStartXPos(), (int)npc.getStartYPos(), (int)npc.getStartZPos())){
return false;
}
}
if(npc.isAttacking()){
if(!wasAttacked){
wasAttacked = true;
@@ -56,33 +56,33 @@ public class EntityAIReturn extends EntityAIBase
return false;
}
if(npc.ai.movingType == EnumMovingType.MovingPath && npc.ai.getDistanceSqToPathPoint() < ConfigMain.NpcNavRange * ConfigMain.NpcNavRange)
if(npc.ais.movingType == EnumMovingType.MovingPath && npc.ais.getDistanceSqToPathPoint() < ConfigMain.NpcNavRange * ConfigMain.NpcNavRange)
return false;
if (npc.getNavigator().noPath() || (!npc.isAttacking() && wasAttacked)) {
return true;
}
if(npc.ai.movingType == EnumMovingType.Wandering)
return this.npc.getDistanceSq(npc.getStartXPos(), npc.getStartYPos(), npc.getStartZPos()) > npc.ai.walkingRange * npc.ai.walkingRange;
if(npc.ais.movingType == EnumMovingType.Wandering)
return this.npc.getDistanceSq(npc.getStartXPos(), npc.getStartYPos(), npc.getStartZPos()) > npc.ais.walkingRange * npc.ais.walkingRange;
if(npc.ai.movingType == EnumMovingType.Standing)
if(npc.ais.movingType == EnumMovingType.Standing)
return !this.npc.isVeryNearAssignedPlace();
return false;
}
public boolean continueExecuting(){
return !npc.isFollower() && !npc.isKilled() && !npc.isAttacking() && !npc.isVeryNearAssignedPlace() && totalTicks <= MaxTotalTicks && !npc.isInteracting();
}
public void updateTask(){
totalTicks++;
if(totalTicks > MaxTotalTicks){
npc.setPosition(endPosX, endPosY, endPosZ);
npc.getNavigator().clearPathEntity();
return;
}
}
if(stuckTicks > 0){
stuckTicks--;
}
@@ -95,19 +95,19 @@ public class EntityAIReturn extends EntityAIBase
}
else
navigate(stuckCount % 2 == 1);
}
}
else{
stuckCount = 0;
}
}
private boolean isTooFar(){
int allowedDistance = npc.stats.aggroRange * 2;
if(npc.ai.movingType == EnumMovingType.Wandering)
allowedDistance += npc.ai.walkingRange;
if(npc.ais.movingType == EnumMovingType.Wandering)
allowedDistance += npc.ais.walkingRange;
return npc.getDistanceSq(endPosX, endPosY, endPosZ) > allowedDistance * allowedDistance;
}
public void startExecuting()
public void startExecuting()
{
stuckTicks = 0;
totalTicks = 0;
@@ -133,7 +133,7 @@ public class EntityAIReturn extends EntityAIBase
int distance = (int) range;
if(distance > ConfigMain.NpcNavRange)
distance = ConfigMain.NpcNavRange / 2;
else
else
distance /= 2;
if(distance > 2){
Vec3 start = Vec3.createVectorHelper(posX, posY, posZ);
@@ -22,7 +22,7 @@ public class EntityAISprintToTarget extends EntityAIBase
return false;
}
switch(this.npc.ai.onAttack){
switch(this.npc.ais.onAttack){
case 0 : return !this.npc.isInRange(runTarget, 8)? (!this.npc.onGround ? false : true) : false;
case 2 : return this.npc.isInRange(runTarget, 7)? (!this.npc.onGround ? false : true) : false;
default : return false;
@@ -33,9 +33,9 @@ public class EntityAIWander extends EntityAIBase
if (this.entity.getAge() >= 100 || !entity.getNavigator().noPath() || entity.isInteracting() || this.entity.getRNG().nextInt(80) != 0){
return false;
}
if(entity.ai.npcInteracting && entity.getRNG().nextInt(4) == 1)
if(entity.ais.npcInteracting && entity.getRNG().nextInt(4) == 1)
nearbyNPC = getNearbyNPC();
if(nearbyNPC != null){
this.xPosition = MathHelper.floor_double(nearbyNPC.posX);
this.yPosition = MathHelper.floor_double(nearbyNPC.posY);
@@ -52,7 +52,7 @@ public class EntityAIWander extends EntityAIBase
this.yPosition = vec.yCoord;
if(entity.canFly())
this.yPosition = entity.getStartYPos() + entity.getRNG().nextFloat() * 0.75 * entity.ai.walkingRange;
this.yPosition = entity.getStartYPos() + entity.getRNG().nextFloat() * 0.75 * entity.ais.walkingRange;
this.zPosition = vec.zCoord;
}
}
@@ -66,28 +66,28 @@ public class EntityAIWander extends EntityAIBase
}
}
private EntityNPCInterface getNearbyNPC() {
List<EntityNPCInterface> list = entity.worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(entity.ai.walkingRange, entity.ai.walkingRange > 7?7:entity.ai.walkingRange, entity.ai.walkingRange), selector);
List<EntityNPCInterface> list = entity.worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(entity.ais.walkingRange, entity.ais.walkingRange > 7?7:entity.ais.walkingRange, entity.ais.walkingRange), selector);
Iterator<EntityNPCInterface> ita = list.iterator();
while(ita.hasNext()){
EntityNPCInterface npc = ita.next();
if(!npc.ai.stopAndInteract || npc.isAttacking() || !npc.isEntityAlive() || entity.faction.isAggressiveToNpc(npc))
if(!npc.ais.stopAndInteract || npc.isAttacking() || !npc.isEntityAlive() || entity.faction.isAggressiveToNpc(npc))
ita.remove();
}
if(list.isEmpty())
return null;
return list.get(entity.getRNG().nextInt(list.size()));
}
private Vec3 getVec(){
if(entity.ai.walkingRange > 0){
if(entity.ais.walkingRange > 0){
double distance = this.entity.getDistanceSq(this.entity.getStartXPos(), this.entity.getStartYPos(), this.entity.getStartZPos());
int range = (int) MathHelper.sqrt_double(this.entity.ai.walkingRange * this.entity.ai.walkingRange - distance);
int range = (int) MathHelper.sqrt_double(this.entity.ais.walkingRange * this.entity.ais.walkingRange - distance);
if(range > ConfigMain.NpcNavRange)
range = ConfigMain.NpcNavRange;
if(range < 3){
range = this.entity.ai.walkingRange;
range = this.entity.ais.walkingRange;
if(range > ConfigMain.NpcNavRange)
range = ConfigMain.NpcNavRange;
Vec3 start = Vec3.createVectorHelper(this.entity.getStartXPos(), this.entity.getStartYPos(), this.entity.getStartZPos());
@@ -121,7 +121,7 @@ public class EntityAIWander extends EntityAIBase
entity.saySurrounding(line);
else
nearbyNPC.saySurrounding(line);
entity.addInteract(nearbyNPC);
nearbyNPC.addInteract(entity);
}
@@ -20,7 +20,7 @@ public class EntityAIWaterNav extends EntityAIBase
{
if (this.theEntity.isInWater() || this.theEntity.handleLavaMovement())
{
if (this.theEntity.ai.canSwim)
if (this.theEntity.ais.canSwim)
{
return true;
}
@@ -28,7 +28,7 @@ public class EntityAIWaterNav extends EntityAIBase
{
return true;
}
}
return false;
}
@@ -92,7 +92,7 @@ public class FlyPathFinder extends PathFinder
{
int i;
if (((EntityNPCInterface)theEntity).ai.canSwim && this.theEntity.isInWater())
if (((EntityNPCInterface)theEntity).ais.canSwim && this.theEntity.isInWater())
{
i = (int)this.theEntity.boundingBox.minY;
BlockPos.MutableBlockPos muteBlock = new BlockPos.MutableBlockPos(MathHelper.floor_double(this.theEntity.posX), i, MathHelper.floor_double(this.theEntity.posZ));
@@ -132,7 +132,7 @@ public class FlyPathFinder extends PathFinder
return openPoint(blockpos1.getX(), i, blockpos1.getZ());
}
public NPCPathPoint getPathPointToCoords(Entity entityIn, double x, double y, double z)
{
@@ -661,7 +661,7 @@ public class FlyPathFinder extends PathFinder
int entitySizeX = MathHelper.floor_double(this.theEntity.width + 1.0F);
int entitySizeY = MathHelper.floor_double(this.theEntity.height + 1.0F);
int entitySizeZ = MathHelper.floor_double(this.theEntity.width + 1.0F);
return this.getPathNodeType(this.worldMap, p_192558_2_, p_192558_3_, p_192558_4_, p_192558_1_, entitySizeX, entitySizeY, entitySizeZ, ((EntityCustomNpc)this.theEntity).ai.doorInteract == 0, ((EntityCustomNpc)this.theEntity).ai.doorInteract == 1);
return this.getPathNodeType(this.worldMap, p_192558_2_, p_192558_3_, p_192558_4_, p_192558_1_, entitySizeX, entitySizeY, entitySizeZ, ((EntityCustomNpc)this.theEntity).ais.doorInteract == 0, ((EntityCustomNpc)this.theEntity).ais.doorInteract == 1);
}
public PathNodeType checkNeighborBlocks(IBlockAccess worldmap, int x, int y, int z, PathNodeType type)
@@ -735,7 +735,7 @@ public class FlyPathFinder extends PathFinder
{
if (material == Material.water)
{
return ((EntityNPCInterface)this.theEntity).ai.canSwim ? PathNodeType.OPEN : PathNodeType.WATER;
return ((EntityNPCInterface)this.theEntity).ais.canSwim ? PathNodeType.OPEN : PathNodeType.WATER;
}
else if (material == Material.lava)
{
@@ -28,7 +28,7 @@ public class FlyingMoveHelper extends EntityMoveHelper{
this.update = false;
double speed = this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
double verticalSpeed = this.speed * this.entity.ai.flySpeed/8.0D;
double verticalSpeed = this.speed * this.entity.ais.flySpeed/8.0D;
this.entity.setAIMoveSpeed((float)speed);
double d0 = this.posX - this.entity.posX;
@@ -45,7 +45,7 @@ public class FlyingMoveHelper extends EntityMoveHelper{
this.entity.motionX += (speed * (d0 / d5) - this.entity.motionX) * speed;
this.entity.motionZ += (speed * (d2 / d5) - this.entity.motionZ) * speed;
if (((EntityNPCFlying)this.entity).flyLimitAllow || !this.entity.ai.hasFlyLimit) {
if (((EntityNPCFlying)this.entity).flyLimitAllow || !this.entity.ais.hasFlyLimit) {
this.entity.motionY = verticalSpeed * (d1 / d5);
if (this.entity.motionY > 0) {
this.entity.motionY += 0.1D;
@@ -1,6 +1,6 @@
package noppes.npcs.ai.selector;
import kamkeel.addon.DBCAddon;
import kamkeel.npcs.addon.DBCAddon;
import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -31,20 +31,20 @@ public class NPCAttackSelector implements IEntitySelector
public boolean isEntityApplicable(Entity entity){
if(!entity.isEntityAlive() || entity == npc || npc.getDistanceToEntity(entity) > npc.stats.aggroRange || !(entity instanceof EntityLivingBase) || ((EntityLivingBase)entity).getHealth() < 1)
return false;
if (this.npc.ai.directLOS && !this.npc.getEntitySenses().canSee(entity))
if (this.npc.ais.directLOS && !this.npc.getEntitySenses().canSee(entity))
return false;
if(!npc.stats.attackInvisible &&((EntityLivingBase)entity).isPotionActive(Potion.invisibility) && npc.getDistanceSqToEntity(entity) < 9)
return false;
//prevent the npc from going on an endless killing spree
if(!npc.isFollower() && npc.ai.returnToStart){
if(!npc.isFollower() && npc.ais.returnToStart){
int allowedDistance = npc.stats.aggroRange * 2;
if(npc.ai.movingType == EnumMovingType.Wandering)
allowedDistance += npc.ai.walkingRange;
if(npc.ais.movingType == EnumMovingType.Wandering)
allowedDistance += npc.ais.walkingRange;
double distance = entity.getDistanceSq(npc.getStartXPos(), npc.getStartYPos(), npc.getStartZPos());
if(npc.ai.movingType == EnumMovingType.MovingPath){
int[] arr = npc.ai.getCurrentMovingPath();
if(npc.ais.movingType == EnumMovingType.MovingPath){
int[] arr = npc.ais.getCurrentMovingPath();
distance = entity.getDistanceSq(arr[0], arr[1], arr[2]);
}
@@ -14,7 +14,7 @@ public class NPCInteractSelector implements IEntitySelector {
if(entity == npc || !(entity instanceof EntityNPCInterface) || !npc.isEntityAlive())
return false;
EntityNPCInterface selected = (EntityNPCInterface) entity;
if(selected.isAttacking() || npc.getFaction().isAggressiveToNpc(selected) || !npc.ai.stopAndInteract)
if(selected.isAttacking() || npc.getFaction().isAggressiveToNpc(selected) || !npc.ais.stopAndInteract)
return false;
return true;
}
@@ -10,29 +10,34 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileBanner;
import noppes.npcs.blocks.tiles.TileColorable;
import java.util.List;
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class BlockBanner extends BlockContainer{
public int renderId = -1;
public BlockBanner() {
super(Material.rock);
setBlockBounds(0, 0, 0, 1, 2, 1);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
ItemStack item = player.inventory.getCurrentItem();
if(item == null)
@@ -43,10 +48,10 @@ public class BlockBanner extends BlockContainer{
TileBanner tile = (TileBanner) par1World.getTileEntity(i, j, k);
if(tile.canEdit())
return true;
else if(item.getItem() != Items.dye)
else if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int color = BlockColored.func_150031_c(item.getItemDamage());
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
if(tile.color != color){
NoppesUtilServer.consumeItemStack(1, player);
tile.color = color;
@@ -54,7 +59,7 @@ public class BlockBanner extends BlockContainer{
}
return true;
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -63,13 +68,13 @@ public class BlockBanner extends BlockContainer{
par3List.add(new ItemStack(par1, 1, 4));
}
@Override
@Override
public int damageDropped(int par1)
{
return par1 % 7;
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
int meta = world.getBlockMetadata(x, y, z);
if(meta >= 7)
@@ -78,22 +83,26 @@ public class BlockBanner extends BlockContainer{
setBlockBounds(0, 0, 0, 1, 2, 1);
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
if(!par1World.isAirBlock(par2, par3 + 1, par4)){
par1World.setBlockToAir(par2, par3, par4);
}
else{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileBanner tile = (TileBanner) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
tile.color = 15 - par6ItemStack.getItemDamage();
tile.rotation = l;
tile.color = colorTableInts[15 - par6ItemStack.getItemDamage()];
if(par6ItemStack.hasTagCompound() && par6ItemStack.getTagCompound().hasKey(BRUSH_COLOR_TAG)){
tile.color = par6ItemStack.getTagCompound().getInteger(BRUSH_COLOR_TAG);
}
tile.time = System.currentTimeMillis();
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
par1World.setBlock(par2, par3 + 1, par4, this, par6ItemStack.getItemDamage() + 7, 2);
@@ -102,25 +111,25 @@ public class BlockBanner extends BlockContainer{
}
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@Override
@SideOnly(Side.CLIENT)
@@ -150,8 +159,27 @@ public class BlockBanner extends BlockContainer{
{
if (p_149681_5_ >= 7 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this)
p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_);
else if (p_149681_5_ < 7 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ + 1, p_149681_4_) == this)
p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ + 1, p_149681_4_);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if(meta >= 7)
y--;
TileEntity tileentity = world.getTileEntity(x, y, z);
ItemStack stack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
if (tileentity instanceof TileBanner) {
NBTTagCompound compound = new NBTTagCompound();
tileentity.writeToNBT(compound);
NBTTagCompound brushCompound = new NBTTagCompound();
brushCompound.setInteger(BRUSH_COLOR_TAG, compound.getInteger(BRUSH_COLOR_TAG));
stack.setTagCompound(brushCompound);
}
return stack;
}
}
@@ -9,17 +9,17 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileBeam;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileVariant;
import java.util.List;
public class BlockBeam extends BlockRotated{
public BlockBeam() {
super(Blocks.planks);
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -29,18 +29,18 @@ public class BlockBeam extends BlockRotated{
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public int damageDropped(int par1){
return par1;
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
if(tile.rotation == 0){
setBlockBounds(0.33f, 0.33f, 0.25f, 0.67f, 0.67f, 1f );
}
@@ -55,7 +55,7 @@ public class BlockBeam extends BlockRotated{
}
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
@@ -20,7 +20,7 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileBigSign;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileVariant;
import noppes.npcs.constants.EnumGuiType;
public class BlockBigSign extends BlockContainer{
@@ -70,11 +70,11 @@ public class BlockBigSign extends BlockContainer{
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
int meta = tile.getBlockMetadata();
float xStart = 0;
float zStart = 0;
@@ -1,5 +1,7 @@
package noppes.npcs.blocks;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.gui.GuiOpenBookPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
@@ -10,9 +12,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.Server;
import noppes.npcs.blocks.tiles.TileBook;
import noppes.npcs.constants.EnumPacketClient;
public class BlockBook extends BlockRotated{
@@ -32,8 +32,8 @@ public class BlockBook extends BlockRotated{
if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BOOK)) {
((TileBook)tile).book.func_150996_a(Items.writable_book);
}
Server.sendData((EntityPlayerMP)player, EnumPacketClient.OPEN_BOOK, i, j, k, ((TileBook)tile).book.writeToNBT(new NBTTagCompound()));
return true;
PacketHandler.Instance.sendToPlayer(new GuiOpenBookPacket(i, j, k, ((TileBook)tile).book.writeToNBT(new NBTTagCompound())), (EntityPlayerMP) player);
return true;
}
@Override
@@ -19,8 +19,6 @@ import org.lwjgl.opengl.GL11;
import java.util.Random;
import static noppes.npcs.client.ClientProxy.RAND;
public class BlockCampfire extends BlockLightable{
public BlockCampfire(boolean lit) {
@@ -43,8 +41,7 @@ public class BlockCampfire extends BlockLightable{
int meta = world.getBlockMetadata(x, y, z);
if((item.getItem() == Items.flint || item.getItem() == Items.flint_and_steel) && unlitBlock() == this){
if(world.rand.nextInt(3) == 0 && !world.isRemote)
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
CustomNpcs.proxy.spawnParticle("largesmoke", x + 0.5f, y + 0.5f, z + 0.5f, 0.0D, 0.0D, 0.0D, 2);
if(item.getItem() == Items.flint)
NoppesUtilServer.consumeItemStack(1, player);
@@ -3,6 +3,7 @@ package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
@@ -10,31 +11,31 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.blocks.tiles.TileCandle;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileVariant;
import java.util.Random;
public class BlockCandle extends BlockLightable{
public BlockCandle(boolean lit) {
super(Blocks.planks, lit);
super(Blocks.stone, lit);
setBlockBounds(0.3f, 0, 0.3f, 0.7f, 0.5f, 0.7f);
}
}
@Override
public int maxRotation(){
return 8;
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
if(tile.color == 2){
TileVariant tile = (TileVariant) tileentity;
if(tile.variant == 2){
float xOffset = 0;
float yOffset = 0;
if(tile.rotation == 0)
@@ -45,31 +46,31 @@ public class BlockCandle extends BlockLightable{
xOffset = 0.2f;
else if(tile.rotation == 2)
xOffset = -0.2f;
setBlockBounds(0.2f + xOffset, 0.4f, 0.2f + yOffset, 0.8f + xOffset, 0.9f, 0.8f + yOffset);
}
else if(tile.color == 1)
else if(tile.variant == 1)
setBlockBounds(0.1f, 0.1f, 0.1f, 0.9f, 0.8f, 0.9f);
else
setBlockBounds(0.3f, 0, 0.3f, 0.7f, 0.5f, 0.7f);
}
@Override
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float p_149660_6_, float p_149660_7_, float p_149660_8_, int meta){
return side;
}
@Override
@Override
public void onPostBlockPlaced(World world, int x, int y, int z, int meta) {
TileCandle tile = (TileCandle) world.getTileEntity(x, y, z);
if(meta == 1)
tile.color = 0;
tile.variant = 0;
else if(meta == 0)
tile.color = 1;
tile.variant = 1;
else{
tile.color = 2;
tile.variant = 2;
if(meta == 2)
tile.rotation = 0;
else if(meta == 3)
@@ -81,10 +82,16 @@ public class BlockCandle extends BlockLightable{
}
world.setBlockMetadataWithNotify(x, y, z, 0, 4);
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister par1IconRegister){
this.blockIcon = par1IconRegister.registerIcon(this.getTextureName());
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int meta){
return Blocks.soul_sand.getIcon(p_149691_1_, meta);
return this.blockIcon;
}
@Override
@@ -97,18 +104,18 @@ public class BlockCandle extends BlockLightable{
if(this == unlitBlock())
return;
TileCandle tile = (TileCandle) world.getTileEntity(x, y, z);
if(tile.color == 1){
if(tile.variant == 1){
if(tile.rotation % 2 == 0){
world.spawnParticle("smoke", x + 0.5f, y + 0.66f, z + 0.13f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", x + 0.5f, y + 0.65f, z + 0.13f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", x + 0.5f, y + 0.66f, z + 0.87f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", x + 0.5f, y + 0.65f, z + 0.87f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", x + 0.13f, y + 0.66f, z + 0.5f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", x + 0.13f, y + 0.65f, z + 0.5f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", x + 0.87f, y + 0.66f, z + 0.5f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", x + 0.87f, y + 0.65f, z + 0.5f, 0.0D, 0.0D, 0.0D);
}
@@ -125,12 +132,12 @@ public class BlockCandle extends BlockLightable{
world.spawnParticle("smoke", x + 0.76f, y + 0.66f, z + 0.24f, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", x + 0.76f, y + 0.65f, z + 0.24f, 0.0D, 0.0D, 0.0D);
}
}
else{
float xOffset = 0.5f, yOffset = 0.45f, zOffset = 0.5f;
if(tile.color == 2){
if(tile.variant == 2){
yOffset = 1.05f;
if(tile.rotation == 0)
zOffset += 0.12f;
@@ -144,7 +151,7 @@ public class BlockCandle extends BlockLightable{
double d0 = (double)((float)x + xOffset);
double d1 = (double)((float)y + yOffset);
double d2 = (double)((float)z + zOffset);
world.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
@@ -2,9 +2,9 @@ package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.blocks.tiles.TileBlockAnvil;
@@ -26,15 +27,35 @@ public class BlockCarpentryBench extends BlockContainer
public int renderId = -1;
public BlockCarpentryBench()
{
super(Material.wood);
setStepSound(soundTypeWood);
super(Material.rock);
setStepSound(soundTypePiston);
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (block != this)
{
return block.getLightValue(world, x, y, z);
}
if(meta >= 4)
return 5;
return getLightValue();
}
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9)
{//onBlockActivated
{
if(!par1World.isRemote){
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerAnvil.ordinal(), par1World, i, j, k);
int meta = par1World.getBlockMetadata(i, j, k);
if(meta >= 4){
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerAnvil.ordinal(), par1World, i, j, k);
} else {
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerCarpentryBench.ordinal(), par1World, i, j, k);
}
}
return true;
}
@@ -63,6 +84,9 @@ public class BlockCarpentryBench extends BlockContainer
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
if(meta >= 4){
return Blocks.anvil.getIcon(side, 0);
}
return Blocks.planks.getIcon(side, 0);
}
@@ -3,7 +3,6 @@ package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -11,7 +10,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -19,38 +17,26 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileCouchWood;
import java.util.List;
public class BlockCouchWood extends BlockContainer{
public int renderId = -1;
public BlockCouchWood() {
super(Material.wood);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
ItemStack item = player.inventory.getCurrentItem();
if(item == null || item.getItem() != Items.dye)
if(item == null)
return BlockChair.MountBlock(par1World, i, j, k, player);
int meta = par1World.getBlockMetadata(i, j, k);
if(meta >= 7)
j--;
TileColorable tile = (TileColorable) par1World.getTileEntity(i, j, k);
int color = BlockColored.func_150031_c(item.getItemDamage());
if(tile.color != color){
NoppesUtilServer.consumeItemStack(1, player);
tile.color = color;
par1World.markBlockForUpdate(i, j, k);
}
return true;
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -60,7 +46,7 @@ public class BlockCouchWood extends BlockContainer{
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public int damageDropped(int par1)
{
return par1;
@@ -69,15 +55,13 @@ public class BlockCouchWood extends BlockContainer{
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 0.5, z + 1);
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileCouchWood tile = (TileCouchWood) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
tile.color = 15 - par6ItemStack.getItemDamage();
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage(), 2);
updateModel(par1World, par2, par3, par4, tile);
onNeighborBlockChange(par1World, par2 + 1, par3, par4, this);
@@ -88,7 +72,7 @@ public class BlockCouchWood extends BlockContainer{
par1World.markBlockForUpdate(par2, par3, par4);
}
@Override
@Override
public void onNeighborBlockChange(World worldObj, int x, int y, int z, Block block) {
if(worldObj.isRemote || block != this)
return;
@@ -98,7 +82,7 @@ public class BlockCouchWood extends BlockContainer{
updateModel(worldObj, x, y, z, (TileCouchWood) tile);
worldObj.markBlockForUpdate(x, y, z);
}
private void updateModel(World world, int x, int y, int z, TileCouchWood tile){
if(world.isRemote)
return;
@@ -131,25 +115,25 @@ public class BlockCouchWood extends BlockContainer{
return tile.rotation == couch.rotation;
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@Override
@SideOnly(Side.CLIENT)
@@ -11,13 +11,14 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileColorable;
@@ -25,23 +26,30 @@ import noppes.npcs.blocks.tiles.TileCouchWool;
import java.util.List;
public class BlockCouchWool extends BlockContainer{
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class BlockCouchWool extends BlockContainer {
public int renderId = -1;
public BlockCouchWool() {
super(Material.wood);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
ItemStack item = player.inventory.getCurrentItem();
if(item == null || item.getItem() != Items.dye)
TileColorable.ColorChangeType colorChangeType = TileColorable.allowColorChange(item);
if(colorChangeType == TileColorable.ColorChangeType.NONE)
return BlockChair.MountBlock(par1World, i, j, k, player);
else if(colorChangeType == TileColorable.ColorChangeType.PAINTBRUSH)
return false;
int meta = par1World.getBlockMetadata(i, j, k);
if(meta >= 7)
j--;
TileColorable tile = (TileColorable) par1World.getTileEntity(i, j, k);
int color = BlockColored.func_150031_c(item.getItemDamage());
TileColorable tile = (TileColorable) par1World.getTileEntity(i, j, k);
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
if(tile.color != color){
NoppesUtilServer.consumeItemStack(1, player);
tile.color = color;
@@ -49,8 +57,8 @@ public class BlockCouchWool extends BlockContainer{
}
return true;
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -60,7 +68,7 @@ public class BlockCouchWool extends BlockContainer{
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public int damageDropped(int par1)
{
return par1;
@@ -69,16 +77,19 @@ public class BlockCouchWool extends BlockContainer{
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 0.5, z + 1);
}
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack itemStack)
{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileCouchWool tile = (TileCouchWool) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
tile.color = 15 - par6ItemStack.getItemDamage();
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage(), 2);
tile.rotation = l;
tile.color = colorTableInts[15 - itemStack.getItemDamage()];
if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey(BRUSH_COLOR_TAG)){
tile.color = itemStack.getTagCompound().getInteger(BRUSH_COLOR_TAG);
}
par1World.setBlockMetadataWithNotify(par2, par3, par4, itemStack.getItemDamage(), 2);
updateModel(par1World, par2, par3, par4, tile);
onNeighborBlockChange(par1World, par2 + 1, par3, par4, this);
onNeighborBlockChange(par1World, par2 - 1, par3, par4, this);
@@ -88,7 +99,7 @@ public class BlockCouchWool extends BlockContainer{
par1World.markBlockForUpdate(par2, par3, par4);
}
@Override
@Override
public void onNeighborBlockChange(World worldObj, int x, int y, int z, Block block) {
if(worldObj.isRemote || block != this)
return;
@@ -98,7 +109,7 @@ public class BlockCouchWool extends BlockContainer{
updateModel(worldObj, x, y, z, (TileCouchWool) tile);
worldObj.markBlockForUpdate(x, y, z);
}
private void updateModel(World world, int x, int y, int z, TileCouchWool tile){
if(world.isRemote)
return;
@@ -130,16 +141,16 @@ public class BlockCouchWool extends BlockContainer{
}
private boolean compareCornerTiles(TileCouchWool tile, int x, int y, int z, World world, int meta, boolean isLeft){
int meta2 = world.getBlockMetadata(x, y, z);
if(meta2 != meta)
return false;
// if(meta2 != meta)
// return false;
TileEntity tile2 = world.getTileEntity(x , y, z);
int rotation = (tile.rotation + (!isLeft?1:3)) % 4;
return tile2 != null & tile2 instanceof TileCouchWool && ((TileCouchWool)tile2).rotation == rotation;
}
private boolean compareTiles(TileCouchWool tile, int x, int y, int z, World world, int meta){
int meta2 = world.getBlockMetadata(x, y, z);
if(meta2 != meta)
return false;
// if(meta2 != meta)
// return false;
TileEntity tile2 = world.getTileEntity(x, y, z);
if(tile2 == null || !(tile2 instanceof TileCouchWool))
return false;
@@ -155,25 +166,25 @@ public class BlockCouchWool extends BlockContainer{
return tile.rotation == rotation;
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@Override
@SideOnly(Side.CLIENT)
@@ -187,4 +198,18 @@ public class BlockCouchWool extends BlockContainer{
return new TileCouchWool();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileEntity tileentity = world.getTileEntity(x, y, z);
ItemStack stack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
if (tileentity instanceof TileCouchWool) {
NBTTagCompound compound = new NBTTagCompound();
tileentity.writeToNBT(compound);
NBTTagCompound brushCompound = new NBTTagCompound();
brushCompound.setInteger(BRUSH_COLOR_TAG, compound.getInteger(BRUSH_COLOR_TAG));
stack.setTagCompound(brushCompound);
}
return stack;
}
}
@@ -3,19 +3,20 @@ package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileLamp;
import noppes.npcs.blocks.tiles.TileVariant;
public class BlockLamp extends BlockLightable{
public class BlockLantern extends BlockLightable{
public BlockLamp(boolean lit) {
super(Blocks.planks, lit);
public BlockLantern(boolean lit) {
super(Blocks.iron_block, lit);
setBlockBounds(0.3f, 0, 0.3f, 0.7f, 0.6f, 0.7f);
}
@@ -23,16 +24,16 @@ public class BlockLamp extends BlockLightable{
public int maxRotation(){
return 8;
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
if(tile.color == 2){
TileVariant tile = (TileVariant) tileentity;
if(tile.variant == 2){
float xOffset = 0;
float yOffset = 0;
if(tile.rotation == 0)
@@ -43,28 +44,28 @@ public class BlockLamp extends BlockLightable{
xOffset = 0.2f;
else if(tile.rotation == 2)
xOffset = -0.2f;
setBlockBounds(0.3f + xOffset, 0.2f, 0.3f + yOffset, 0.7f + xOffset, 0.7f, 0.7f + yOffset);
}
else
setBlockBounds(0.3f, 0, 0.3f, 0.7f, 0.6f, 0.7f);
}
@Override
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float p_149660_6_, float p_149660_7_, float p_149660_8_, int meta){
return side;
}
@Override
@Override
public void onPostBlockPlaced(World world, int x, int y, int z, int meta) {
TileLamp tile = (TileLamp) world.getTileEntity(x, y, z);
if(meta == 1)
tile.color = 0;
tile.variant = 0;
else if(meta == 0)
tile.color = 1;
tile.variant = 1;
else{
tile.color = 2;
tile.variant = 2;
if(meta == 2)
tile.rotation = 0;
else if(meta == 3)
@@ -77,10 +78,16 @@ public class BlockLamp extends BlockLightable{
world.setBlockMetadataWithNotify(x, y, z, 0, 4);
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister par1IconRegister){
this.blockIcon = par1IconRegister.registerIcon(this.getTextureName());
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int meta){
return Blocks.soul_sand.getIcon(p_149691_1_, meta);
return this.blockIcon;
}
@Override
@@ -90,11 +97,11 @@ public class BlockLamp extends BlockLightable{
@Override
public Block unlitBlock() {
return CustomItems.lamp_unlit;
return CustomItems.lantern_unlit;
}
@Override
public Block litBlock() {
return CustomItems.lamp;
return CustomItems.lantern;
}
}
@@ -6,33 +6,49 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.util.Random;
public abstract class BlockLightable extends BlockRotated{
public abstract class BlockLightable extends BlockRotated {
protected BlockLightable(Block block, boolean lit) {
super(block);
if (lit)
this.setLightLevel(1.0F);
}
public abstract Block unlitBlock();
public abstract Block litBlock();
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
TileEntity tile = world.getTileEntity(x, y, z);
if(litBlock() == this)
world.setBlock(x, y, z, unlitBlock(), world.getBlockMetadata(x, y, z), 2);
else
world.setBlock(x, y, z, litBlock(), world.getBlockMetadata(x, y, z), 2);
tile.validate();
world.setTileEntity(x, y, z, tile);
// Get the current tile entity and store its NBT
TileEntity oldTile = world.getTileEntity(x, y, z);
NBTTagCompound compound = new NBTTagCompound();
oldTile.writeToNBT(compound);
// Determine which block to set (lit/unlit) based on the current one
Block newBlock = (litBlock() == this ? unlitBlock() : litBlock());
int meta = world.getBlockMetadata(x, y, z);
// Change the block; this creates a new tile entity instance
world.setBlock(x, y, z, newBlock, meta, 2);
// Get the new tile and load the stored NBT
TileEntity newTile = world.getTileEntity(x, y, z);
if(newTile != null){
newTile.readFromNBT(compound);
newTile.markDirty();
}
world.markBlockForUpdate(x, y, z);
world.notifyBlockOfNeighborChange(x, y, z, newBlock);
return true;
}
@@ -2,6 +2,7 @@ package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -16,38 +17,36 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import noppes.npcs.Server;
import noppes.npcs.blocks.tiles.TileMailbox;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import java.util.ArrayList;
import java.util.List;
public class BlockMailbox extends BlockContainer{
public int renderId = -1;
public BlockMailbox() {
super(Material.iron);
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
if(!par1World.isRemote){
Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI, EnumGuiType.PlayerMailbox, i, j, k);
GuiOpenPacket.openGUI((EntityPlayerMP)player, EnumGuiType.PlayerMailbox, i, j, k);
}
return true;
}
@Override
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
{
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
@@ -56,40 +55,40 @@ public class BlockMailbox extends BlockContainer{
return ret;
}
@Override
@Override
public int damageDropped(int par1)
{
return par1 >> 2;
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
par1World.setBlockMetadataWithNotify(par2, par3, par4, l | par6ItemStack.getItemDamage() << 2, 2);
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int p_149691_2_)
@@ -1,5 +1,7 @@
package noppes.npcs.blocks;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.gui.GuiRedstonePacket;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
@@ -13,10 +15,8 @@ import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.Server;
import noppes.npcs.blocks.tiles.TileRedstoneBlock;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
public class BlockNpcRedstone extends BlockContainer{
public BlockNpcRedstone(){
@@ -32,8 +32,8 @@ public class BlockNpcRedstone extends BlockContainer{
TileEntity tile = par1World.getTileEntity(i, j, k);
NBTTagCompound compound = new NBTTagCompound();
tile.writeToNBT(compound);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI_REDSTONE, compound);
return true;
PacketHandler.Instance.sendToPlayer(new GuiRedstonePacket(compound), (EntityPlayerMP)player);
return true;
}
return false;
}
@@ -14,25 +14,25 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileNpcContainer;
import noppes.npcs.blocks.tiles.TilePedestal;
import noppes.npcs.blocks.tiles.TileVariant;
import java.util.List;
public class BlockPedestal extends BlockTrigger{
public BlockPedestal() {
super(Blocks.stone);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
if(par1World.isRemote)
return true;
TilePedestal tile = (TilePedestal) par1World.getTileEntity(i, j, k);
ItemStack item = player.getCurrentEquippedItem();
ItemStack weapon = tile.getStackInSlot(0);
if(item == null && weapon != null){
@@ -51,8 +51,8 @@ public class BlockPedestal extends BlockTrigger{
}
return true;
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -61,18 +61,18 @@ public class BlockPedestal extends BlockTrigger{
par3List.add(new ItemStack(par1, 1, 4));
}
@Override
@Override
public int damageDropped(int par1){
return par1;
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
if(tile.rotation % 2 == 0){
setBlockBounds(0f, 0, 0.2f, 1, 0.5f, 0.8f );
}
@@ -81,12 +81,12 @@ public class BlockPedestal extends BlockTrigger{
}
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p_149691_1_, int meta)
@@ -108,7 +108,7 @@ public class BlockPedestal extends BlockTrigger{
public TileEntity createNewTileEntity(World var1, int var2) {
return new TilePedestal();
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_){
TileNpcContainer tile = (TileNpcContainer)world.getTileEntity(x, y, z);
@@ -13,9 +13,9 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileVariant;
public abstract class BlockRotated extends BlockContainer{
public abstract class BlockRotated extends BlockContainer {
private Block block;
protected BlockRotated(Block block) {
super(block.getMaterial());
@@ -24,38 +24,38 @@ public abstract class BlockRotated extends BlockContainer{
public int renderId = -1;
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * maxRotation() / 360.0F) + 0.5D) & (maxRotation() - 1);
l %= maxRotation();
TileColorable tile = (TileColorable) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
TileVariant tile = (TileVariant) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z){
setBlockBoundsBasedOnState(world, x, y, z);
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
public int maxRotation(){
return 4;
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side){
return true;
}
@@ -64,7 +64,7 @@ public abstract class BlockRotated extends BlockContainer{
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@Override
@SideOnly(Side.CLIENT)
@@ -9,30 +9,30 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileShelf;
import noppes.npcs.blocks.tiles.TileVariant;
import java.util.List;
public class BlockShelf extends BlockRotated{
public BlockShelf() {
super(Blocks.planks);
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
}
@Override
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int x, int y, int z){
setBlockBoundsBasedOnState(p_149668_1_, x, y, z);
return AxisAlignedBB.getBoundingBox(x + minX, y + 0.9f, z + minZ, x + maxX, y + 1, z + maxZ);
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -41,14 +41,14 @@ public class BlockShelf extends BlockRotated{
par3List.add(new ItemStack(par1, 1, 4));
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
float xStart = 0;
float zStart = 0;
float xEnd = 1;
@@ -64,7 +64,7 @@ public class BlockShelf extends BlockRotated{
setBlockBounds(xStart, 0.44f, zStart, xEnd, 1, zEnd);
}
@Override
@Override
public int damageDropped(int par1){
return par1;
}
@@ -0,0 +1,158 @@
package noppes.npcs.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileShortLamp;
import java.util.List;
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class BlockShortLamp extends BlockContainer {
public int renderId = -1;
public BlockShortLamp() {
super(Material.wood);
setLightLevel(1);
setBlockBounds(0.25f, 0, 0.25f, 0.75f, 1, 0.75f);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player,
int side, float hitX, float hitY, float hitZ) {
ItemStack item = player.inventory.getCurrentItem();
if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int meta = world.getBlockMetadata(x, y, z);
TileColorable tile = (TileColorable) world.getTileEntity(x, y, z);
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
if (tile.color != color) {
NoppesUtilServer.consumeItemStack(1, player);
tile.color = color;
world.markBlockForUpdate(x, y, z);
}
return true;
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
setBlockBoundsBasedOnState(world, x, y, z);
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
list.add(new ItemStack(item, 1, 0));
list.add(new ItemStack(item, 1, 1));
list.add(new ItemStack(item, 1, 2));
list.add(new ItemStack(item, 1, 3));
list.add(new ItemStack(item, 1, 4));
}
@Override
public int damageDropped(int meta) {
return meta;
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z,
EntityLivingBase entity, ItemStack stack) {
int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileColorable tile = (TileColorable) world.getTileEntity(x, y, z);
tile.rotation = l;
tile.color = colorTableInts[15 - stack.getItemDamage()];
if(stack.hasTagCompound() && stack.getTagCompound().hasKey(BRUSH_COLOR_TAG)){
tile.color = stack.getTagCompound().getInteger(BRUSH_COLOR_TAG);
}
world.setBlockMetadataWithNotify(x, y, z, stack.getItemDamage(), 2);
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
setBlockBounds(0.25f, 0, 0.25f, 0.75f, 1, 0.75f);
}
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
public int getRenderType(){
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister reg) {
// Optional icon registration
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
if(meta == 1)
return Blocks.stone.getIcon(side, 0);
else if(meta == 2)
return Blocks.iron_block.getIcon(side, 0);
else if(meta == 3)
return Blocks.gold_block.getIcon(side, 0);
else if(meta == 4)
return Blocks.diamond_block.getIcon(side, 0);
return Blocks.planks.getIcon(side, 0);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileShortLamp();
}
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
super.onBlockHarvested(world, x, y, z, meta, player);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileEntity tileentity = world.getTileEntity(x, y, z);
ItemStack stack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
if (tileentity instanceof TileShortLamp) {
NBTTagCompound compound = new NBTTagCompound();
tileentity.writeToNBT(compound);
NBTTagCompound brushCompound = new NBTTagCompound();
brushCompound.setInteger(BRUSH_COLOR_TAG, compound.getInteger(BRUSH_COLOR_TAG));
stack.setTagCompound(brushCompound);
}
return stack;
}
}
+11 -11
View File
@@ -12,8 +12,8 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileBanner;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileSign;
import noppes.npcs.blocks.tiles.TileVariant;
import java.util.List;
@@ -23,7 +23,7 @@ public class BlockSign extends BlockRotated{
super(Blocks.planks);
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
@@ -36,13 +36,13 @@ public class BlockSign extends BlockRotated{
((EntityPlayer)par5EntityLivingBase).addChatComponentMessage(new ChatComponentTranslation("availability.editIcon"));
}
@Override
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
TileBanner tile = (TileBanner) world.getTileEntity(x, y, z);
return tile.canEdit();
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -51,22 +51,22 @@ public class BlockSign extends BlockRotated{
par3List.add(new ItemStack(par1, 1, 4));
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
if(tile.rotation % 2 == 1)
setBlockBounds(0, 0.3f, 0.3f, 1, 1, 0.7f);
else
else
setBlockBounds(0.3f, 0.3f, 0, 0.7f, 1, 1);
}
@Override
@Override
public int damageDropped(int par1){
return par1;
}
@@ -16,13 +16,13 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileStool;
import noppes.npcs.blocks.tiles.TileVariant;
import java.util.List;
public class BlockStool extends BlockContainer{
public int renderId = -1;
public BlockStool() {
@@ -30,12 +30,12 @@ public class BlockStool extends BlockContainer{
setBlockBounds(0.1f, 0, 0.1f, 0.9f, 0.6f, 0.9f);
}
@Override
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int x, int y, int z){
return AxisAlignedBB.getBoundingBox(x + 0.1f, y, z + 0.1f, x + 0.9f, y + 0.5f, z + 0.9f);
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -45,48 +45,48 @@ public class BlockStool extends BlockContainer{
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_){
return BlockChair.MountBlock(world, x, y, z, player);
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileColorable tile = (TileColorable) par1World.getTileEntity(par2, par3, par4);
TileVariant tile = (TileVariant) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@Override
@SideOnly(Side.CLIENT)
@@ -11,14 +11,13 @@ import noppes.npcs.blocks.tiles.TileTable;
import java.util.List;
public class BlockTable extends BlockRotated{
public class BlockTable extends BlockRotated {
public BlockTable() {
super(Blocks.planks);
this.setLightOpacity(-1);
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -28,15 +27,14 @@ public class BlockTable extends BlockRotated{
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public int damageDropped(int par1){
return par1;
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
}
@@ -10,13 +10,14 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.NoppesUtilServer;
@@ -25,8 +26,11 @@ import noppes.npcs.blocks.tiles.TileTallLamp;
import java.util.List;
public class BlockTallLamp extends BlockContainer{
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class BlockTallLamp extends BlockContainer {
public int renderId = -1;
public BlockTallLamp() {
@@ -34,16 +38,16 @@ public class BlockTallLamp extends BlockContainer{
setBlockBounds(0, 0, 0, 1, 2, 1);
setLightLevel(1);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
ItemStack item = player.inventory.getCurrentItem();
if(item == null || item.getItem() != Items.dye)
return false;
if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int meta = par1World.getBlockMetadata(i, j, k);
if(meta >= 7)
j--;
TileColorable tile = (TileColorable) par1World.getTileEntity(i, j, k);
int color = BlockColored.func_150031_c(item.getItemDamage());
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
if(tile.color != color){
NoppesUtilServer.consumeItemStack(1, player);
tile.color = color;
@@ -56,7 +60,7 @@ public class BlockTallLamp extends BlockContainer{
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -65,32 +69,40 @@ public class BlockTallLamp extends BlockContainer{
par3List.add(new ItemStack(par1, 1, 4));
}
@Override
@Override
public int damageDropped(int par1){
return par1 % 7;
}
@Override
@Override
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
return super.canPlaceBlockAt(world, x, y, z) && world.isAirBlock(x, y + 1, z);
}
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
if(!par1World.isAirBlock(par2, par3 + 1, par4)){
par1World.setBlockToAir(par2, par3, par4);
}
else{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileColorable tile = (TileColorable) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
tile.color = 15 - par6ItemStack.getItemDamage();
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
tile.color = colorTableInts[15 - par6ItemStack.getItemDamage()];
if(par6ItemStack.hasTagCompound() && par6ItemStack.getTagCompound().hasKey(BRUSH_COLOR_TAG)){
tile.color = par6ItemStack.getTagCompound().getInteger(BRUSH_COLOR_TAG);
}
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
par1World.setBlock(par2, par3 + 1, par4, this, par6ItemStack.getItemDamage() + 7, 2);
}
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
int meta = world.getBlockMetadata(x, y, z);
if(meta >= 7)
@@ -99,26 +111,24 @@ public class BlockTallLamp extends BlockContainer{
setBlockBounds(0, 0, 0, 1, 2, 1);
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
{}
@Override
@SideOnly(Side.CLIENT)
@@ -149,8 +159,27 @@ public class BlockTallLamp extends BlockContainer{
{
if (p_149681_5_ >= 7 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this)
p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_);
else if (p_149681_5_ < 7 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ + 1, p_149681_4_) == this)
p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ + 1, p_149681_4_);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if(meta >= 7)
y--;
TileEntity tileentity = world.getTileEntity(x, y, z);
ItemStack stack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
if (tileentity instanceof TileTallLamp) {
NBTTagCompound compound = new NBTTagCompound();
tileentity.writeToNBT(compound);
NBTTagCompound brushCompound = new NBTTagCompound();
brushCompound.setInteger(BRUSH_COLOR_TAG, compound.getInteger(BRUSH_COLOR_TAG));
stack.setTagCompound(brushCompound);
}
return stack;
}
}
@@ -22,8 +22,8 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileBigSign;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileTombstone;
import noppes.npcs.blocks.tiles.TileVariant;
import noppes.npcs.constants.EnumGuiType;
import java.util.List;
@@ -79,11 +79,11 @@ public class BlockTombstone extends BlockContainer{
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
if(tile.rotation % 2 == 0)
setBlockBounds(0, 0, 0.3f, 1, 1, 0.7f);
else
@@ -3,7 +3,7 @@ package noppes.npcs.blocks;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileVariant;
public abstract class BlockTrigger extends BlockRotated{
@@ -23,7 +23,7 @@ public abstract class BlockTrigger extends BlockRotated{
@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int p_149709_5_){
TileColorable tile = (TileColorable)world.getTileEntity(x, y, z);
TileVariant tile = (TileVariant)world.getTileEntity(x, y, z);
if(tile != null)
return tile.powerProvided();
return 0;
@@ -10,28 +10,29 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.*;
import net.minecraft.world.World;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileWallBanner;
import java.util.List;
import static kamkeel.npcs.util.ColorUtil.colorTableInts;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class BlockWallBanner extends BlockContainer{
public int renderId = -1;
public BlockWallBanner() {
super(Material.rock);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){
ItemStack item = player.inventory.getCurrentItem();
if(item == null)
@@ -39,10 +40,10 @@ public class BlockWallBanner extends BlockContainer{
TileWallBanner tile = (TileWallBanner) par1World.getTileEntity(i, j, k);
if(tile.canEdit())
return true;
else if(item.getItem() != Items.dye)
return false;
int color = BlockColored.func_150031_c(item.getItemDamage());
else if(TileColorable.allowColorChange(item) != TileColorable.ColorChangeType.DYE)
return false;
int color = colorTableInts[BlockColored.func_150031_c(item.getItemDamage())];
if(tile.color != color){
NoppesUtilServer.consumeItemStack(1, player);
tile.color = color;
@@ -51,28 +52,32 @@ public class BlockWallBanner extends BlockContainer{
return true;
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileWallBanner tile = (TileWallBanner) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
tile.color = 15 - par6ItemStack.getItemDamage();
tile.rotation = l;
tile.color = colorTableInts[15 - par6ItemStack.getItemDamage()];
if(par6ItemStack.hasTagCompound() && par6ItemStack.getTagCompound().hasKey(BRUSH_COLOR_TAG)){
tile.color = par6ItemStack.getTagCompound().getInteger(BRUSH_COLOR_TAG);
}
tile.time = System.currentTimeMillis();
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage(), 2);
if(par5EntityLivingBase instanceof EntityPlayer && par1World.isRemote)
((EntityPlayer)par5EntityLivingBase).addChatComponentMessage(new ChatComponentTranslation("availability.editIcon"));
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_)
{
return null;
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -82,31 +87,31 @@ public class BlockWallBanner extends BlockContainer{
}
@Override
@Override
public int damageDropped(int par1)
{
return par1;
}
@Override
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
@Override
public boolean renderAsNormalBlock(){
return false;
}
@Override
@Override
public int getRenderType(){
return renderId;
return renderId;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
}
@Override
@SideOnly(Side.CLIENT)
@@ -128,4 +133,19 @@ public class BlockWallBanner extends BlockContainer{
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileWallBanner();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileEntity tileentity = world.getTileEntity(x, y, z);
ItemStack stack = new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
if (tileentity instanceof TileWallBanner) {
NBTTagCompound compound = new NBTTagCompound();
tileentity.writeToNBT(compound);
NBTTagCompound brushCompound = new NBTTagCompound();
brushCompound.setInteger(BRUSH_COLOR_TAG, compound.getInteger(BRUSH_COLOR_TAG));
stack.setTagCompound(brushCompound);
}
return stack;
}
}
@@ -1,5 +1,7 @@
package noppes.npcs.blocks;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.gui.GuiWaypointPacket;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
@@ -12,10 +14,8 @@ import net.minecraft.world.World;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.Server;
import noppes.npcs.blocks.tiles.TileWaypoint;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
public class BlockWaypoint extends BlockContainer{
@@ -34,7 +34,7 @@ public class BlockWaypoint extends BlockContainer{
TileEntity tile = par1World.getTileEntity(i, j, k);
NBTTagCompound compound = new NBTTagCompound();
tile.writeToNBT(compound);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI_WAYPOINT, compound);
PacketHandler.Instance.sendToPlayer(new GuiWaypointPacket(compound), (EntityPlayerMP)player);
return true;
}
return false;
@@ -13,8 +13,8 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import noppes.npcs.blocks.tiles.TileColorable;
import noppes.npcs.blocks.tiles.TileNpcContainer;
import noppes.npcs.blocks.tiles.TileVariant;
import noppes.npcs.blocks.tiles.TileWeaponRack;
import java.util.List;
@@ -24,7 +24,7 @@ public class BlockWeaponRack extends BlockTrigger{
public BlockWeaponRack() {
super(Blocks.planks);
}
@Override
@Override
public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
if(par1World.isRemote)
return true;
@@ -39,7 +39,7 @@ public class BlockWeaponRack extends BlockTrigger{
hit = 1 - hitZ;
if(tile.rotation == 1)
hit = hitZ;
int selected = 2 - (int) (hit / 0.34);
ItemStack item = player.getCurrentEquippedItem();
ItemStack weapon = tile.getStackInSlot(selected);
@@ -59,7 +59,7 @@ public class BlockWeaponRack extends BlockTrigger{
}
return true;
}
@Override
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
@@ -69,13 +69,13 @@ public class BlockWeaponRack extends BlockTrigger{
par3List.add(new ItemStack(par1, 1, 5));
}
@Override
@Override
public int damageDropped(int par1){
return par1 % 7;
}
@Override
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){
if(!par1World.isAirBlock(par2, par3 + 1, par4)){
par1World.setBlockToAir(par2, par3, par4);
@@ -83,31 +83,31 @@ public class BlockWeaponRack extends BlockTrigger{
else{
int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
l %= 4;
TileColorable tile = (TileColorable) par1World.getTileEntity(par2, par3, par4);
TileVariant tile = (TileVariant) par1World.getTileEntity(par2, par3, par4);
tile.rotation = l;
par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2);
par1World.setBlock(par2, par3 + 1, par4, this, par6ItemStack.getItemDamage() + 7, 2);
}
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z){
setBlockBoundsBasedOnState(world, x, y, z);
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
@Override
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
int meta = world.getBlockMetadata(x, y, z);
if(meta >= 7)
y--;
TileEntity tileentity = world.getTileEntity(x, y, z);
if(!(tileentity instanceof TileColorable)){
if(!(tileentity instanceof TileVariant)){
super.setBlockBoundsBasedOnState(world, x, y, z);
return;
}
TileColorable tile = (TileColorable) tileentity;
TileVariant tile = (TileVariant) tileentity;
float xStart = 0;
float zStart = 0;
float xEnd = 1;
@@ -139,7 +139,7 @@ public class BlockWeaponRack extends BlockTrigger{
{
if (p_149681_5_ >= 7 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this)
p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_);
else if (p_149681_5_ < 7 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ + 1, p_149681_4_) == this)
p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ + 1, p_149681_4_);
}
@@ -0,0 +1,11 @@
package noppes.npcs.blocks.tiles;
import net.minecraft.item.ItemStack;
public interface ITileIcon {
boolean canEdit();
void setTime(long time);
void setIcon(ItemStack stack);
}
@@ -5,10 +5,10 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import noppes.npcs.constants.EnumBannerVariant;
public class TileBanner extends TileColorable {
public class TileBanner extends TileColorable implements ITileIcon {
public ItemStack icon;
public EnumBannerVariant variant = EnumBannerVariant.Normal;
public EnumBannerVariant bannerTrim = EnumBannerVariant.Normal;
public long time = 0;
public void readFromNBT(NBTTagCompound compound){
@@ -17,9 +17,9 @@ public class TileBanner extends TileColorable {
int variantIndex = compound.getInteger("BannerVariant");
if (variantIndex >= 0 && variantIndex < EnumBannerVariant.values().length) {
variant = EnumBannerVariant.values()[variantIndex];
bannerTrim = EnumBannerVariant.values()[variantIndex];
} else {
variant = EnumBannerVariant.Normal;
bannerTrim = EnumBannerVariant.Normal;
}
}
@@ -27,7 +27,7 @@ public class TileBanner extends TileColorable {
super.writeToNBT(compound);
if(icon != null)
compound.setTag("BannerIcon", icon.writeToNBT(new NBTTagCompound()));
compound.setInteger("BannerVariant", variant.ordinal());
compound.setInteger("BannerVariant", bannerTrim.ordinal());
}
@Override
@@ -35,7 +35,18 @@ public class TileBanner extends TileColorable {
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 2, zCoord + 1);
}
public boolean canEdit(){
@Override
public boolean canEdit(){
return System.currentTimeMillis() - time < 20000;
}
@Override
public void setTime(long time){
this.time = time;
}
@Override
public void setIcon(ItemStack stack){
this.icon = stack;
}
}
@@ -1,5 +1,5 @@
package noppes.npcs.blocks.tiles;
public class TileBeam extends TileColorable {
public class TileBeam extends TileVariant {
}
@@ -1,15 +1,24 @@
package noppes.npcs.blocks.tiles;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.EnumSkyBlock;
public class TileBlockAnvil extends TileEntity {
public TileBlockAnvil(){
public boolean firstTick = true;
}
public TileBlockAnvil(){}
public boolean canUpdate(){
return false;
return true;
}
@Override
public void updateEntity() {
if (hasWorldObj() && firstTick && !getWorldObj().isRemote) {
firstTick = false;
getWorldObj().updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord);
getWorldObj().markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
@@ -5,7 +5,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class TileBook extends TileColorable {
public class TileBook extends TileVariant {
public ItemStack book = new ItemStack(Items.writable_book);
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
@@ -1,11 +1,13 @@
package noppes.npcs.blocks.tiles;
import net.minecraft.block.Block;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import java.util.Random;
public class TileCampfire extends TileColorable {
public class TileCampfire extends TileVariant {
public static final Random RAND = new Random();
private boolean rainAndSky = false;
@@ -53,6 +55,7 @@ public class TileCampfire extends TileColorable {
public boolean isLit()
{
return this.getBlockMetadata() == 0;
Block block = this.getBlockType();
return block == CustomItems.campfire;
}
}
@@ -1,5 +1,5 @@
package noppes.npcs.blocks.tiles;
public class TileChair extends TileColorable {
public class TileChair extends TileVariant {
}
@@ -1,53 +1,48 @@
package noppes.npcs.blocks.tiles;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import noppes.npcs.items.ItemNpcTool;
public class TileColorable extends TileEntity {
public int color = 14;
public int rotation;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class TileColorable extends TileVariant {
public int color = 0xFFFFFF;
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
color = compound.getInteger("BannerColor");
rotation = compound.getInteger("BannerRotation");
color = compound.getInteger(BRUSH_COLOR_TAG);
}
public void writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
compound.setInteger("BannerColor", color);
compound.setInteger("BannerRotation", rotation);
}
public boolean canUpdate(){
return false;
compound.setInteger(BRUSH_COLOR_TAG, color);
}
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt){
NBTTagCompound compound = pkt.func_148857_g();
readFromNBT(compound);
public void setColor(int color){
this.color = color;
this.markDirty();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
@Override
public Packet getDescriptionPacket(){
NBTTagCompound compound = new NBTTagCompound();
writeToNBT(compound);
compound.removeTag("Items");
S35PacketUpdateTileEntity packet = new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, compound);
return packet;
public static ColorChangeType allowColorChange(ItemStack stack){
if(stack == null || stack.getItem() == null)
return ColorChangeType.NONE;
if(stack.getItem() == Items.dye)
return ColorChangeType.DYE;
if(ItemNpcTool.isPaintbrush(stack))
return ColorChangeType.PAINTBRUSH;
return ColorChangeType.NONE;
}
@Override
public AxisAlignedBB getRenderBoundingBox(){
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
public enum ColorChangeType {
NONE,
DYE,
PAINTBRUSH
}
public int powerProvided(){
return 0;
}
}
@@ -3,10 +3,10 @@ package noppes.npcs.blocks.tiles;
import net.minecraft.nbt.NBTTagCompound;
public class TileCouchWood extends TileColorable {
public class TileCouchWood extends TileVariant {
public boolean hasLeft = false;
public boolean hasRight = false;
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
@@ -8,7 +8,6 @@ public class TileCouchWool extends TileColorable {
public boolean hasRight = false;
public boolean hasCornerLeft = false;
public boolean hasCornerRight = false;
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
@@ -2,6 +2,6 @@ package noppes.npcs.blocks.tiles;
public class TileLamp extends TileColorable {
public class TileLamp extends TileVariant {
}
@@ -9,11 +9,11 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
public abstract class TileNpcContainer extends TileColorable implements IInventory {
public abstract class TileNpcContainer extends TileVariant implements IInventory {
private ItemStack[] chestContents;
public String customName = "";
public int playerUsing = 0;
public TileNpcContainer(){
chestContents = new ItemStack[getSizeInventory()];
}
@@ -66,7 +66,7 @@ public abstract class TileNpcContainer extends TileColorable implements IInvento
compound.setString("CustomName", this.customName);
}
}
public boolean receiveClientEvent(int p_145842_1_, int p_145842_2_)
{
if (p_145842_1_ == 1)
@@ -152,7 +152,7 @@ public abstract class TileNpcContainer extends TileColorable implements IInvento
public String getInventoryName() {
return hasCustomInventoryName()?customName:getName();
}
public abstract String getName();
@Override
@@ -190,7 +190,7 @@ public abstract class TileNpcContainer extends TileColorable implements IInvento
ItemStack itemstack = this.getStackInSlot(i1);
if (itemstack == null)
continue;
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityitem;
@@ -212,11 +212,11 @@ public abstract class TileNpcContainer extends TileColorable implements IInvento
if (itemstack.hasTagCompound()){
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
}
}
}
}
@@ -1,5 +1,5 @@
package noppes.npcs.blocks.tiles;
public class TileShelf extends TileColorable {
public class TileShelf extends TileVariant {
}
@@ -0,0 +1,12 @@
package noppes.npcs.blocks.tiles;
import net.minecraft.util.AxisAlignedBB;
public class TileShortLamp extends TileColorable {
@Override
public AxisAlignedBB getRenderBoundingBox(){
return AxisAlignedBB.getBoundingBox(xCoord + 0.25f, yCoord, zCoord + 0.25f, xCoord + 0.75f, yCoord + 1, zCoord + 0.75f);
}
}
@@ -1,6 +1,42 @@
package noppes.npcs.blocks.tiles;
public class TileSign extends TileBanner {
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
public class TileSign extends TileVariant implements ITileIcon {
public ItemStack icon;
public long time = 0;
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
icon = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("BannerIcon"));
}
public void writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
if(icon != null)
compound.setTag("BannerIcon", icon.writeToNBT(new NBTTagCompound()));
}
@Override
public AxisAlignedBB getRenderBoundingBox(){
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 2, zCoord + 1);
}
public boolean canEdit(){
return System.currentTimeMillis() - time < 20000;
}
@Override
public void setTime(long time) {
this.time = time;
}
@Override
public void setIcon(ItemStack stack) {
this.icon = stack;
}
}
@@ -1,5 +1,5 @@
package noppes.npcs.blocks.tiles;
public class TileStool extends TileColorable {
public class TileStool extends TileVariant {
}
@@ -2,7 +2,7 @@ package noppes.npcs.blocks.tiles;
public class TileTable extends TileColorable{
public class TileTable extends TileVariant {
}
@@ -0,0 +1,90 @@
package noppes.npcs.blocks.tiles;
import kamkeel.npcs.util.ColorUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG;
public class TileVariant extends TileEntity {
public static int variantVersion = 1;
int version = variantVersion;
public int variant = 14;
public int rotation;
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
version = compound.getInteger("CNPCVersion");
FixTileData(version, compound, this);
variant = compound.getInteger("CNPCVariant");
rotation = compound.getInteger("CNPCRotation");
}
public void writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
compound.setInteger("CNPCVersion", version);
compound.setInteger("CNPCVariant", variant);
compound.setInteger("CNPCRotation", rotation);
}
public boolean canUpdate(){
return false;
}
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt){
NBTTagCompound compound = pkt.func_148857_g();
readFromNBT(compound);
}
@Override
public Packet getDescriptionPacket(){
NBTTagCompound compound = new NBTTagCompound();
writeToNBT(compound);
compound.removeTag("Items");
S35PacketUpdateTileEntity packet = new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, compound);
return packet;
}
@Override
public AxisAlignedBB getRenderBoundingBox(){
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
}
public int powerProvided(){
return 0;
}
public static void FixTileData(int version, NBTTagCompound compound, TileEntity tileEntity){
if(version == variantVersion)
return;
boolean fixMade = false;
if(version < 1){
if(compound.hasKey("BannerColor")){
int bannerColor = compound.getInteger("BannerColor");
if(isColorTile(tileEntity)){
compound.setInteger(BRUSH_COLOR_TAG, ColorUtil.colorTableInts[bannerColor]);
}
compound.setInteger("CNPCVariant", bannerColor);
fixMade = true;
}
if(compound.hasKey("BannerRotation")){
compound.setInteger("CNPCRotation", compound.getInteger("BannerRotation"));
fixMade = true;
}
}
if(fixMade)
tileEntity.markDirty();
}
public static boolean isColorTile(TileEntity tileEntity){
return tileEntity instanceof TileColorable;
}
}
@@ -42,10 +42,10 @@ public class AssetsBrowser {
private void getFiles() {
folders.clear();
files.clear();
ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository();
SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
Map<String, IResourceManager> map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2);
HashSet<String> set = new HashSet<String>();
for(String name: map.keySet()){
@@ -62,7 +62,7 @@ public class AssetsBrowser {
}
}
}
for(String file : set){
progressFile(new File(file));
}
@@ -97,7 +97,7 @@ public class AssetsBrowser {
ZipEntry zipentry = entries.nextElement();
String entryName = zipentry.getName();
checkFile(entryName);
}
zip.close();
}
@@ -109,7 +109,7 @@ public class AssetsBrowser {
e.printStackTrace();
}
}
private void checkFolder(File file, int length){
File[] files = file.listFiles();
if(files == null){
@@ -128,7 +128,7 @@ public class AssetsBrowser {
checkFile(name);
}
}
private void checkFile(String name){
if(!name.startsWith("/"))
name = "/" + name;
@@ -1,24 +0,0 @@
package noppes.npcs.client;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumPacketServer;
import java.io.IOException;
public class Client {
public static void sendData(final EnumPacketServer enu, final Object... obs) {
ByteBuf buffer = Unpooled.buffer();
try {
if(!Server.fillBuffer(buffer, enu, obs))
return;
CustomNpcs.Channel.sendToServer(new FMLProxyPacket(buffer, "CustomNPCs"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -1,11 +1,16 @@
package noppes.npcs.client;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.select.GuiSoundSelection;
import noppes.npcs.client.gui.select.GuiTextureSelection;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.controllers.data.*;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.util.CacheHashMap;
import java.util.HashMap;
@@ -13,15 +18,17 @@ import java.util.UUID;
public class ClientCacheHandler {
private static final CacheHashMap<String, CacheHashMap.CachedObject<ImageData>> imageDataCache = new CacheHashMap<>((long) ConfigClient.CacheLife * 60 * 1000);
public static final HashMap<Integer, Animation> animationCache = new HashMap<>();
public static PlayerData playerData = new PlayerData();
public static OverlayQuestTracking questTrackingOverlay = null;
public static HashMap<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
public static Party party;
public static boolean allowProfiles = true;
public static boolean allowParties = true;
public static ImageData getImageData(String directory) {
synchronized (imageDataCache) {
if (!imageDataCache.containsKey(directory)) {
@@ -48,17 +55,25 @@ public class ClientCacheHandler {
public static void clearCache() {
ClientCacheHandler.imageDataCache.clear();
ClientCacheHandler.animationCache.clear();
ClientCacheHandler.questTrackingOverlay = null;
ClientCacheHandler.customOverlays.clear();
ClientCacheHandler.skinOverlays.clear();
ClientCacheHandler.playerAnimations.clear();
ClientCacheHandler.playerData.animationData.clearCache();
// Clear Texture Caches
GuiSoundSelection.cachedDomains.clear();
GuiTextureSelection.cachedTextures.clear();
// Clear music/bard sounds
MusicController.Instance.stopAllSounds();
}
public static void clearSkinCache() {
ClientCacheHandler.imageDataCache.clear();
ClientCacheHandler.customOverlays.clear();
ClientCacheHandler.skinOverlays.clear();
// Clear Texture Caches
GuiSoundSelection.cachedDomains.clear();
GuiTextureSelection.cachedTextures.clear();
}
}
@@ -1,9 +1,7 @@
package noppes.npcs.client;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.entity.EntityClientPlayerMP;
@@ -13,27 +11,28 @@ import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.client.event.*;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.hud.ClientHudManager;
import noppes.npcs.client.gui.hud.CompassHudComponent;
import noppes.npcs.client.gui.hud.EnumHudComponent;
import noppes.npcs.client.gui.hud.QuestTrackingComponent;
import noppes.npcs.client.renderer.MarkRenderer;
import noppes.npcs.client.renderer.RenderCNPCPlayer;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.MarkType;
import noppes.npcs.controllers.data.*;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
import java.lang.reflect.Field;
import java.util.*;
public class ClientEventHandler {
public static final RenderCNPCPlayer renderCNPCSelf = new RenderCNPCPlayer();
public static final RenderCNPCPlayer renderCNPCPlayer = new RenderCNPCPlayer();
public static HashMap<Integer,Long> disabledButtonTimes = new HashMap<>();
@@ -95,9 +94,12 @@ public class ClientEventHandler {
overlayCustom.renderGameOverlay(event.partialTicks);
}
if (ClientCacheHandler.questTrackingOverlay != null) {
ClientCacheHandler.questTrackingOverlay.renderGameOverlay(event.partialTicks);
if(ClientHudManager.getInstance().getHudComponents().isEmpty()){
ClientHudManager.getInstance().registerHud(EnumHudComponent.QuestTracker, new QuestTrackingComponent(Minecraft.getMinecraft()));
ClientHudManager.getInstance().registerHud(EnumHudComponent.QuestCompass, new CompassHudComponent(Minecraft.getMinecraft()));
}
ClientHudManager.getInstance().renderAllHUDs(event.partialTicks);
}
}
@@ -109,8 +111,17 @@ public class ClientEventHandler {
ClientEventHandler.renderer = event.renderer;
ClientEventHandler.partialRenderTick = Minecraft.getMinecraft().timer.renderPartialTicks;
if (event.entity instanceof EntityClientPlayerMP) {
Render render = RenderManager.instance.getEntityClassRenderObject(event.entity.getClass());
this.setOriginalPlayerParts(event.entity);
}
@SubscribeEvent
public void renderHand(RenderHandEvent event) {
this.setOriginalPlayerParts(Minecraft.getMinecraft().thePlayer);
}
private void setOriginalPlayerParts(Entity entity) {
if (entity instanceof EntityClientPlayerMP) {
Render render = RenderManager.instance.getEntityClassRenderObject(entity.getClass());
if (!processedPlayerRenderers.contains(render)) {
processedPlayerRenderers.add(render);
Collection<ModelRenderer> modelRenderers = getAllModelRenderers(render);
@@ -128,10 +139,7 @@ public class ClientEventHandler {
@SubscribeEvent
public void onRenderEntity(RenderLivingEvent.Post event) {
AnimationData data = null;
if (event.entity instanceof EntityNPCInterface) {
data = ClientEventHandler.renderingNpc.display.animationData;
MarkData markData = MarkData.get((EntityNPCInterface) event.entity);
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(PlayerData.get(player) != null){
@@ -143,10 +151,6 @@ public class ClientEventHandler {
}
}
} else if (event.entity instanceof EntityPlayer) {
if (ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) {
data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID());
}
for (Map.Entry<ModelRenderer,FramePart> entry : ClientEventHandler.originalValues.entrySet()) {
ModelRenderer renderer = entry.getKey();
FramePart part = entry.getValue();
@@ -161,35 +165,9 @@ public class ClientEventHandler {
ClientEventHandler.playerModel = null;
}
if (data != null && data.isActive() && !Minecraft.getMinecraft().isGamePaused()) {
Animation animation = data.animation;
if (data.isActive() && animation.currentFrame().useRenderTicks()) {
animation.increaseTime();
}
}
ClientEventHandler.renderingNpc = null;
}
@SubscribeEvent
public void onUpdateEntity(LivingEvent.LivingUpdateEvent event) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
AnimationData data = null;
if (event.entity instanceof EntityNPCInterface) {
data = ((EntityNPCInterface) event.entity).display.animationData;
} else if (event.entity instanceof EntityPlayer && ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) {
data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID());
}
if (data != null && data.isActive()) {
Animation animation = data.animation;
if (data.isActive() && !animation.currentFrame().useRenderTicks()) {
animation.increaseTime();
}
}
}
}
@SubscribeEvent
public void onRenderPlayer(RenderPlayerEvent.Pre event) {
ClientEventHandler.renderingPlayer = event.entityPlayer;
@@ -5,8 +5,7 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import kamkeel.addon.client.DBCClient;
import net.minecraft.block.Block;
import kamkeel.npcs.addon.client.DBCClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.model.ModelBiped;
@@ -17,6 +16,7 @@ import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@@ -29,7 +29,10 @@ import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.FakePlayer;
import noppes.npcs.*;
import noppes.npcs.CommonProxy;
import noppes.npcs.CustomItems;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.IWorld;
import noppes.npcs.blocks.tiles.*;
import noppes.npcs.client.controllers.*;
@@ -40,6 +43,7 @@ import noppes.npcs.client.fx.EntityRainbowFX;
import noppes.npcs.client.gui.*;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.global.*;
import noppes.npcs.client.gui.item.GuiNpcPaintbrush;
import noppes.npcs.client.gui.mainmenu.*;
import noppes.npcs.client.gui.player.*;
import noppes.npcs.client.gui.player.companion.GuiNpcCompanionInv;
@@ -53,17 +57,19 @@ import noppes.npcs.client.gui.script.GuiScriptItem;
import noppes.npcs.client.model.*;
import noppes.npcs.client.renderer.*;
import noppes.npcs.client.renderer.blocks.*;
import noppes.npcs.client.renderer.items.CustomItemRenderer;
import noppes.npcs.client.renderer.items.ScriptedBlockItemRenderer;
import noppes.npcs.client.renderer.items.*;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.StringCache;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.containers.*;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.*;
import noppes.npcs.entity.data.ModelData;
import noppes.npcs.entity.data.ModelPartData;
import noppes.npcs.items.ItemLinked;
import noppes.npcs.items.ItemNpcTool;
import noppes.npcs.items.ItemScripted;
import org.lwjgl.input.Keyboard;
import tconstruct.client.tabs.InventoryTabCustomNpc;
@@ -84,8 +90,6 @@ public class ClientProxy extends CommonProxy {
public void load() {
Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize);
createFolders();
CustomNpcs.Channel.register(new PacketHandlerClient());
CustomNpcs.ChannelPlayer.register(new PacketHandlerPlayer());
new MusicController();
new ScriptSoundController();
@@ -111,6 +115,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileBanner.class, new BlockBannerRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileWallBanner.class, new BlockWallBannerRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileTallLamp.class, new BlockTallLampRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileShortLamp.class, new BlockShortLampRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileChair.class, new BlockChairRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileWeaponRack.class, new BlockWeaponRackRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileCrate.class, new BlockCrateRenderer());
@@ -118,7 +123,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileCouchWood.class, new BlockCouchWoodRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileTable.class, new BlockTableRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileCandle.class, new BlockCandleRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileLamp.class, new BlockLampRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileLamp.class, new BlockLanternRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileStool.class, new BlockStoolRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileBigSign.class, new BlockBigSignRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileBarrel.class, new BlockBarrelRenderer());
@@ -130,10 +135,17 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileBook.class, new BlockBookRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TilePedestal.class, new BlockPedestalRenderer());
RenderingRegistry.registerBlockHandler(new BlockBloodRenderer());
// Tile Item Renderers
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.couchWool), new ItemCouchWoolRenderer());
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.banner), new ItemBannerRenderer());
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.wallBanner), new ItemBannerWallRenderer());
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.shortLamp), new ItemShortLampRenderer());
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.tallLamp), new ItemTallLampRenderer());
}
Minecraft mc = Minecraft.getMinecraft();
NPCButton = new KeyBinding("NPC Inventory", Keyboard.KEY_L, "key.categories.customnpc");
NPCButton = new KeyBinding("NPC Inventory", Keyboard.KEY_N, "key.categories.customnpc");
ClientRegistry.registerKeyBinding(NPCButton);
mc.gameSettings.loadOptions();
@@ -208,6 +220,15 @@ public class ClientProxy extends CommonProxy {
return null;
}
public AnimationData getClientAnimationData(Entity entity) {
if (entity instanceof EntityPlayer) {
return ClientCacheHandler.playerAnimations.get(entity.getUniqueID());
} else if (entity instanceof EntityNPCInterface) {
return ((EntityNPCInterface) entity).display.animationData;
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -246,7 +267,7 @@ public class ClientProxy extends CommonProxy {
return new GuiNpcPather(npc);
else if (gui == EnumGuiType.ManageFactions)
return new GuiNPCManageFactions(npc);
return new GuiNPCManageFactions(npc);
else if (gui == EnumGuiType.ManageCustomForms)
return DBCClient.Instance.manageCustomForms(npc);
@@ -274,7 +295,10 @@ public class ClientProxy extends CommonProxy {
return new GuiNPCManageAnimations(animNpc, save);
}
else if (gui == EnumGuiType.ManageLinked)
return new GuiNPCManageLinkedNpc(npc);
return new GuiNPCManageLinked(npc);
else if (gui == EnumGuiType.ManageMagic)
return new GuiNpcManageMagic(npc);
else if (gui == EnumGuiType.ManageTransport)
return new GuiNPCManageTransporters(npc);
@@ -291,6 +315,9 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.ManageBanks)
return new GuiNPCManageBanks(npc, (ContainerManageBanks) container);
else if (gui == EnumGuiType.ManageEffects)
return new GuiNPCManageEffects(npc);
else if (gui == EnumGuiType.MainMenuGlobal)
return new GuiNPCGlobalMainMenu(npc);
@@ -318,9 +345,12 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.ScriptItem)
return new GuiScriptItem();
else if (gui == EnumGuiType.PlayerAnvil)
else if (gui == EnumGuiType.PlayerCarpentryBench)
return new GuiNpcCarpentryBench((ContainerCarpentryBench) container);
else if (gui == EnumGuiType.PlayerAnvil)
return new GuiNpcAnvil((ContainerAnvilRepair) container);
else if (gui == EnumGuiType.SetupFollower)
return new GuiNpcFollowerSetup(npc, (ContainerNPCFollowerSetup) container);
@@ -366,7 +396,7 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.RedstoneBlock)
return new GuiNpcRedstoneBlock(x, y, z);
else if(gui == EnumGuiType.MobSpawner)
else if(gui == EnumGuiType.Cloner)
return new GuiNpcMobSpawner(x, y, z);
else if(gui == EnumGuiType.MobSpawnerMounter)
@@ -390,6 +420,9 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.ScriptBlock)
return new GuiScriptBlock(x,y,z);
else if (gui == EnumGuiType.Paintbrush)
return new GuiNpcPaintbrush();
else if (gui == EnumGuiType.GlobalRemote)
return new GuiNPCGlobalMainMenu(null);
@@ -502,9 +535,11 @@ public class ClientProxy extends CommonProxy {
@Override
public void registerItem(Item item) {
if (item instanceof ItemScripted) {
MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer());
} else {
if (item instanceof ItemScripted || item instanceof ItemLinked) {
MinecraftForgeClient.registerItemRenderer(item, new ItemCustomRenderer());
} else if (item instanceof ItemNpcTool) {
MinecraftForgeClient.registerItemRenderer(item, new ItemToolRenderer());
}else {
MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer());
}
}
@@ -565,7 +600,7 @@ public class ClientProxy extends CommonProxy {
}
public static class FontContainer {
private StringCache textFont = null;
public StringCache textFont = null;
public boolean useCustomFont = true;
private FontContainer(){
@@ -5,23 +5,32 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import kamkeel.addon.DBCAddon;
import kamkeel.addon.client.DBCClient;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.player.CheckPlayerValue;
import kamkeel.npcs.network.packets.player.InputDevicePacket;
import kamkeel.npcs.network.packets.player.ScreenSizePacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.audio.SoundManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.controllers.ScriptSoundController;
import noppes.npcs.client.gui.player.inventory.*;
import noppes.npcs.client.gui.hud.ClientHudManager;
import noppes.npcs.client.gui.hud.CompassHudComponent;
import noppes.npcs.client.gui.hud.EnumHudComponent;
import noppes.npcs.client.gui.hud.HudComponent;
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
import noppes.npcs.client.renderer.RenderNPCInterface;
import noppes.npcs.constants.EnumPlayerPacket;
import noppes.npcs.constants.MarkType;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import tconstruct.client.tabs.InventoryTabCustomNpc;
import java.util.ArrayList;
import static noppes.npcs.client.ClientEventHandler.renderCNPCPlayer;
@@ -38,7 +47,9 @@ public class ClientTickHandler{
public void onClientTick(TickEvent.ClientTickEvent event){
Minecraft mc = Minecraft.getMinecraft();
if ((this.prevWorld == null || mc.theWorld == null) && this.prevWorld != mc.theWorld) {
ClientCacheHandler.clearCache();
if (mc.theWorld == null) {
ClientCacheHandler.clearCache();
}
this.prevWorld = mc.theWorld;
}
if(event.phase == Phase.END) {
@@ -49,7 +60,7 @@ public class ClientTickHandler{
}
if(mc.thePlayer != null && mc.thePlayer.openContainer instanceof ContainerPlayer){
if(otherContainer){
NoppesUtilPlayer.sendData(EnumPlayerPacket.CheckQuestCompletion);
PacketClient.sendClient(new CheckPlayerValue(CheckPlayerValue.Type.CheckQuestCompletion));
otherContainer = false;
}
}
@@ -57,10 +68,8 @@ public class ClientTickHandler{
otherContainer = true;
CustomNpcs.ticks++;
RenderNPCInterface.LastTextureTick++;
if(prevWorld != mc.theWorld){
prevWorld = mc.theWorld;
MusicController.Instance.stopAllSounds();
} else if (MusicController.Instance.isPlaying() && MusicController.Instance.getEntity() != null) {
if (MusicController.Instance.isPlaying() && MusicController.Instance.getEntity() != null) {
Entity entity = MusicController.Instance.getEntity();
if (MusicController.Instance.getOffRange() > 0 &&
(Minecraft.getMinecraft().thePlayer == null ||
@@ -69,13 +78,21 @@ public class ClientTickHandler{
MusicController.Instance.stopMusic();
}
}
MusicController.Instance.onUpdate();
ScriptSoundController.Instance.onUpdate();
if(Minecraft.getMinecraft().thePlayer!=null && (prevWidth!=mc.displayWidth || prevHeight!=mc.displayHeight)){
prevWidth = mc.displayWidth;
prevHeight = mc.displayHeight;
NoppesUtilPlayer.sendData(EnumPlayerPacket.ScreenSize,mc.displayWidth,mc.displayHeight);
PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth,mc.displayHeight));
}
if(mc.theWorld == null)
return;
if(mc.theWorld.getTotalWorldTime() % 20 == 0) { // Update every second
updateCompassMarks();
}
}
@SubscribeEvent
@@ -83,22 +100,7 @@ public class ClientTickHandler{
if(Mouse.getEventButton() == -1 && Mouse.getEventDWheel() == 0)
return;
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
StringBuilder keysDownString = new StringBuilder();
for (int i = 0; i < Keyboard.getKeyCount(); i++) {//Creates a comma separated string of the integer IDs of held keys
if (Keyboard.isKeyDown(i)) {
keysDownString.append(Integer.valueOf(i)).append(",");
}
}
if (keysDownString.length() > 0) {//Removes last comma for later parsing
keysDownString.deleteCharAt(keysDownString.length() - 1);
}
NoppesUtilPlayer.sendData(EnumPlayerPacket.MouseClicked, Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton()), isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keysDownString.toString());
InputDevicePacket.sendMouse(Mouse.getEventButton(),Mouse.getEventDWheel(),Mouse.isButtonDown(Mouse.getEventButton()));
}
@SubscribeEvent
@@ -106,23 +108,7 @@ public class ClientTickHandler{
if(ClientProxy.NPCButton.isPressed()){
Minecraft mc = Minecraft.getMinecraft();
if(mc.currentScreen == null){
switch (GuiCNPCInventory.activeTab){
case 0:
NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog());
break;
case 1:
NoppesUtil.openGUI(mc.thePlayer, new GuiParty());
break;
case 2:
NoppesUtil.openGUI(mc.thePlayer, new GuiFaction());
break;
case 3:
NoppesUtil.openGUI(mc.thePlayer, new GuiSettings());
break;
case 4:
NoppesUtil.openGUI(mc.thePlayer, DBCClient.Instance.inventoryGUI());
break;
}
InventoryTabCustomNpc.tabHelper();
}
else if(mc.currentScreen instanceof GuiCNPCInventory)
mc.setIngameFocus();
@@ -130,23 +116,9 @@ public class ClientTickHandler{
if(!Keyboard.isRepeatEvent()) {
int key = Keyboard.getEventKey();
boolean isCtrlPressed = Keyboard.isKeyDown(157) || Keyboard.isKeyDown(29);
boolean isShiftPressed = Keyboard.isKeyDown(54) || Keyboard.isKeyDown(42);
boolean isAltPressed = Keyboard.isKeyDown(184) || Keyboard.isKeyDown(56);
boolean isMetaPressed = Keyboard.isKeyDown(220) || Keyboard.isKeyDown(219);
boolean keyDown = Keyboard.isKeyDown(key);
StringBuilder keysDownString = new StringBuilder();
for (int i = 0; i < Keyboard.getKeyCount(); i++) {//Creates a comma separated string of the integer IDs of held keys
if (Keyboard.isKeyDown(i)) {
keysDownString.append(Integer.valueOf(i)).append(",");
}
}
if (keysDownString.length() > 0) {//Removes last comma for later parsing
keysDownString.deleteCharAt(keysDownString.length() - 1);
}
NoppesUtilPlayer.sendData(EnumPlayerPacket.KeyPressed, key, isCtrlPressed, isShiftPressed, isAltPressed, isMetaPressed, keyDown, keysDownString.toString());
InputDevicePacket.sendKeyboard(key, keyDown);
}
}
@@ -163,4 +135,59 @@ public class ClientTickHandler{
return false;
}
private final int SCAN_RANGE = 128;
private void updateCompassMarks() {
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
if(player == null || mc.theWorld == null)
return;
if(ClientHudManager.getInstance() == null || ClientHudManager.getInstance().getHudComponents() == null)
return;
// Update compass
HudComponent compass = ClientHudManager.getInstance()
.getHudComponents().get(EnumHudComponent.QuestCompass);
if(!(compass instanceof CompassHudComponent))
return;
if(!compass.enabled)
return;
ArrayList<CompassHudComponent.MarkTargetEntry> marks = new ArrayList<>();
// Scan entities in loaded chunks
for(Object entity : mc.theWorld.loadedEntityList) {
if(entity instanceof EntityNPCInterface) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
if(npc.dimension != player.dimension)
continue;
// Check distance
if(player.getDistanceToEntity(npc) > SCAN_RANGE)
continue;
// Get marks
MarkData markData = MarkData.get(npc);
for(MarkData.Mark mark : markData.marks) {
if(mark.getType() != MarkType.NONE &&
mark.availability.isAvailable(player)) {
marks.add(new CompassHudComponent.MarkTargetEntry(
(int)npc.posX,
(int)npc.posZ,
mark.getType(),
mark.color
));
break; // Only show first valid mark per NPC
}
}
}
}
((CompassHudComponent) compass).updateMarkTargets(marks);
}
}
@@ -1,7 +1,7 @@
package noppes.npcs.client;
import kamkeel.addon.DBCAddon;
import kamkeel.addon.GeckoAddon;
import kamkeel.npcs.addon.DBCAddon;
import kamkeel.npcs.addon.GeckoAddon;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.passive.EntityChicken;
+66 -163
View File
@@ -1,43 +1,36 @@
package noppes.npcs.client;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.GuiRequestPacket;
import kamkeel.npcs.network.packets.request.IsGuiOpenInform;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
import noppes.npcs.client.fx.CustomFX;
import noppes.npcs.client.gui.player.GuiDialogInteract;
import noppes.npcs.client.gui.player.GuiQuestCompletion;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.IScrollData;
import noppes.npcs.client.gui.util.IScrollGroup;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.Quest;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.scripted.ScriptParticle;
import org.lwjgl.Sys;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Random;
import java.util.Map;
import java.util.Vector;
public class NoppesUtil {
@@ -47,31 +40,10 @@ public class NoppesUtil {
}
public static void requestOpenGUI(EnumGuiType gui, int i, int j, int k) {
Client.sendData(EnumPacketServer.Gui, gui.ordinal(), i, j, k);
PacketClient.sendClient(new GuiRequestPacket(gui.ordinal(), i, j, k));
}
public static void spawnParticle(ByteBuf buffer) throws IOException{
double posX = buffer.readDouble();
double posY = buffer.readDouble();
double posZ = buffer.readDouble();
float height = buffer.readFloat();
float width = buffer.readFloat();
float yOffset = buffer.readFloat();
String particle = Server.readString(buffer);
World worldObj = Minecraft.getMinecraft().theWorld;
Random rand = worldObj.rand;
if(particle.equals("heal")){
for (int k = 0; k < 6; k++)
{
worldObj.spawnParticle("instantSpell", posX + (rand.nextDouble() - 0.5D) * (double)width, (posY + rand.nextDouble() * (double)height) - (double)yOffset, posZ + (rand.nextDouble() - 0.5D) * (double)width, 0, 0, 0);
worldObj.spawnParticle("spell", posX + (rand.nextDouble() - 0.5D) * (double)width, (posY + rand.nextDouble() * (double)height) - (double)yOffset, posZ + (rand.nextDouble() - 0.5D) * (double)width, 0, 0, 0);
}
}
}
public static void updateSkinOverlayData(EntityPlayer player, NBTTagCompound compound) {
public static void updateSkinOverlayData(EntityPlayer player, NBTTagCompound compound) {
HashMap<Integer, SkinOverlay> skinOverlays = new HashMap<>();
HashMap<Integer, SkinOverlay> oldOverlays = new HashMap<>();
NBTTagList skinOverlayList = compound.getTagList("SkinOverlayData",10);
@@ -90,39 +62,7 @@ public class NoppesUtil {
ClientCacheHandler.skinOverlays.put(player.getUniqueID(), skinOverlays);
}
public static void spawnScriptedParticle(EntityPlayer player, ByteBuf buffer){
Minecraft minecraft = Minecraft.getMinecraft();
NBTTagCompound compound;
ScriptParticle particle;
try {
compound = Server.readNBT(buffer);
particle = ScriptParticle.fromNBT(compound);
} catch (IOException ignored) {
return;
}
World worldObj = player.worldObj;
if (worldObj == null) {
return;
}
Entity entity = null;
if (compound.hasKey("EntityID")) {
entity = worldObj.getEntityByID(compound.getInteger("EntityID"));
if (entity != null)
worldObj = entity.worldObj;
else return;
}
CustomFX fx = CustomFX.fromScriptedParticle(particle, worldObj, entity);
for(int i = 0; i < particle.amount; i++){
minecraft.effectRenderer.addEffect(fx);
}
}
public static void clickSound() {
public static void clickSound() {
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
}
@@ -199,78 +139,32 @@ public class NoppesUtil {
Vector<String> data = new Vector<String>();
String line;
EnumScrollData dataType = EnumScrollData.values()[buffer.readInt()];
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
data.add(Server.readString(buffer));
data.add(ByteBufUtils.readString(buffer));
}
} catch (Exception e) {
}
((IScrollData)gui).setData(data,null);
((IScrollData)gui).setData(data,null, dataType);
}
private static HashMap<String,Integer> data = new HashMap<String,Integer>();
private static HashMap<String,Integer> group = new HashMap<String,Integer>();
public static void addScrollGroup(ByteBuf buffer) {
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
int id = buffer.readInt();
String name = Server.readString(buffer);
group.put(name, id);
}
} catch (Exception ignored) {
}
}
public static void setScrollGroup(ByteBuf buffer) {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
int id = buffer.readInt();
String name = Server.readString(buffer);
group.put(name, id);
}
} catch (Exception ignored) {
}
if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui();
}
if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui();
}
if(gui instanceof IScrollGroup)
((IScrollGroup)gui).setScrollGroup(new Vector<String>(group.keySet()), group);
group = new HashMap<String,Integer>();
}
public static void addScrollData(ByteBuf buffer) {
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
int id = buffer.readInt();
String name = Server.readString(buffer);
data.put(name, id);
}
} catch (Exception e) {
}
}
public static void setScrollData(ByteBuf buffer) {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
EnumScrollData dataType = EnumScrollData.values()[buffer.readInt()];
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
int id = buffer.readInt();
String name = Server.readString(buffer);
String name = ByteBufUtils.readString(buffer);
data.put(name, id);
}
} catch (Exception e) {
@@ -282,7 +176,7 @@ public class NoppesUtil {
gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui();
}
if(gui instanceof IScrollData)
((IScrollData)gui).setData(new Vector<String>(data.keySet()), data);
((IScrollData)gui).setData(new Vector<String>(data.keySet()), data, dataType);
data = new HashMap<String,Integer>();
}
@@ -327,53 +221,62 @@ public class NoppesUtil {
}
public static void isGUIOpen(boolean isGUIOpen) {
Client.sendData(EnumPacketServer.IsGuiOpen, isGUIOpen);
PacketClient.sendClient(new IsGuiOpenInform(isGUIOpen));
}
/**
* Handles the incoming large packet with full player data.
* The packet writes:
* - player name (String)
* - questCategories, questActive, questFinished (maps)
* - dialogCategories, dialogRead (maps)
* - transportCategories, transportLocations (maps)
* - bankData, factionData (maps)
*
* The existing PlayerDataController functions are used on the server side;
* here we simply update the active SubGuiPlayerDataNew if present.
*/
public static void handlePlayerData(ByteBuf data, EntityPlayer player) throws IOException {
String playerName = ByteBufUtils.readString(data);
Map<String, Integer> questCategories = readMap(data);
Map<String, Integer> questActive = readMap(data);
Map<String, Integer> questFinished = readMap(data);
Map<String, Integer> dialogCategories = readMap(data);
Map<String, Integer> dialogRead = readMap(data);
Map<String, Integer> transportCategories = readMap(data);
Map<String, Integer> transportLocations = readMap(data);
Map<String, Integer> bankData = readMap(data);
Map<String, Integer> factionData = readMap(data);
private static byte[] accumulatedData = new byte[0];
public static void handleLargeData(byte[] chunk) {
// Append the chunk to the accumulated data
accumulatedData = concatByteArrays(accumulatedData, chunk);
}
public static void handlePlayerDataEnd(boolean sync) {
NBTTagCompound compound;
try {
compound = CompressedStreamTools.func_152457_a(accumulatedData, new NBTSizeTracker(2097152L));
if(sync){
ClientCacheHandler.playerData.setSyncNBT(compound);
}
else {
ClientCacheHandler.playerData.setSyncNBTFull(compound);
}
} catch (IOException e) {
e.printStackTrace();
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
} finally {
// Reset the accumulated data after processing
accumulatedData = new byte[0];
if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui();
}
if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui();
}
if (gui instanceof IPlayerDataInfo) {
IPlayerDataInfo info = (IPlayerDataInfo) gui;
info.setQuestData(questCategories, questActive, questFinished);
info.setDialogData(dialogCategories, dialogRead);
info.setTransportData(transportCategories, transportLocations);
info.setBankData(bankData);
info.setFactionData(factionData);
}
}
public static void handleFormEnd() {
NBTTagCompound compound;
try {
compound = CompressedStreamTools.func_152457_a(accumulatedData, new NBTSizeTracker(2097152L));
ClientCacheHandler.playerData.setDBCSync(compound);
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
accumulatedData = new byte[0];
private static Map<String, Integer> readMap(ByteBuf data) {
int size = data.readInt();
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i < size; i++) {
String key = ByteBufUtils.readString(data);
int value = data.readInt();
map.put(key, value);
}
}
// Utility method to concatenate two byte arrays
private static byte[] concatByteArrays(byte[] a, byte[] b) {
byte[] result = new byte[a.length + b.length];
System.arraycopy(a, 0, result, 0, a.length);
System.arraycopy(b, 0, result, a.length, b.length);
return result;
return map;
}
}
@@ -1,457 +0,0 @@
package noppes.npcs.client;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.achievement.GuiAchievement;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.PacketBuffer;
import net.minecraft.stats.Achievement;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.StatCollector;
import net.minecraft.village.MerchantRecipeList;
import noppes.npcs.*;
import noppes.npcs.client.ClientProxy.FontContainer;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.controllers.ScriptClientSound;
import noppes.npcs.client.controllers.ScriptSoundController;
import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd;
import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.player.GuiBook;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.MarkData;
import noppes.npcs.controllers.data.RecipeCarpentry;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.entity.EntityNPCInterface;
import java.io.IOException;
import java.util.HashMap;
public class PacketHandlerClient extends PacketHandlerServer{
@SubscribeEvent
public void onPacketData(ClientCustomPacketEvent event) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ByteBuf buffer = event.packet.payload();
try {
client(buffer,(EntityPlayer) player,EnumPacketClient.values()[buffer.readInt()]);
} catch (IOException e) {
e.printStackTrace();
}
}
private void client(ByteBuf buffer, final EntityPlayer player, EnumPacketClient type) throws IOException{
if(type == EnumPacketClient.CHATBUBBLE){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
EntityNPCInterface npc = (EntityNPCInterface) entity;
if(npc.messages == null)
npc.messages = new RenderChatMessages();
String text = NoppesStringUtils.formatText(Server.readString(buffer), player, npc);
npc.messages.addMessage(text, npc);
if(buffer.readBoolean())
player.addChatMessage(new ChatComponentTranslation(npc.getCommandSenderName() + ": " + text));
}
else if(type == EnumPacketClient.CHAT){
if(!ConfigClient.ChatAlerts)
return;
String message = "";
String str;
while((str = Server.readString(buffer)) != null && !str.isEmpty())
message += StatCollector.translateToLocal(str);
player.addChatMessage(new ChatComponentTranslation(message));
}
else if(type == EnumPacketClient.MESSAGE || type == EnumPacketClient.PARTY_MESSAGE){
if(!ConfigClient.BannerAlerts)
return;
String description = StatCollector.translateToLocal(Server.readString(buffer));
String message = Server.readString(buffer);
Achievement ach = type == EnumPacketClient.MESSAGE ? new MessageAchievement(message, description) : new MessageAchievement(CustomItems.bag == null ? Items.paper : CustomItems.bag, message, description);
Minecraft.getMinecraft().guiAchievement.func_146256_a(ach);
ObfuscationReflectionHelper.setPrivateValue(GuiAchievement.class, Minecraft.getMinecraft().guiAchievement, ach.getDescription(), 4);
}
else if(type == EnumPacketClient.SYNCRECIPES_ADD){
NBTTagList list = Server.readNBT(buffer).getTagList("recipes", 10);
if(list == null)
return;
for(int i = 0; i < list.tagCount(); i++)
{
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
RecipeController.syncRecipes.put(recipe.id,recipe);
}
}
else if(type == EnumPacketClient.SYNCRECIPES_WORKBENCH){
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.SYNCRECIPES_CARPENTRYBENCH){
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.LARGE_NBT_PART){
byte[] chunk = new byte[buffer.readShort()];
buffer.readBytes(chunk);
NoppesUtil.handleLargeData(chunk);
}
else if(type == EnumPacketClient.SYNC_PLAYER){
boolean sync = buffer.readBoolean();
NoppesUtil.handlePlayerDataEnd(sync);
}
else if(type == EnumPacketClient.SYNC_ADD || type == EnumPacketClient.SYNC_END){
int synctype = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
SyncController.clientSync(synctype, compound, type == EnumPacketClient.SYNC_END);
}
else if(type == EnumPacketClient.SYNC_UPDATE){
int synctype = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
SyncController.clientSyncUpdate(synctype, compound, buffer);
}
else if(type == EnumPacketClient.SYNC_REMOVE){
int synctype = buffer.readInt();
int id = buffer.readInt();
SyncController.clientSyncRemove(synctype, id);
}
else if(type == EnumPacketClient.SYNC_CONFIG){
NBTTagCompound configNBT = Server.readNBT(buffer);
SyncController.receiveConfigs(configNBT);
}
else if(type == EnumPacketClient.MARK_DATA){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(!(entity instanceof EntityNPCInterface))
return;
MarkData data = MarkData.get((EntityNPCInterface) entity);
data.setNBT(Server.readNBT(buffer));
}
else if(type == EnumPacketClient.DIALOG){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
NoppesUtil.openDialog(Server.readNBT(buffer), (EntityNPCInterface) entity, player);
}
else if(type == EnumPacketClient.DIALOG_DUMMY){
EntityDialogNpc npc = new EntityDialogNpc(player.worldObj);
npc.display.name = Server.readString(buffer);
EntityUtil.Copy(player, npc);
NoppesUtil.openDialog(Server.readNBT(buffer), npc, player);
}
else if(type == EnumPacketClient.QUEST_COMPLETION){
NoppesUtil.guiQuestCompletion(player, Server.readNBT(buffer));
}
else if(type == EnumPacketClient.EDIT_NPC){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
NoppesUtil.setLastNpc((EntityNPCInterface) entity);
}
else if(type == EnumPacketClient.PLAY_MUSIC){
MusicController.Instance.playMusicBackground(Server.readString(buffer), player, Integer.MAX_VALUE);
}
else if(type == EnumPacketClient.PLAY_SOUND){
MusicController.Instance.playSound(Server.readString(buffer),buffer.readFloat(),buffer.readFloat(),buffer.readFloat());
}
else if(type == EnumPacketClient.UPDATE_NPC){
NBTTagCompound compound = Server.readNBT(buffer);
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId"));
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
((EntityNPCInterface)entity).readSpawnData(compound);
}
else if(type == EnumPacketClient.ROLE){
NBTTagCompound compound = Server.readNBT(buffer);
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId"));
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
((EntityNPCInterface)entity).advanced.setRole(compound.getInteger("Role"));
((EntityNPCInterface)entity).roleInterface.readFromNBT(compound);
NoppesUtil.setLastNpc((EntityNPCInterface) entity);
}
else if(type == EnumPacketClient.GUI){
EnumGuiType gui = EnumGuiType.values()[buffer.readInt()];
CustomNpcs.proxy.openGui(NoppesUtil.getLastNpc(), gui, buffer.readInt(), buffer.readInt(), buffer.readInt());
}
else if(type == EnumPacketClient.SCRIPTED_PARTICLE){
NoppesUtil.spawnScriptedParticle(player, buffer);
}
else if(type == EnumPacketClient.PARTICLE){
NoppesUtil.spawnParticle(buffer);
}
else if(type == EnumPacketClient.DELETE_NPC){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
((EntityNPCInterface)entity).delete();
}
else if(type == EnumPacketClient.SCROLL_LIST){
NoppesUtil.setScrollList(buffer);
}
else if(type == EnumPacketClient.SCROLL_DATA){
NoppesUtil.setScrollData(buffer);
}
else if(type == EnumPacketClient.SCROLL_DATA_PART){
NoppesUtil.addScrollData(buffer);
}
else if(type == EnumPacketClient.SCROLL_GROUP){
NoppesUtil.setScrollGroup(buffer);
}
else if(type == EnumPacketClient.SCROLL_GROUP_PART){
NoppesUtil.addScrollGroup(buffer);
}
else if(type == EnumPacketClient.SCROLL_SELECTED){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null || !(gui instanceof IScrollData))
return;
String selected = Server.readString(buffer);
((IScrollData)gui).setSelected(selected);
}
else if(type == EnumPacketClient.GUI_REDSTONE){
NoppesUtil.saveRedstoneBlock(player, Server.readNBT(buffer));
}
else if(type == EnumPacketClient.GUI_WAYPOINT){
NoppesUtil.saveWayPointBlock(player, Server.readNBT(buffer));
}
else if(type == EnumPacketClient.CLONE){
NBTTagCompound compound = Server.readNBT(buffer);
NoppesUtil.openGUI(player, new GuiNpcMobSpawnerAdd(compound));
}
else if(type == EnumPacketClient.CLONER){
int x = buffer.readInt();
int y = buffer.readInt();
int z = buffer.readInt();
CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.MobSpawner, player);
}
else if(type == EnumPacketClient.TELEPORTER){
CustomNpcs.proxy.openGui((EntityNPCInterface)null,EnumGuiType.NpcDimensions);
}
else if(type == EnumPacketClient.GUI_DATA){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui();
}
else if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui();
}
if(gui instanceof IGuiData)
((IGuiData)gui).setGuiData(Server.readNBT(buffer));
}
else if(type == EnumPacketClient.GUI_ERROR){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null || !(gui instanceof IGuiError))
return;
int i = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
((IGuiError)gui).setError(i, compound);
}
else if(type == EnumPacketClient.GUI_CLOSE){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
if(gui instanceof IGuiClose){
int i = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
((IGuiClose)gui).setClose(i, compound);
}
Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(null);
mc.setIngameFocus();
}
else if(type == EnumPacketClient.VILLAGER_LIST){
MerchantRecipeList merchantrecipelist = MerchantRecipeList.func_151390_b(new PacketBuffer(buffer));
ServerEventsHandler.Merchant.setRecipes(merchantrecipelist);
}
else if(type == EnumPacketClient.OPEN_BOOK){
int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
NoppesUtil.openGUI(player, new GuiBook(player, ItemStack.loadItemStackFromNBT(Server.readNBT(buffer)), x, y, z));
}
else if(type == EnumPacketClient.CONFIG){
int config = buffer.readInt();
if(config == 0){//Font
String font = Server.readString(buffer);
int size = buffer.readInt();
if(!font.isEmpty()){
ConfigClient.FontType = font;
ConfigClient.FontSize = size;
ClientProxy.Font = new FontContainer(ConfigClient.FontType, ConfigClient.FontSize);
ConfigClient.FontTypeProperty.set(ConfigClient.FontType);
ConfigClient.FontSizeProperty.set(ConfigClient.FontSize);
if(ConfigClient.config.hasChanged()){
ConfigClient.config.save();
}
player.addChatMessage(new ChatComponentTranslation("Font set to %s", ClientProxy.Font.getName()));
}
else
player.addChatMessage(new ChatComponentTranslation("Current font is %s", ClientProxy.Font.getName()));
}
}
else if(type == EnumPacketClient.ISGUIOPEN){
boolean isGUIOpen = Minecraft.getMinecraft().currentScreen != null;
NoppesUtil.isGUIOpen(isGUIOpen);
}
else if(type == EnumPacketClient.SCRIPT_OVERLAY_DATA){
OverlayCustom overlayCustom = new OverlayCustom(Minecraft.getMinecraft());
overlayCustom.setOverlayData(Server.readNBT(buffer));
ClientCacheHandler.customOverlays.put(overlayCustom.overlay.getID(),overlayCustom);
}
else if(type == EnumPacketClient.SCRIPT_OVERLAY_CLOSE){
int id = buffer.readInt();
ClientCacheHandler.customOverlays.remove(id);
}
else if(type == EnumPacketClient.OVERLAY_QUEST_TRACKING){
try {
NBTTagCompound compound = Server.readNBT(buffer);
ClientCacheHandler.questTrackingOverlay = new OverlayQuestTracking(Minecraft.getMinecraft());
ClientCacheHandler.questTrackingOverlay.setOverlayData(compound);
} catch (IOException e) {
ClientCacheHandler.questTrackingOverlay = null;
}
}
else if(type == EnumPacketClient.SWING_PLAYER_ARM){
Minecraft.getMinecraft().thePlayer.swingItem();
}
else if(type == EnumPacketClient.PLAYER_UPDATE_SKIN_OVERLAYS) {
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(Server.readString(buffer));
NBTTagCompound compound = Server.readNBT(buffer);
if (sendingPlayer != null) {
NoppesUtil.updateSkinOverlayData(sendingPlayer, compound);
}
}
else if(type == EnumPacketClient.UPDATE_ANIMATIONS) {
NBTTagCompound compound = Server.readNBT(buffer);
AnimationData animationData = null;
if (compound.hasKey("EntityId")) {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId"));
if (entity instanceof EntityNPCInterface) {
animationData = ((EntityNPCInterface) entity).display.animationData;
}
} else {
EntityPlayer sendingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(Server.readString(buffer));
if (sendingPlayer != null) {
if (!ClientCacheHandler.playerAnimations.containsKey(sendingPlayer.getUniqueID())) {
ClientCacheHandler.playerAnimations.put(sendingPlayer.getUniqueID(), new AnimationData(sendingPlayer));
}
animationData = ClientCacheHandler.playerAnimations.get(sendingPlayer.getUniqueID());
animationData.parent = sendingPlayer;
}
}
if (animationData != null) {
int animationId;
if (compound.hasKey("AnimationID")) {
animationId = compound.getInteger("AnimationID");
} else {
Animation animation = new Animation();
animation.readFromNBT(compound.getCompoundTag("Animation"));
ClientCacheHandler.animationCache.put(animation.getID(), animation);
animationId = animation.getID();
}
animationData.setAnimation(ClientCacheHandler.animationCache.get(animationId));
animationData.readFromNBT(compound);
Client.sendData(EnumPacketServer.CacheAnimation, animationId);
}
}
else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) {
long length = buffer.readLong();
try {
String parsedButtons = Server.readString(buffer);
if (parsedButtons == null || parsedButtons.isEmpty()) {
ClientEventHandler.disabledButtonTimes.put(-1, length);
return;
}
String[] splitIds = parsedButtons.split(";");
for (String s : splitIds) {
ClientEventHandler.disabledButtonTimes.put(Integer.parseInt(s), length);
}
} catch (Exception ignored) {}
}
else if(type == EnumPacketClient.PLAY_SOUND_TO) {
int id = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
ScriptClientSound sound = ScriptClientSound.fromScriptSound(compound, player.worldObj);
ScriptSoundController.Instance.playSound(id,sound);
}
else if(type == EnumPacketClient.PLAY_SOUND_TO_NO_ID) {
NBTTagCompound compound = Server.readNBT(buffer);
ScriptClientSound sound = ScriptClientSound.fromScriptSound(compound, player.worldObj);
ScriptSoundController.Instance.playSound(sound);
}
else if(type == EnumPacketClient.STOP_SOUND_FOR) {
int id = buffer.readInt();
ScriptSoundController.Instance.stopSound(id);
}
else if(type == EnumPacketClient.PAUSE_SOUNDS) {
ScriptSoundController.Instance.pauseAllSounds();
}
else if(type == EnumPacketClient.CONTINUE_SOUNDS) {
ScriptSoundController.Instance.continueAllSounds();
}
else if(type == EnumPacketClient.STOP_SOUNDS) {
ScriptSoundController.Instance.stopAllSounds();
}
else if(type == EnumPacketClient.SYNC_WEAPON) {
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(!(entity instanceof EntityNPCInterface))
return;
EntityNPCInterface npc = (EntityNPCInterface) entity;
int weaponSlotIndex = buffer.readInt();
ItemStack stack = ItemStack.loadItemStackFromNBT(Server.readNBT(buffer));
npc.inventory.weapons.put(weaponSlotIndex,stack);
}
else if(type == EnumPacketClient.PARTY_DATA){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui();
}
else if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui();
}
if(gui instanceof IPartyData)
((IPartyData)gui).setPartyData(Server.readNBT(buffer));
}
else if(type == EnumPacketClient.DBC_FORM){
NoppesUtil.handleFormEnd();
}
}
}
@@ -57,6 +57,7 @@ public class RenderChatMessages implements IChatMessages{
FontRenderer font = Minecraft.getMinecraft().fontRenderer;
float var13 = 1.6F;
float var14 = 0.016666668F * var13;
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushMatrix();
int size = 0;
for (TextBlockClient block : messages.values())
@@ -140,6 +141,7 @@ public class RenderChatMessages implements IChatMessages{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
RenderHelper.enableStandardItemLighting();
GL11.glPopAttrib();
}
private void drawRect(int par0, int par1, int par2, int par3, int par4, double par5)
@@ -18,7 +18,7 @@ public class TranslateUtil {
private static final String AudioUrl = "http://translate.google.com/translate_tts?q=%s&tl=%s";
public static String Translate(String text){
try {
String urlStr = String.format(TranslateUrl, URLEncoder.encode(text,"utf8"), "auto", "nl");
URL url = new URL(urlStr);
@@ -45,10 +45,10 @@ public class TranslateUtil {
} catch (IOException e) {
e.printStackTrace();
}
return text;
}
// public static void PlayAudio(String text){
// try {
// String urlStr = String.format(AudioUrl, URLEncoder.encode(text,"utf8"), "en");
@@ -59,12 +59,12 @@ public class TranslateUtil {
// //connection.setDoOutput(true);
// connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");
// connection.setRequestProperty("X-HTTP-Method-Override", "GET");
//
//
// InputStream audioSrc = new BufferedInputStream(connection.getInputStream());
// //DataInputStream read = new DataInputStream(audioSrc);
// AudioInputStream audioIn = AudioSystem.getAudioInputStream(audioSrc);
// Clip clip = AudioSystem.getClip();
//
//
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// } catch (MalformedURLException e) {
@@ -72,10 +72,10 @@ public class TranslateUtil {
// } catch (IOException e) {
// e.printStackTrace();
// } catch (UnsupportedAudioFileException e) {
// // TODO Auto-generated catch block
//
// e.printStackTrace();
// } catch (LineUnavailableException e) {
// // TODO Auto-generated catch block
//
// e.printStackTrace();
// }
// }
@@ -4,7 +4,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.controllers.ServerCloneController;
import noppes.npcs.controllers.ServerTagMapController;
import noppes.npcs.controllers.data.TagMap;
import java.io.File;
@@ -61,7 +61,7 @@ public class MusicController {
soundHandler.stopSounds();
} catch (Exception ignored) {}
}
if (this.isPlaying()) {
if (this.playingSound != null) {
this.playingSound.stopSound();
this.playingSound = null;
}
@@ -1,7 +1,5 @@
package noppes.npcs.client.fx;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.client.Minecraft;
@@ -10,12 +8,12 @@ import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import org.lwjgl.opengl.GL11;
public class EntityBigSmokeFX extends EntityFX
{
@@ -1,36 +1,37 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.TileEntityGetPacket;
import kamkeel.npcs.network.packets.request.TileEntitySavePacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.blocks.tiles.TileBorder;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
public class GuiBorderBlock extends GuiNPCInterface implements IGuiData{
private TileBorder tile;
public GuiBorderBlock(int x, int y, int z) {
super();
tile = (TileBorder) player.worldObj.getTileEntity(x, y, z);
Client.sendData(EnumPacketServer.GetTileEntity, x, y, z);
PacketClient.sendClient(new TileEntityGetPacket(x, y, z));
}
public void initGui()
{
super.initGui();
this.addButton(new GuiNpcButton(4, guiLeft + 40, guiTop + 40, 120, 20, "Availability Options"));
addLabel(new GuiNpcLabel(0,"Height", guiLeft+ 1, guiTop + 76, 0xffffff));
addLabel(new GuiNpcLabel(0,"Height", guiLeft+ 1, guiTop + 76, 0xffffff));
addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft+ 60, guiTop + 71,40,20, tile.height + ""));
getTextField(0).integersOnly = true;
getTextField(0).setMinMaxDefault(0, 500, 6);
getTextField(0).setMinMaxDefault(0, 500, 6);
addLabel(new GuiNpcLabel(1,"Message", guiLeft+ 1, guiTop + 100, 0xffffff));
addLabel(new GuiNpcLabel(1,"Message", guiLeft+ 1, guiTop + 100, 0xffffff));
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft+ 60, guiTop + 95,200,20, tile.message));
addButton(new GuiNpcButton(0, guiLeft + 40, guiTop + 190,120,20, "Done"));
}
protected void actionPerformed(GuiButton guibutton) {
@@ -48,10 +49,10 @@ public class GuiBorderBlock extends GuiNPCInterface implements IGuiData{
return;
tile.height = getTextField(0).getInteger();
tile.message = getTextField(1).getText();
NBTTagCompound compound = new NBTTagCompound();
tile.writeToNBT(compound);
Client.sendData(EnumPacketServer.SaveTileEntity, compound);
PacketClient.sendClient(new TileEntitySavePacket(compound));
}
@Override
public void setGuiData(NBTTagCompound compound) {
@@ -0,0 +1,196 @@
package noppes.npcs.client.gui;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.gui.util.GuiDiagram;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.data.Magic;
import noppes.npcs.controllers.data.MagicAssociation;
import noppes.npcs.controllers.data.MagicCycle;
import noppes.npcs.constants.EnumDiagramLayout;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GuiMagicCycleMap extends GuiDiagram {
private List<Magic> cycleMagics;
private MagicCycle cycle;
/**
* Constructor using a MagicCycle object.
*/
public GuiMagicCycleMap(GuiNPCInterface parent, int x, int y, int width, int height, MagicCycle cycle) {
super(parent, x, y, width, height);
this.cycle = cycle;
cycleMagics = new ArrayList<>();
// If cycle is null, leave cycleMagics empty.
if (this.cycle == null) {
setLayout(EnumDiagramLayout.CIRCULAR_MANUAL);
setCurvedArrows(true);
setCurveAngle(-20);
invalidateCache();
return;
}
MagicController mc = MagicController.getInstance();
// Get magics from the cycle's associations if associations are not null.
if (cycle.associations != null) {
for (MagicAssociation assoc : cycle.associations.values()) {
Magic m = mc.getMagic(assoc.magicId);
if (m != null) {
cycleMagics.add(m);
}
}
}
// Use the cycle's layout if set; otherwise default to CIRCULAR_MANUAL.
setLayout(cycle.layout != null ? cycle.layout : EnumDiagramLayout.CIRCULAR_MANUAL);
setCurvedArrows(true);
setCurveAngle(-20);
invalidateCache();
this.iconSize = 20;
this.slotSize = iconSize + slotPadding;
}
/**
* Constructor using a cycle ID.
*/
public GuiMagicCycleMap(GuiNPCInterface parent, int x, int y, int width, int height, int cycleId) {
this(parent, x, y, width, height, MagicController.getInstance().getCycle(cycleId));
}
@Override
protected List<DiagramIcon> createIcons() {
List<DiagramIcon> icons = new ArrayList<>();
// If the magic list is empty, simply return an empty list.
if (cycleMagics == null || cycleMagics.isEmpty()) {
return icons;
}
// For each magic in the cycle, create an icon.
for (Magic m : cycleMagics) {
if (m == null) continue;
MagicIcon icon = new MagicIcon(m);
icon.enabled = true;
icon.pressable = true;
// If available, set manual ordering data from the cycle association.
MagicAssociation assoc = cycle.associations.get(m.id);
if (assoc != null) {
icon.index = assoc.index;
icon.priority = assoc.priority;
}
icons.add(icon);
}
return icons;
}
@Override
protected List<DiagramConnection> createConnections() {
List<DiagramConnection> conns = new ArrayList<>();
if (cycleMagics == null || cycleMagics.isEmpty())
return conns;
// Only add connections for interactions between magics in this cycle.
Map<Integer, Integer> orderMap = new HashMap<>();
for (int i = 0; i < cycleMagics.size(); i++) {
orderMap.put(cycleMagics.get(i).id, i);
}
for (Magic m : cycleMagics) {
if (m == null || m.interactions == null) continue;
for (Map.Entry<Integer, Float> entry : m.interactions.entrySet()) {
int targetId = entry.getKey();
if (!orderMap.containsKey(targetId)) continue;
float percent = entry.getValue();
String hover = "+" + (int) (percent * 100) + "%";
conns.add(new DiagramConnection(m.id, targetId, percent, hover));
}
}
return conns;
}
@Override
protected void renderIcon(DiagramIcon icon, int posX, int posY, IconRenderState state) {
Magic magic = ((MagicIcon) icon).magic;
Minecraft mc = Minecraft.getMinecraft();
FontRenderer fontRenderer = mc.fontRenderer;
int size = this.iconSize;
float scale = (float) size / 16.0f;
float renderX = posX - 8 * scale;
float renderY = posY - 8 * scale;
if (magic.item != null) {
RenderHelper.enableGUIStandardItemLighting();
GL11.glPushMatrix();
GL11.glTranslatef(renderX, renderY, 0);
GL11.glScalef(scale, scale, 1.0f);
renderItem.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), magic.item, 0, 0);
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
} else if (magic.iconTexture != null && !magic.iconTexture.isEmpty()) {
ImageData imageData = ClientCacheHandler.getImageData(magic.iconTexture);
if (imageData != null && imageData.imageLoaded()) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_ALPHA_TEST);
imageData.bindTexture();
int texWidth = imageData.getTotalWidth();
int texX = posX - size / 2;
int texY = posY - size / 2;
func_152125_a(texX, texY, 0, 0, texWidth, texWidth, size, size, texWidth, texWidth);
GL11.glPopAttrib();
}
} else {
RenderHelper.enableGUIStandardItemLighting();
GL11.glPushMatrix();
GL11.glTranslatef(renderX, renderY, 0);
GL11.glScalef(scale, scale, 1.0f);
ItemStack sword = new ItemStack(Items.iron_sword);
renderItem.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), sword, 0, 0);
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
}
if (state == IconRenderState.NOT_HIGHLIGHTED) {
int rectX = posX - size / 2;
int rectY = posY - size / 2;
drawRect(rectX, rectY, rectX + size, rectY + size, 0x80202020);
}
GL11.glColor4f(1f, 1f, 1f, 1f);
}
@Override
protected List<String> getIconTooltip(DiagramIcon icon) {
Magic magic = ((MagicIcon) icon).magic;
List<String> tooltip = new ArrayList<>();
tooltip.add(magic.getDisplayName());
return tooltip;
}
@Override
protected String getIconName(DiagramIcon icon) {
Magic magic = ((MagicIcon) icon).magic;
return magic.getName();
}
// Inner class wrapping a Magic as a DiagramIcon.
private class MagicIcon extends DiagramIcon {
public Magic magic;
public MagicIcon(Magic magic) {
super(magic.id, 0, 0);
this.magic = magic;
}
}
@Override
protected void drawHoveringText(List<String> text, int mouseX, int mouseY, FontRenderer fontRenderer) {
parent.renderHoveringText(text, mouseX, mouseY, fontRenderer);
}
}
Loaded 100 of 799 files, more files were not shown because too many files have changed in this diff. Show more