From 207d9f6124b9e6a39ce6f68db770b5a0ebede823 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 12 Mar 2025 05:00:21 -0400 Subject: [PATCH] Item Config + Machine Gun Fixes --- src/main/java/foxz/command/CmdConfig.java | 9 +- .../kamkeel/npcs/command/ConfigCommand.java | 9 +- src/main/java/noppes/npcs/CustomItems.java | 8 +- .../java/noppes/npcs/client/ClientProxy.java | 3 +- .../java/noppes/npcs/config/ConfigItem.java | 82 +++++++ .../java/noppes/npcs/config/ConfigMain.java | 29 +-- .../noppes/npcs/config/LoadConfiguration.java | 3 + .../npcs/controllers/data/RecipesDefault.java | 8 +- src/main/java/noppes/npcs/items/ItemGun.java | 16 +- .../noppes/npcs/items/ItemMachineGun.java | 222 ++++++++++-------- .../java/noppes/npcs/items/ItemMusket.java | 24 +- .../assets/customnpcs/lang/en_US.lang | 1 + 12 files changed, 258 insertions(+), 156 deletions(-) create mode 100644 src/main/java/noppes/npcs/config/ConfigItem.java diff --git a/src/main/java/foxz/command/CmdConfig.java b/src/main/java/foxz/command/CmdConfig.java index 597db83a1..081624148 100644 --- a/src/main/java/foxz/command/CmdConfig.java +++ b/src/main/java/foxz/command/CmdConfig.java @@ -14,6 +14,7 @@ import net.minecraft.block.BlockLeavesBase; import net.minecraft.block.BlockVine; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcs; +import noppes.npcs.config.ConfigItem; import noppes.npcs.config.ConfigMain; import noppes.npcs.controllers.ChunkController; @@ -123,15 +124,15 @@ public class CmdConfig extends ChMcLogger { ) public boolean guns(String[] args){ if(args.length == 0){ - sendmessage("GunsEnabled: " + ConfigMain.GunsEnabled); + sendmessage("GunsEnabled: " + ConfigItem.GunsEnabled); } else{ - ConfigMain.GunsEnabled = Boolean.parseBoolean(args[0]); - ConfigMain.GunsEnabledProperty.set(ConfigMain.GunsEnabled); + ConfigItem.GunsEnabled = Boolean.parseBoolean(args[0]); + ConfigItem.GunsEnabledProperty.set(ConfigItem.GunsEnabled); if(ConfigMain.config.hasChanged()){ ConfigMain.config.save(); } - sendmessage("GunsEnabled is now " + ConfigMain.GunsEnabled); + sendmessage("GunsEnabled is now " + ConfigItem.GunsEnabled); } return true; } diff --git a/src/main/java/kamkeel/npcs/command/ConfigCommand.java b/src/main/java/kamkeel/npcs/command/ConfigCommand.java index b432df26e..c7eb467e6 100644 --- a/src/main/java/kamkeel/npcs/command/ConfigCommand.java +++ b/src/main/java/kamkeel/npcs/command/ConfigCommand.java @@ -13,6 +13,7 @@ import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomNpcs; +import noppes.npcs.config.ConfigItem; import noppes.npcs.config.ConfigMain; import noppes.npcs.controllers.ChunkController; import noppes.npcs.controllers.PlayerDataController; @@ -121,15 +122,15 @@ public class ConfigCommand extends CommandKamkeelBase { ) public void guns(ICommandSender sender, String[] args){ if(args.length == 0){ - sendResult(sender, "GunsEnabled: \u00A7c" + ConfigMain.GunsEnabled); + sendResult(sender, "GunsEnabled: \u00A7c" + ConfigItem.GunsEnabled); } else{ - ConfigMain.GunsEnabled = Boolean.parseBoolean(args[0]); - ConfigMain.GunsEnabledProperty.set(ConfigMain.GunsEnabled); + ConfigItem.GunsEnabled = Boolean.parseBoolean(args[0]); + ConfigItem.GunsEnabledProperty.set(ConfigItem.GunsEnabled); if(ConfigMain.config.hasChanged()){ ConfigMain.config.save(); } - sendResult(sender, "GunsEnabled is now \u00A7c" + ConfigMain.GunsEnabled); + sendResult(sender, "GunsEnabled is now \u00A7c" + ConfigItem.GunsEnabled); } } diff --git a/src/main/java/noppes/npcs/CustomItems.java b/src/main/java/noppes/npcs/CustomItems.java index fe7864812..0dfbb421e 100644 --- a/src/main/java/noppes/npcs/CustomItems.java +++ b/src/main/java/noppes/npcs/CustomItems.java @@ -15,7 +15,7 @@ import net.minecraftforge.common.util.EnumHelper; import net.minecraftforge.oredict.OreDictionary; import noppes.npcs.blocks.*; import noppes.npcs.blocks.tiles.*; -import noppes.npcs.config.ConfigMain; +import noppes.npcs.config.ConfigItem; import noppes.npcs.constants.EnumNpcToolMaterial; import noppes.npcs.items.*; @@ -216,7 +216,7 @@ public class CustomItems { GameRegistry.registerTileEntity(TileBanner.class, "TileNPCBanner"); GameRegistry.registerTileEntity(TileScripted.class, "TileNPCScripted"); - if(!ConfigMain.DisableExtraBlock){ + if(!ConfigItem.DisableExtraBlock){ GameRegistry.registerTileEntity(TileWallBanner.class, "TileNPCWallBanner"); GameRegistry.registerTileEntity(TileTallLamp.class, "TileNPCTallLamp"); GameRegistry.registerTileEntity(TileShortLamp.class, "TileNPCShortLamp"); @@ -284,7 +284,7 @@ public class CustomItems { ((ItemNpcBlock)Item.getItemFromBlock(carpentyBench)).names = new String[]{"tile.npcCarpentyBench", "tile.anvil"}; - if(!ConfigMain.DisableExtraBlock){ + if(!ConfigItem.DisableExtraBlock){ blood = new BlockBlood().setBlockName("npcBloodBlock").setBlockTextureName("customnpcs:npcBloodBlock").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); @@ -376,7 +376,7 @@ public class CustomItems { clarinet = new ItemMusicClarinet().setUnlocalizedName("npcClarinet").setFull3D().setMaxStackSize(1).setTextureName("customnpcs:npcClarinet"); - if(!ConfigMain.DisableExtraItems){ + if(!ConfigItem.DisableExtraItems){ tabArmor = new CreativeTabNpcs("cnpcsa"); tabWeapon = new CreativeTabNpcs("cnpcsw"); diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 5a4b640e5..1e1607567 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -59,6 +59,7 @@ import noppes.npcs.client.renderer.*; import noppes.npcs.client.renderer.blocks.*; import noppes.npcs.client.renderer.items.*; import noppes.npcs.config.ConfigClient; +import noppes.npcs.config.ConfigItem; import noppes.npcs.config.ConfigMain; import noppes.npcs.config.StringCache; import noppes.npcs.constants.EnumGuiType; @@ -111,7 +112,7 @@ public class ClientProxy extends CommonProxy { MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.scripted), new ScriptedBlockItemRenderer()); RenderingRegistry.registerBlockHandler(new BlockBorderRenderer()); - if(!ConfigMain.DisableExtraBlock){ + if(!ConfigItem.DisableExtraBlock){ ClientRegistry.bindTileEntitySpecialRenderer(TileBanner.class, new BlockBannerRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileWallBanner.class, new BlockWallBannerRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileTallLamp.class, new BlockTallLampRenderer()); diff --git a/src/main/java/noppes/npcs/config/ConfigItem.java b/src/main/java/noppes/npcs/config/ConfigItem.java new file mode 100644 index 000000000..6bf997152 --- /dev/null +++ b/src/main/java/noppes/npcs/config/ConfigItem.java @@ -0,0 +1,82 @@ +package noppes.npcs.config; + +import cpw.mods.fml.common.FMLLog; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import noppes.npcs.CustomNpcs; +import noppes.npcs.config.legacy.LegacyConfig; +import org.apache.logging.log4j.Level; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ConfigItem +{ + public static Configuration config; + + public final static String ALL = "All"; + public final static String GUN = "Gun"; + /** + * Item Properties + **/ + public static Property DisableExtraBlockProperty; + public static boolean DisableExtraBlock = false; + public static Property DisableExtraItemsProperty; + public static boolean DisableExtraItems = false; + public static Property GunsEnabledProperty; + public static boolean GunsEnabled = true; + public static int MachineGunAmmo = 8; + public static int MachineGunTickSpeed = 6; + + /** + * Item Properties + **/ + + + public static void init(File configFile) + { + config = new Configuration(configFile); + + try + { + config.load(); + + // ITEMS + DisableExtraBlockProperty = config.get(ALL, "Disable Extra Blocks", false); + DisableExtraBlock = DisableExtraBlockProperty.getBoolean(false); + + DisableExtraItemsProperty = config.get(ALL, "Disable Extra Items", false); + DisableExtraItems = DisableExtraItemsProperty.getBoolean(false); + + // Gun + GunsEnabledProperty = config.get(GUN, "Guns Enabled", true, "Set to false if you want to disable guns"); + GunsEnabled = GunsEnabledProperty.getBoolean(true); + MachineGunAmmo = config.get(GUN, "Machine Gun Ammo", 8, "Max Clip of a Machine Gun").getInt(8); + MachineGunTickSpeed = config.get(GUN, "Machine Gun Fire Rate", 6, "How many ticks to shoot bullets at").getInt(6); + + // Convert to Legacy + if(CustomNpcs.legacyExist){ + DisableExtraBlock = LegacyConfig.DisableExtraBlock; + DisableExtraBlockProperty.set(DisableExtraBlock); + + DisableExtraItems = LegacyConfig.DisableExtraItems; + DisableExtraItemsProperty.set(DisableExtraItems); + + GunsEnabled = LegacyConfig.GunsEnabled; + GunsEnabledProperty.set(GunsEnabled); + } + } + catch (Exception e) + { + FMLLog.log(Level.ERROR, e, "CNPC+ has had a problem loading its item configuration"); + } + finally + { + if (config.hasChanged()) { + config.save(); + } + } + } +} diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index 4eaae5c5a..d58fa0346 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -22,6 +22,7 @@ public class ConfigMain public final static String PARTY = "PARTY"; public final static String PROFILES = "Profile"; public final static String ATTRIBUTES = "Attributes"; + public final static String ITEM = "Item"; /** * General Main Properties @@ -30,18 +31,9 @@ public class ConfigMain public static Property EnableUpdateCheckerProperty; public static boolean EnableUpdateChecker = true; - public static Property DisableExtraBlockProperty; - public static boolean DisableExtraBlock = false; - - public static Property DisableExtraItemsProperty; - public static boolean DisableExtraItems = false; - public static Property DisableEnchantsProperty; public static boolean DisableEnchants = false; - public static Property GunsEnabledProperty; - public static boolean GunsEnabled = true; - public static Property EnchantStartIdProperty; public static int EnchantStartId = 100; @@ -154,15 +146,6 @@ public class ConfigMain EnableUpdateCheckerProperty = config.get(GENERAL, "Enables Update Checker", true); EnableUpdateChecker = EnableUpdateCheckerProperty.getBoolean(true); - DisableExtraBlockProperty = config.get(GENERAL, "Disable Extra Blocks", false); - DisableExtraBlock = DisableExtraBlockProperty.getBoolean(false); - - DisableExtraItemsProperty = config.get(GENERAL, "Disable Extra Items", false); - DisableExtraItems = DisableExtraItemsProperty.getBoolean(false); - - GunsEnabledProperty = config.get(GENERAL, "Guns Enabled", true, "Set to false if you want to disable guns"); - GunsEnabled = GunsEnabledProperty.getBoolean(true); - DisableEnchantsProperty = config.get(GENERAL, "Disable Enchants", false); DisableEnchants = DisableEnchantsProperty.getBoolean(false); @@ -268,6 +251,7 @@ public class ConfigMain "Enable Attributes", "Critical Amount" }))); + // Attributes AttributesEnabled = config.get(ATTRIBUTES, "Enable Attributes", true, "Allows Attributes to be applied to Items and Armors").getBoolean(true); AttributesCriticalBoost = config.get(ATTRIBUTES, "Critical Amount", 100, "The boost in damage received by achieving a critical hit. Takes an number so 100 is 100% extra damage").getInt(100); @@ -277,18 +261,9 @@ public class ConfigMain EnableUpdateChecker = LegacyConfig.EnableUpdateChecker; EnableUpdateCheckerProperty.set(EnableUpdateChecker); - DisableExtraBlock = LegacyConfig.DisableExtraBlock; - DisableExtraBlockProperty.set(DisableExtraBlock); - - DisableExtraItems = LegacyConfig.DisableExtraItems; - DisableExtraItemsProperty.set(DisableExtraItems); - DisableEnchants = LegacyConfig.DisableEnchants; DisableEnchantsProperty.set(DisableEnchants); - GunsEnabled = LegacyConfig.GunsEnabled; - GunsEnabledProperty.set(GunsEnabled); - EnchantStartId = LegacyConfig.EnchantStartId; EnchantStartIdProperty.set(EnchantStartId); diff --git a/src/main/java/noppes/npcs/config/LoadConfiguration.java b/src/main/java/noppes/npcs/config/LoadConfiguration.java index 43152620b..1b3310b96 100644 --- a/src/main/java/noppes/npcs/config/LoadConfiguration.java +++ b/src/main/java/noppes/npcs/config/LoadConfiguration.java @@ -6,6 +6,7 @@ import java.io.File; public class LoadConfiguration { public static File mainConfigFile; + public static File itemConfigFile; public static File scriptConfigFile; public static File debugConfigFile; public static File clientConfigFile; @@ -13,11 +14,13 @@ public class LoadConfiguration { public static void init(String configpath) { mainConfigFile = new File(configpath + "main.cfg"); + itemConfigFile = new File(configpath + "item.cfg"); clientConfigFile = new File(configpath + "client.cfg"); scriptConfigFile = new File(configpath + "script.cfg"); debugConfigFile = new File(configpath + "debug.cfg"); ConfigMain.init(mainConfigFile); + ConfigItem.init(itemConfigFile); ConfigClient.init(clientConfigFile); ConfigScript.init(scriptConfigFile); ConfigDebug.init(debugConfigFile); diff --git a/src/main/java/noppes/npcs/controllers/data/RecipesDefault.java b/src/main/java/noppes/npcs/controllers/data/RecipesDefault.java index 18040ff94..671497ec8 100644 --- a/src/main/java/noppes/npcs/controllers/data/RecipesDefault.java +++ b/src/main/java/noppes/npcs/controllers/data/RecipesDefault.java @@ -6,7 +6,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import noppes.npcs.CustomItems; -import noppes.npcs.config.ConfigMain; +import noppes.npcs.config.ConfigItem; import noppes.npcs.controllers.RecipeController; public class RecipesDefault { @@ -34,7 +34,7 @@ public class RecipesDefault { anvil.setItemDamage(1); addRecipe("Anvil", anvil, true, "XXX","Z Z","Z Z", 'X', Blocks.iron_block, 'Z', Items.iron_ingot); - if(!ConfigMain.DisableExtraItems){ + if(!ConfigItem.DisableExtraItems){ addRecipe("Mana", CustomItems.mana, true, "XY",'X',Items.redstone,'Y',Items.glowstone_dust); addRecipe("Gun Wooden", CustomItems.gunWood, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Blocks.planks); addRecipe("Gun Stone", CustomItems.gunStone, false, "XXXY"," ZM "," M ",'Y', Blocks.lever, 'M', Items.stick, 'Z', Blocks.stone_button,'X', Blocks.cobblestone); @@ -54,7 +54,7 @@ public class RecipesDefault { } } if(i < 1){ - if(!ConfigMain.DisableExtraBlock){ + if(!ConfigItem.DisableExtraBlock){ addRecipe("WallBanner Wooden", new ItemStack(CustomItems.wallBanner, 1, 0), false, "XXX","ZZZ","ZZZ","Z Z",'Z', Blocks.wool, 'X', Blocks.planks); addRecipe("WallBanner Stone", new ItemStack(CustomItems.wallBanner, 1, 1), false, "XXX","ZZZ","ZZZ","Z Z",'Z', Blocks.wool, 'X', Blocks.cobblestone); addRecipe("WallBanner Iron", new ItemStack(CustomItems.wallBanner, 1, 2), false, "XXX","ZZZ","ZZZ","Z Z",'Z', Blocks.wool, 'X', Items.iron_ingot); @@ -155,7 +155,7 @@ public class RecipesDefault { addRecipe("BigSign", new ItemStack(CustomItems.bigsign, 2), false, "XXX","XXX","XXX", 'X', Blocks.planks); } - if(!ConfigMain.DisableExtraItems){ + if(!ConfigItem.DisableExtraItems){ addRecipe("Battle Axe1", CustomItems.battleAxeWood, false, "XX","XY"," Y", " Y", 'Y', Items.stick, 'X', Blocks.planks); addRecipe("Battle Axe2", CustomItems.battleAxeStone, false, "XX","XY"," Y", " Y", 'Y', Items.stick, 'X', Blocks.cobblestone); addRecipe("Battle Axe3", CustomItems.battleAxeIron, false, "XX","XY"," Y", " Y", 'Y', Items.stick, 'X', Items.iron_ingot); diff --git a/src/main/java/noppes/npcs/items/ItemGun.java b/src/main/java/noppes/npcs/items/ItemGun.java index 9a99a1e73..a3651e4a7 100644 --- a/src/main/java/noppes/npcs/items/ItemGun.java +++ b/src/main/java/noppes/npcs/items/ItemGun.java @@ -9,7 +9,7 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; import noppes.npcs.CustomItems; -import noppes.npcs.config.ConfigMain; +import noppes.npcs.config.ConfigItem; import noppes.npcs.constants.EnumNpcToolMaterial; import noppes.npcs.enchants.EnchantInterface; import noppes.npcs.entity.EntityProjectile; @@ -31,7 +31,7 @@ public class ItemGun extends ItemNpcInterface implements IProjectileCallback{ if(worldObj.isRemote) return; - if (!hasBullet(player, stack) || !ConfigMain.GunsEnabled){ + if (!hasBullet(player, stack) || !ConfigItem.GunsEnabled){ worldObj.playSoundAtEntity(player, "customnpcs:gun.empty", 1.0F,1); return; } @@ -49,16 +49,16 @@ public class ItemGun extends ItemNpcInterface implements IProjectileCallback{ projectile.callbackItem = stack; projectile.setSpeed(40); projectile.shoot(material.getDamageVsEntity() + 1); - + if(!player.capabilities.isCreativeMode && !hasInfinite(stack)) consumeItem(player, getBullet()); - + worldObj.playSoundAtEntity(player, "customnpcs:gun.pistol.shot", 1.0F,itemRand.nextFloat() * 0.3F + 0.8F); worldObj.spawnEntityInWorld(projectile); - } + } @Override - public void onUsingTick(ItemStack stack, EntityPlayer player, int count) + public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { int ticks = getMaxItemUseDuration(stack) - count; if(ticks == 8 && !player.worldObj.isRemote){ @@ -111,11 +111,11 @@ public class ItemGun extends ItemNpcInterface implements IProjectileCallback{ return CustomItems.bulletBlack; } } - + public boolean hasInfinite(ItemStack stack){ return EnchantInterface.getLevel(EnchantInterface.Infinite, stack) > 0; } - + @Override public int getItemEnchantability(){ return this.material.getEnchantability(); diff --git a/src/main/java/noppes/npcs/items/ItemMachineGun.java b/src/main/java/noppes/npcs/items/ItemMachineGun.java index 3fc1a817e..b2b838606 100644 --- a/src/main/java/noppes/npcs/items/ItemMachineGun.java +++ b/src/main/java/noppes/npcs/items/ItemMachineGun.java @@ -1,116 +1,154 @@ package noppes.npcs.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import noppes.npcs.CustomItems; -import noppes.npcs.config.ConfigMain; +import noppes.npcs.config.ConfigItem; import noppes.npcs.entity.EntityProjectile; import org.lwjgl.opengl.GL11; -public class ItemMachineGun extends ItemNpcInterface{ +import java.util.List; - public ItemMachineGun(int par1) { - super(par1); +public class ItemMachineGun extends ItemNpcInterface { + + public ItemMachineGun(int par1) { + super(par1); this.setMaxDamage(80); setCreativeTab(CustomItems.tabWeapon); - } - public void onPlayerStoppedUsing(ItemStack stack, World par2World, EntityPlayer player, int count) { - if(player.capabilities.isCreativeMode) - return; - - int ticks = getMaxItemUseDuration(stack) - count; - int shotsleft = stack.stackTagCompound.getInteger("ShotsLeft") - ticks/6; - if(stack.stackTagCompound.getBoolean("Reloading2")){ - shotsleft = ticks/5; - if(ticks > 40) - shotsleft = 8; - if(shotsleft > 1){ - stack.stackTagCompound.setInteger("ShotsLeft", shotsleft); - stack.stackTagCompound.setBoolean("Reloading2", false); - } - } - else if(shotsleft <= 0){ - stack.stackTagCompound.setBoolean("Reloading2", true); - stack.damageItem(1, player); - } - else - stack.stackTagCompound.setInteger("ShotsLeft", shotsleft); } - @Override - public void onUsingTick(ItemStack stack, EntityPlayer player, int count) - { - if(player.worldObj.isRemote){ - return; - } - - int ticks = getMaxItemUseDuration(stack) - count; - if(ticks % 6 != 0){ - return; - } - - int shotsleft = stack.stackTagCompound.getInteger("ShotsLeft") - ticks/6; - if(!player.capabilities.isCreativeMode || !ConfigMain.GunsEnabled){ - if(stack.stackTagCompound.getBoolean("Reloading2") && hasItem(player, CustomItems.bulletBlack)){ - if(ticks > 0 && ticks <= 24){ - player.worldObj.playSoundAtEntity(player, "customnpcs:gun.ak47.load", 1.0F,1); - } - return; - } - else if((shotsleft <= 0 || !hasItem(player, CustomItems.bulletBlack)) || !ConfigMain.GunsEnabled) - { - player.worldObj.playSoundAtEntity(player, "customnpcs:gun.empty", 1.0F,1); - return; - } - }else{ - stack.stackTagCompound.removeTag("Reloading2"); - } - EntityProjectile projectile = new EntityProjectile(player.worldObj, player, new ItemStack(CustomItems.bulletBlack,1, 0), false); - projectile.damage = 4; - projectile.setSpeed(40); - projectile.shoot(2); - - if(!player.capabilities.isCreativeMode) - consumeItem(player, CustomItems.bulletBlack); - - player.worldObj.playSoundAtEntity(player, "customnpcs:gun.pistol.shot", 0.9F, itemRand.nextFloat() * 0.3F + 0.8F); - player.worldObj.spawnEntityInWorld(projectile); - - + @SideOnly(Side.CLIENT) + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { + if (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("ShotsLeft")) { + list.add(StatCollector.translateToLocalFormatted("item.npcMachineGun.info") + ": " + + stack.stackTagCompound.getInteger("ShotsLeft")); + } } - @Override - public void renderSpecial(){ - GL11.glRotatef(-6, 0, 0, 1f); - GL11.glScalef(0.8f, 0.7f,0.7f); - GL11.glTranslatef(0.2f, 0.0f, 0.2F); - } - /** - * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer - */ - @Override - public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) - { - if(stack.stackTagCompound == null) - stack.stackTagCompound = new NBTTagCompound(); - if(!player.capabilities.isCreativeMode && !hasItem(player, CustomItems.bulletBlack)) - stack.stackTagCompound.setBoolean("Reloading2", true); - player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); + + @Override + public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { + if (player.worldObj.isRemote) { // Skip if on client side + return; + } + + int ticks = getMaxItemUseDuration(stack) - count; // How many ticks you’ve been holding + ensureNBT(stack); // Make sure the item has its data tags + + int shotsLeft = stack.stackTagCompound.getInteger("ShotsLeft"); + boolean isReloading = stack.stackTagCompound.getBoolean("IsReloading"); + + if (!isReloading && shotsLeft > 0) { + if (ticks >= ConfigItem.MachineGunTickSpeed && ticks % ConfigItem.MachineGunTickSpeed == 0) { + fireShot(stack, player); // Fire a shot (decrements ShotsLeft) + shotsLeft = stack.stackTagCompound.getInteger("ShotsLeft"); + if (shotsLeft <= 0 && hasItem(player, CustomItems.bulletBlack)) { + stack.stackTagCompound.setBoolean("IsReloading", true); + } + } + } else if (isReloading && shotsLeft < ConfigItem.MachineGunAmmo && hasItem(player, CustomItems.bulletBlack)) { + if (ticks % ConfigItem.MachineGunTickSpeed - 1 == 0) { + reloadShot(stack, player); // Add a shot and consume a bullet + player.worldObj.playSoundAtEntity(player, "customnpcs:gun.ak47.load", 1.0F, 1.0F); // Play reload sound + } + } else if (ticks % ConfigItem.MachineGunTickSpeed == 0) { + // No shots or bullets left, play empty sound + player.worldObj.playSoundAtEntity(player, "customnpcs:gun.empty", 1.0F, 1.0F); + } + } + + @Override + public void onPlayerStoppedUsing(ItemStack stack, World par2World, EntityPlayer player, int count) { + if (stack.stackTagCompound == null) { + return; + } + // Stop reloading when you let go + stack.stackTagCompound.setBoolean("IsReloading", false); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + if (player.isUsingItem()) { + return stack; // Avoid glitches from spamming + } + + ensureNBT(stack); // Set up data tags if missing + int shotsLeft = stack.stackTagCompound.getInteger("ShotsLeft"); + stack.stackTagCompound.setBoolean("IsReloading", shotsLeft == 0 && hasItem(player, CustomItems.bulletBlack)); + + player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); // Start the hold action return stack; } - @Override - public int getMaxItemUseDuration(ItemStack par1ItemStack) - { + + @Override + public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } - public EnumAction getItemUseAction(ItemStack stack) - { - if(stack.stackTagCompound == null || !stack.stackTagCompound.getBoolean("Reloading2")) - return EnumAction.bow; - - return EnumAction.block; + @Override + public EnumAction getItemUseAction(ItemStack stack) { + if (stack.stackTagCompound == null || !stack.stackTagCompound.getBoolean("IsReloading")) { + return EnumAction.bow; // Firing animation + } + return EnumAction.block; // Reloading animation + } + + @Override + public void renderSpecial() { + GL11.glRotatef(-6, 0, 0, 1f); + GL11.glScalef(0.8f, 0.7f, 0.7f); + GL11.glTranslatef(0.2f, 0.0f, 0.2F); + } + + private void ensureNBT(ItemStack stack) { + if (stack.stackTagCompound == null) { + stack.stackTagCompound = new NBTTagCompound(); + } + if (!stack.stackTagCompound.hasKey("ShotsLeft")) { + stack.stackTagCompound.setInteger("ShotsLeft", 0); + } + if (!stack.stackTagCompound.hasKey("IsReloading")) { + stack.stackTagCompound.setBoolean("IsReloading", false); + } + } + + private void fireShot(ItemStack stack, EntityPlayer player) { + if (!ConfigItem.GunsEnabled && !player.capabilities.isCreativeMode) { + return; + } + int shotsLeft = stack.stackTagCompound.getInteger("ShotsLeft"); + if (shotsLeft <= 0) { + return; + } + + EntityProjectile projectile = new EntityProjectile(player.worldObj, player, + new ItemStack(CustomItems.bulletBlack, 1, 0), false); + projectile.damage = 4; + projectile.setSpeed(40); + projectile.shoot(2); + player.worldObj.playSoundAtEntity(player, "customnpcs:gun.pistol.shot", 0.9F, + itemRand.nextFloat() * 0.3F + 0.8F); + player.worldObj.spawnEntityInWorld(projectile); + + stack.stackTagCompound.setInteger("ShotsLeft", shotsLeft - 1); + if (!player.capabilities.isCreativeMode) { + consumeItem(player, CustomItems.bulletBlack); + } + } + + private void reloadShot(ItemStack stack, EntityPlayer player) { + int shotsLeft = stack.stackTagCompound.getInteger("ShotsLeft"); + if (shotsLeft < ConfigItem.MachineGunAmmo && hasItem(player, CustomItems.bulletBlack)) { + stack.stackTagCompound.setInteger("ShotsLeft", shotsLeft + 1); // Add one shot + if (!player.capabilities.isCreativeMode) { + consumeItem(player, CustomItems.bulletBlack); // Use up a bullet + } + } } } diff --git a/src/main/java/noppes/npcs/items/ItemMusket.java b/src/main/java/noppes/npcs/items/ItemMusket.java index 8555260f9..176677813 100644 --- a/src/main/java/noppes/npcs/items/ItemMusket.java +++ b/src/main/java/noppes/npcs/items/ItemMusket.java @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import noppes.npcs.CustomItems; -import noppes.npcs.config.ConfigMain; +import noppes.npcs.config.ConfigItem; import noppes.npcs.constants.EnumParticleType; import noppes.npcs.entity.EntityProjectile; import org.lwjgl.opengl.GL11; @@ -21,12 +21,12 @@ public class ItemMusket extends ItemNpcInterface{ public void onPlayerStoppedUsing(ItemStack stack, World par2World, EntityPlayer player, int count) { if(player.worldObj.isRemote) return; - - if(!stack.stackTagCompound.getBoolean("IsLoaded2") && !player.capabilities.isCreativeMode || !ConfigMain.GunsEnabled) { + + if(!stack.stackTagCompound.getBoolean("IsLoaded2") && !player.capabilities.isCreativeMode || !ConfigItem.GunsEnabled) { player.worldObj.playSoundAtEntity(player, "customnpcs:gun.empty", 1.0F,1); return; } - + if(stack.stackTagCompound.getBoolean("Reloading2") && !player.capabilities.isCreativeMode) { stack.stackTagCompound.setBoolean("Reloading2", false); return; @@ -37,10 +37,10 @@ public class ItemMusket extends ItemNpcInterface{ projectile.setSpeed(50); projectile.setParticleEffect(EnumParticleType.Smoke); projectile.shoot(2); - + if(!player.capabilities.isCreativeMode) consumeItem(player, CustomItems.bulletBlack); - + player.worldObj.playSoundAtEntity(player, "random.explode", 0.9F, itemRand.nextFloat() * 0.3F + 1.8F); player.worldObj.playSoundAtEntity(player, "ambient.weather.thunder", 2.0F, itemRand.nextFloat() * 0.3F + 1.8F); player.worldObj.spawnEntityInWorld(projectile); @@ -49,12 +49,12 @@ public class ItemMusket extends ItemNpcInterface{ } @Override - public void onUsingTick(ItemStack stack, EntityPlayer player, int count) + public void onUsingTick(ItemStack stack, EntityPlayer player, int count) { if(player.worldObj.isRemote){ return; } - + int ticks = getMaxItemUseDuration(stack) - count; if(!player.capabilities.isCreativeMode){ @@ -67,7 +67,7 @@ public class ItemMusket extends ItemNpcInterface{ } } } - + @Override public void renderSpecial(){ GL11.glRotatef(-6, 0, 0, 1f); @@ -94,10 +94,10 @@ public class ItemMusket extends ItemNpcInterface{ } public EnumAction getItemUseAction(ItemStack stack) - { + { if(stack.stackTagCompound == null || !stack.stackTagCompound.getBoolean("Reloading2")) return EnumAction.bow; - + return EnumAction.block; } -} \ No newline at end of file +} diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index b4d7e3d37..a825947cd 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -802,6 +802,7 @@ item.npcDiamondGun.name=Diamond Gun item.npcBronzeGun.name=Bronze Gun item.npcEmeraldGun.name=Emerald Gun item.npcMachineGun.name=Machine Gun +item.npcMachineGun.info=Remaining item.npcWoodenBullet.name=Wooden Bullet item.npcStoneBullet.name=Stone Bullet