Item Config + Machine Gun Fixes

This commit is contained in:
Kam committed 2025-03-12 05:00:21 -04:00
1 parent 3939e6cf2b
commit 207d9f6124
12 files changed
+258 -156

No files matched your search

+5 -4
View File
@@ -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;
}
@@ -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);
}
}
+4 -4
View File
@@ -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");
@@ -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());
@@ -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();
}
}
}
}
@@ -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);
@@ -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);
@@ -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);
+8 -8
View File
@@ -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();
@@ -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
}
}
}
}
+12 -12
View File
@@ -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;
}
}
}