diff --git a/src/main/java/foxz/command/CmdConfig.java b/src/main/java/foxz/command/CmdConfig.java index d947513b0..e712fa4ca 100644 --- a/src/main/java/foxz/command/CmdConfig.java +++ b/src/main/java/foxz/command/CmdConfig.java @@ -5,6 +5,9 @@ import foxz.commandhelper.annotations.Command; import foxz.commandhelper.annotations.SubCommand; import foxz.commandhelper.permissions.OpOnly; import foxz.commandhelper.permissions.PlayerOnly; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumConfigOperation; +import kamkeel.npcs.network.packets.client.ConfigCommandPacket; import net.minecraft.block.Block; import net.minecraft.block.BlockIce; import net.minecraft.block.BlockLeavesBase; @@ -207,6 +210,6 @@ public class CmdConfig extends ChMcLogger { for(int i = 0; i < args.length; i++){ font += " " + args[i]; } - Server.sendData((EntityPlayerMP)this.pcParam, EnumPacketClient.CONFIG, 0, font.trim(), size); + PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP)this.pcParam); } } diff --git a/src/main/java/foxz/command/CmdDialog.java b/src/main/java/foxz/command/CmdDialog.java index 6dfa15a4f..842611930 100644 --- a/src/main/java/foxz/command/CmdDialog.java +++ b/src/main/java/foxz/command/CmdDialog.java @@ -11,7 +11,6 @@ import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.client.EntityUtil; import noppes.npcs.controllers.DialogController; -import noppes.npcs.controllers.SyncController; import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.controllers.data.PlayerData; diff --git a/src/main/java/kamkeel/npcs/command/ConfigCommand.java b/src/main/java/kamkeel/npcs/command/ConfigCommand.java index 89d22db44..0459e469a 100644 --- a/src/main/java/kamkeel/npcs/command/ConfigCommand.java +++ b/src/main/java/kamkeel/npcs/command/ConfigCommand.java @@ -1,6 +1,9 @@ package kamkeel.npcs.command; import foxz.utils.Market; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumConfigOperation; +import kamkeel.npcs.network.packets.client.ConfigCommandPacket; import net.minecraft.block.Block; import net.minecraft.block.BlockIce; import net.minecraft.block.BlockLeavesBase; @@ -291,8 +294,7 @@ public class ConfigCommand extends CommandKamkeelBase { for(int i = 0; i < args.length; i++){ font += " " + args[i]; } - Server.sendData((EntityPlayerMP)sender, EnumPacketClient.CONFIG, 0, font.trim(), size); + PacketHandler.Instance.sendToPlayer(new ConfigCommandPacket(EnumConfigOperation.FONT, font.trim(), size), (EntityPlayerMP)sender); } - } diff --git a/src/main/java/kamkeel/npcs/command/DialogCommand.java b/src/main/java/kamkeel/npcs/command/DialogCommand.java index c139e9b09..d89311880 100644 --- a/src/main/java/kamkeel/npcs/command/DialogCommand.java +++ b/src/main/java/kamkeel/npcs/command/DialogCommand.java @@ -11,7 +11,6 @@ import noppes.npcs.constants.EnumAvailabilityDialog; import noppes.npcs.constants.EnumAvailabilityQuest; import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.PlayerDataController; -import noppes.npcs.controllers.SyncController; import noppes.npcs.controllers.data.Availability; import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.DialogOption; diff --git a/src/main/java/kamkeel/npcs/controllers/SyncMaster.java b/src/main/java/kamkeel/npcs/controllers/SyncMaster.java index af1bcad98..6f8332934 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncMaster.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncMaster.java @@ -10,10 +10,13 @@ import kamkeel.npcs.network.enums.EnumSyncType; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.Server; import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.FactionController; import noppes.npcs.controllers.QuestController; +import noppes.npcs.controllers.RecipeController; import noppes.npcs.controllers.data.*; import java.util.HashMap; @@ -45,10 +48,48 @@ public class SyncMaster { questCategoriesNBT() ), player); + // 4) Workbench Recipes + PacketHandler.Instance.sendToPlayer(new LargeSyncPacket( + EnumSyncType.WORKBENCH_RECIPES, + EnumSyncAction.RELOAD, + -1, + workbenchNBT() + ), player); + + // 5) Carpentry Recipes + PacketHandler.Instance.sendToPlayer(new LargeSyncPacket( + EnumSyncType.CARPENTRY_RECIPES, + EnumSyncAction.RELOAD, + -1, + carpentryNBT() + ), player); + DBCAddon.instance.syncPlayer(player); syncPlayerData(player, false); } + public static NBTTagCompound workbenchNBT(){ + RecipeController controller = RecipeController.Instance; + NBTTagList list = new NBTTagList(); + NBTTagCompound compound = new NBTTagCompound(); + for(RecipeCarpentry recipe : controller.globalRecipes.values()){ + list.appendTag(recipe.writeNBT()); + } + compound.setTag("recipes", list); + return compound; + } + + public static NBTTagCompound carpentryNBT(){ + RecipeController controller = RecipeController.Instance; + NBTTagList list = new NBTTagList(); + NBTTagCompound compound = new NBTTagCompound(); + for(RecipeCarpentry recipe : controller.carpentryRecipes.values()){ + list.appendTag(recipe.writeNBT()); + } + compound.setTag("recipes", list); + return compound; + } + public static NBTTagCompound factionsNBT(){ NBTTagList list = new NBTTagList(); NBTTagCompound compound = new NBTTagCompound(); @@ -144,6 +185,24 @@ public class SyncMaster { )); } + public static void syncAllWorkbenchRecipes() { + PacketHandler.Instance.sendToAll(new LargeSyncPacket( + EnumSyncType.WORKBENCH_RECIPES, + EnumSyncAction.RELOAD, + -1, + workbenchNBT() + )); + } + + public static void syncAllCarpentryRecipes() { + PacketHandler.Instance.sendToAll(new LargeSyncPacket( + EnumSyncType.CARPENTRY_RECIPES, + EnumSyncAction.RELOAD, + -1, + carpentryNBT() + )); + } + @SideOnly(Side.CLIENT) public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) { switch (enumSyncType){ @@ -238,6 +297,36 @@ public class SyncMaster { ClientCacheHandler.playerData.setSyncNBTFull(fullCompound); break; } + case WORKBENCH_RECIPES: { + NBTTagList list = fullCompound.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); + } + + RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes); + RecipeController.syncRecipes = new HashMap(); + break; + } + case CARPENTRY_RECIPES: { + NBTTagList list = fullCompound.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); + } + + RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes; + RecipeController.syncRecipes = new HashMap(); + break; + } } } diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index c65ae3d00..c3bf6b871 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -60,6 +60,9 @@ public final class PacketHandler { CLIENT_PACKET.registerPacket(new RolePacket()); CLIENT_PACKET.registerPacket(new GuiTeleporterPacket()); CLIENT_PACKET.registerPacket(new SoundManagementPacket()); + CLIENT_PACKET.registerPacket(new ParticlePacket()); + CLIENT_PACKET.registerPacket(new ScriptedParticlePacket()); + CLIENT_PACKET.registerPacket(new ConfigCommandPacket()); // Client | GUI Packets CLIENT_PACKET.registerPacket(new GuiClosePacket()); @@ -70,10 +73,6 @@ public final class PacketHandler { // Client | NPC Packets CLIENT_PACKET.registerPacket(new DeleteNpcPacket()); - - // Client | Other - CLIENT_PACKET.registerPacket(new ParticlePacket()); - CLIENT_PACKET.registerPacket(new ScriptedParticlePacket()); } private void registerChannels() { diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumConfigOperation.java b/src/main/java/kamkeel/npcs/network/enums/EnumConfigOperation.java new file mode 100644 index 000000000..d210c00a9 --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/enums/EnumConfigOperation.java @@ -0,0 +1,5 @@ +package kamkeel.npcs.network.enums; + +public enum EnumConfigOperation { + FONT, +} diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java b/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java index e66957598..e573f5346 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java @@ -7,5 +7,7 @@ public enum EnumSyncType { QUEST, QUEST_CATEGORY, PLAYERDATA, - MAGIC + MAGIC, + WORKBENCH_RECIPES, + CARPENTRY_RECIPES } diff --git a/src/main/java/kamkeel/npcs/network/packets/client/ConfigCommandPacket.java b/src/main/java/kamkeel/npcs/network/packets/client/ConfigCommandPacket.java index cb85e4f28..506e8032e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/client/ConfigCommandPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/client/ConfigCommandPacket.java @@ -7,6 +7,8 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumClientPacket; +import kamkeel.npcs.network.enums.EnumConfigOperation; +import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.CustomNpcs; import noppes.npcs.Server; @@ -20,8 +22,16 @@ import java.io.IOException; public final class ConfigCommandPacket extends AbstractPacket { public static final String packetName = "Client|ConfigCommand"; + private EnumConfigOperation configOperation; + private Object[] objects; + public ConfigCommandPacket() {} + public ConfigCommandPacket(EnumConfigOperation operation, Object... obs) { + this.configOperation = operation; + this.objects = obs; + } + @Override public Enum getType() { return EnumClientPacket.CONFIG; @@ -34,15 +44,16 @@ public final class ConfigCommandPacket extends AbstractPacket { @Override public void sendData(ByteBuf out) throws IOException { - // TODO: Send Packet + out.writeInt(this.configOperation.ordinal()); + ByteBufUtils.fillBuffer(out, objects); } @SideOnly(Side.CLIENT) @Override public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { - int configType = in.readInt(); - if (configType == 0) { // Font Configuration - String font = Server.readString(in); + EnumConfigOperation configType = EnumConfigOperation.values()[in.readInt()]; + if (configType == EnumConfigOperation.FONT) { // Font Configuration + String font = ByteBufUtils.readString(in); int size = in.readInt(); if (!font.isEmpty()) { ConfigClient.FontType = font; diff --git a/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncConfigPacket.java b/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncConfigPacket.java index b27bc4dd9..f1e6ad99f 100644 --- a/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncConfigPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncConfigPacket.java @@ -9,9 +9,7 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumClientPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.CustomNpcs; import noppes.npcs.Server; -import noppes.npcs.controllers.SyncController; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncRecipesCarpentryBenchPacket.java b/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncRecipesCarpentryBenchPacket.java index d30ca5643..c82b39987 100644 --- a/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncRecipesCarpentryBenchPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/client/sync/SyncRecipesCarpentryBenchPacket.java @@ -8,7 +8,6 @@ import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumClientPacket; import net.minecraft.entity.player.EntityPlayer; -import noppes.npcs.CustomNpcs; import noppes.npcs.controllers.RecipeController; import java.io.IOException; @@ -36,7 +35,7 @@ public final class SyncRecipesCarpentryBenchPacket extends AbstractPacket { @SideOnly(Side.CLIENT) @Override public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { - RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes; + RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes; RecipeController.syncRecipes.clear(); } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index bdd8978c8..56f6cbf05 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -591,7 +591,7 @@ public class NoppesUtilServer { } } else{ - for(RecipeCarpentry recipe : RecipeController.Instance.anvilRecipes.values()){ + for(RecipeCarpentry recipe : RecipeController.Instance.carpentryRecipes.values()){ map.put(recipe.name, recipe.id); } } diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 7b01dd466..3c8d18487 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -3,9 +3,13 @@ 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.SyncMaster; 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.client.SoundManagementPacket; +import kamkeel.npcs.network.packets.client.large.LargeSyncPacket; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -24,13 +28,11 @@ 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.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; @@ -48,7 +50,6 @@ 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; @@ -197,48 +198,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 LargeSyncPacket( + EnumSyncType.WORKBENCH_RECIPES, + EnumSyncAction.RELOAD, + -1, + SyncMaster.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 LargeSyncPacket( + EnumSyncType.CARPENTRY_RECIPES, + EnumSyncAction.RELOAD, + -1, + SyncMaster.carpentryNBT() + ), (EntityPlayerMP) player); } if((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK){ ItemStack item = player.inventory.getCurrentItem(); diff --git a/src/main/java/noppes/npcs/ServerTickHandler.java b/src/main/java/noppes/npcs/ServerTickHandler.java index 0532401e6..e121889c3 100644 --- a/src/main/java/noppes/npcs/ServerTickHandler.java +++ b/src/main/java/noppes/npcs/ServerTickHandler.java @@ -11,7 +11,6 @@ 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; diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index c3c41c549..15bc2e6ba 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -9,35 +9,23 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ChatComponentTranslation; 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{ @@ -53,30 +41,7 @@ public class PacketHandlerClient extends PacketHandlerServer{ } private void client(ByteBuf buffer, final EntityPlayer player, EnumPacketClient type) throws IOException{ - 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(); - } - else if(type == EnumPacketClient.SYNCRECIPES_CARPENTRYBENCH){ - RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes; - RecipeController.syncRecipes = new HashMap(); - } - else if(type == EnumPacketClient.SYNC_CONFIG){ - NBTTagCompound configNBT = Server.readNBT(buffer); - SyncController.receiveConfigs(configNBT); - } - else if(type == EnumPacketClient.MARK_DATA){ + if(type == EnumPacketClient.MARK_DATA){ Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt()); if(!(entity instanceof EntityNPCInterface)) return; @@ -92,12 +57,6 @@ public class PacketHandlerClient extends PacketHandlerServer{ 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.UPDATE_NPC){ NBTTagCompound compound = Server.readNBT(buffer); Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(compound.getInteger("EntityId")); @@ -118,12 +77,6 @@ public class PacketHandlerClient extends PacketHandlerServer{ EnumGuiType gui = EnumGuiType.values()[buffer.readInt()]; CustomNpcs.proxy.openGui(NoppesUtil.getLastNpc(), gui, buffer.readInt(), buffer.readInt(), buffer.readInt()); } - 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_SELECTED){ GuiScreen gui = Minecraft.getMinecraft().currentScreen; if(gui == null || !(gui instanceof IScrollData)) @@ -193,28 +146,6 @@ public class PacketHandlerClient extends PacketHandlerServer{ 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; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java b/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java index 290a02b5f..b40544fa2 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java @@ -15,7 +15,7 @@ public class GuiNpcCarpentryBench extends GuiContainerNPCInterface private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/carpentry.png"); private ContainerCarpentryBench container; private GuiNpcButton button; - + public GuiNpcCarpentryBench(ContainerCarpentryBench container) { super(null,container); @@ -38,7 +38,7 @@ public class GuiNpcCarpentryBench extends GuiContainerNPCInterface @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { - button.enabled = RecipeController.Instance != null && !RecipeController.Instance.anvilRecipes.isEmpty(); + button.enabled = RecipeController.Instance != null && !RecipeController.Instance.carpentryRecipes.isEmpty(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(resource); int l = (width - xSize) / 2; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiRecipes.java b/src/main/java/noppes/npcs/client/gui/player/GuiRecipes.java index 5e0c94073..64895af87 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiRecipes.java @@ -33,7 +33,7 @@ public class GuiRecipes extends GuiNPCInterface this.xSize = 256; setBackground("recipes.png"); this.closeOnEsc = true; - recipes.addAll(RecipeController.Instance.anvilRecipes.values()); + recipes.addAll(RecipeController.Instance.carpentryRecipes.values()); } @Override public void initGui(){ @@ -47,7 +47,7 @@ public class GuiRecipes extends GuiNPCInterface addButton(this.left = new GuiButtonNextPage(1, guiLeft + 150, guiTop + 164, true)); addButton(this.right = new GuiButtonNextPage(2, guiLeft + 80, guiTop + 164, false)); - + updateButton(); } private void updateButton(){ @@ -67,10 +67,10 @@ public class GuiRecipes extends GuiNPCInterface private List getSearchList(){ if(search.isEmpty()){ - return new ArrayList(RecipeController.Instance.anvilRecipes.values()); + return new ArrayList(RecipeController.Instance.carpentryRecipes.values()); } List list = new ArrayList(); - for(IRecipe recipe : RecipeController.Instance.anvilRecipes.values()){ + for(IRecipe recipe : RecipeController.Instance.carpentryRecipes.values()){ if(recipe.getRecipeOutput() == null) continue; @@ -96,12 +96,12 @@ public class GuiRecipes extends GuiNPCInterface page++; updateButton(); } - + @Override public void drawScreen(int xMouse, int yMouse, float f){ super.drawScreen(xMouse, yMouse, f); mc.renderEngine.bindTexture(resource); - + label.label = page + 1 + "/" + MathHelper.ceiling_float_int(recipes.size() / 4f); label.x = guiLeft + (256 - Minecraft.getMinecraft().fontRenderer.getStringWidth(label.label)) / 2; for(int i = 0; i < 4; i++){ @@ -165,11 +165,11 @@ public class GuiRecipes extends GuiNPCInterface itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, item, x, y); itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, item, x, y); itemRender.zLevel = 0.0F; - RenderHelper.disableStandardItemLighting(); + RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); } - + private void drawOverlay(ItemStack item, int x, int y, int xMouse, int yMouse){ if (this.func_146978_c(x - guiLeft, y - guiTop, 16, 16, xMouse, yMouse)){ this.renderToolTip(item, xMouse, yMouse); @@ -187,4 +187,4 @@ public class GuiRecipes extends GuiNPCInterface @Override public void save() { } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 22992e872..4d4032d19 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -2,15 +2,11 @@ package noppes.npcs.constants; public enum EnumPacketClient { - SYNCRECIPES_ADD, - SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, - EDIT_NPC, UPDATE_NPC, ROLE, GUI, - DELETE_NPC, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, @@ -18,11 +14,9 @@ public enum EnumPacketClient { GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, - SYNCRECIPES_CARPENTRYBENCH, CLONE, TELEPORTER, OPEN_BOOK, - CONFIG, ISGUIOPEN, SCRIPT_OVERLAY_DATA, SCRIPT_OVERLAY_CLOSE, @@ -34,6 +28,5 @@ public enum EnumPacketClient { DISABLE_MOUSE_INPUT, SYNC_WEAPON, MARK_DATA, - SYNC_CONFIG, PARTY_DATA } diff --git a/src/main/java/noppes/npcs/controllers/RecipeController.java b/src/main/java/noppes/npcs/controllers/RecipeController.java index bd129f508..e1b5d84f9 100644 --- a/src/main/java/noppes/npcs/controllers/RecipeController.java +++ b/src/main/java/noppes/npcs/controllers/RecipeController.java @@ -1,5 +1,6 @@ package noppes.npcs.controllers; +import kamkeel.npcs.controllers.SyncMaster; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; @@ -21,7 +22,7 @@ import java.util.*; public class RecipeController implements IRecipeHandler { private static Collection prevRecipes; public HashMap globalRecipes = new HashMap(); - public HashMap anvilRecipes = new HashMap(); + public HashMap carpentryRecipes = new HashMap(); public static RecipeController Instance; public static final int version = 1; @@ -59,7 +60,7 @@ public class RecipeController implements IRecipeHandler { } else{ globalRecipes.clear(); - anvilRecipes.clear(); + carpentryRecipes.clear(); loadDefaultRecipes(-1); } } catch (Exception e) { @@ -99,7 +100,7 @@ public class RecipeController implements IRecipeHandler { nextId = recipe.id; } } - this.anvilRecipes = anvilRecipes; + this.carpentryRecipes = anvilRecipes; this.globalRecipes = globalRecipes; loadDefaultRecipes(nbttagcompound1.getInteger("Version")); } @@ -110,7 +111,7 @@ public class RecipeController implements IRecipeHandler { for(RecipeCarpentry recipe : globalRecipes.values()){ list.appendTag(recipe.writeNBT()); } - for(RecipeCarpentry recipe : anvilRecipes.values()){ + for(RecipeCarpentry recipe : carpentryRecipes.values()){ list.appendTag(recipe.writeNBT()); } NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -141,7 +142,7 @@ public class RecipeController implements IRecipeHandler { } public RecipeCarpentry findMatchingRecipe(InventoryCrafting par1InventoryCrafting){ - for(RecipeCarpentry recipe : anvilRecipes.values()){ + for(RecipeCarpentry recipe : carpentryRecipes.values()){ if(recipe.isValid() && recipe.matches(par1InventoryCrafting,null)) return recipe; } @@ -151,8 +152,8 @@ public class RecipeController implements IRecipeHandler { public RecipeCarpentry getRecipe(int id) { if(globalRecipes.containsKey(id)) return globalRecipes.get(id); - if(anvilRecipes.containsKey(id)) - return anvilRecipes.get(id); + if(carpentryRecipes.containsKey(id)) + return carpentryRecipes.get(id); return null; } @@ -171,12 +172,12 @@ public class RecipeController implements IRecipeHandler { recipe.name += "_"; } if(recipe.isGlobal){ - anvilRecipes.remove(recipe.id); + carpentryRecipes.remove(recipe.id); globalRecipes.put(recipe.id, recipe); } else{ globalRecipes.remove(recipe.id); - anvilRecipes.put(recipe.id, recipe); + carpentryRecipes.put(recipe.id, recipe); } saveCategories(); reloadGlobalRecipes(globalRecipes); @@ -192,7 +193,7 @@ public class RecipeController implements IRecipeHandler { if(recipe.name.toLowerCase().equals(name)) return true; } - for(RecipeCarpentry recipe : anvilRecipes.values()){ + for(RecipeCarpentry recipe : carpentryRecipes.values()){ if(recipe.name.toLowerCase().equals(name)) return true; } @@ -203,8 +204,14 @@ public class RecipeController implements IRecipeHandler { RecipeCarpentry recipe = getRecipe(id); if(recipe == null) return null; - globalRecipes.remove(recipe.id); - anvilRecipes.remove(recipe.id); + RecipeCarpentry globalRecipe = globalRecipes.remove(recipe.id); + if(globalRecipe != null) + SyncMaster.syncAllWorkbenchRecipes(); + + RecipeCarpentry carpentry = carpentryRecipes.remove(recipe.id); + if(carpentry != null) + SyncMaster.syncAllWorkbenchRecipes(); + saveCategories(); reloadGlobalRecipes(globalRecipes); return recipe; @@ -212,7 +219,7 @@ public class RecipeController implements IRecipeHandler { public void addRecipe(RecipeCarpentry recipeAnvil) { recipeAnvil.id = getUniqueId(); if(!recipeAnvil.isGlobal) - RecipeController.Instance.anvilRecipes.put(recipeAnvil.id, recipeAnvil); + RecipeController.Instance.carpentryRecipes.put(recipeAnvil.id, recipeAnvil); else{ RecipeController.Instance.globalRecipes.put(recipeAnvil.id, recipeAnvil); } @@ -223,7 +230,7 @@ public class RecipeController implements IRecipeHandler { } public List getCarpentryList() { - return new ArrayList(this.anvilRecipes.values()); + return new ArrayList(this.carpentryRecipes.values()); } public void addRecipe(String name, boolean global, ItemStack result, Object... objects) { diff --git a/src/main/java/noppes/npcs/controllers/SyncController.java b/src/main/java/noppes/npcs/controllers/SyncController.java deleted file mode 100644 index d66792574..000000000 --- a/src/main/java/noppes/npcs/controllers/SyncController.java +++ /dev/null @@ -1,25 +0,0 @@ -package noppes.npcs.controllers; - -import io.netty.buffer.ByteBuf; -import kamkeel.npcs.addon.DBCAddon; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.Server; -import noppes.npcs.config.ConfigMain; -import noppes.npcs.constants.EnumPacketClient; - -public class SyncController { - - public static void syncConfigs(EntityPlayerMP player){ - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - nbtTagCompound.setBoolean("Profiles", true); - Server.sendData(player, EnumPacketClient.SYNC_CONFIG, nbtTagCompound); - } - - public static void receiveConfigs(NBTTagCompound compound){ - ConfigMain.EnableProfiles = compound.getBoolean("Profiles"); - } - -}