Jump to content

Recommended Posts

Posted

i have some firearms and im trying to have a way to reload them with a key, and use another key to change between three or more ammunition types. im having a tough time doing that and i think the problem lies in the fact that my way of getting the player that hit the key is not working properly, but it could be something else. a lot of other parts of my code is not working either and i dont understand why. can anyone help me?? please! what am i doing wrong??

 

In Init function in clientside proxy:

	KeyBindings.init();
	FMLCommonHandler.instance().bus().register(new KeyBindings());

 

KeyBindings Class:

public class KeyBindings extends ClientRegistry
{
public static KeyBinding WeaponNextAmmoType;
public static KeyBinding WeaponReload;
public Minecraft mc = Minecraft.getMinecraft();

public static void init()
{
	WeaponNextAmmoType = new KeyBinding("key.WeaponNextAmmoTypeSelection", Keyboard.KEY_B, "key.categories.bioshock.weapon");
	WeaponReload = new KeyBinding("key.WeaponReload", Keyboard.KEY_R, "key.categories.bioshock.weapon");

	ClientRegistry.registerKeyBinding(WeaponNextAmmoType);
	ClientRegistry.registerKeyBinding(WeaponReload);
}

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event)
{
	if(KeyBindings.WeaponNextAmmoType != null)
	{
		if(KeyBindings.WeaponNextAmmoType.isPressed())
		{
			EntityPlayer player = mc.thePlayer;
			if(player.getHeldItem() != null) if(player.getHeldItem().getItem() instanceof ItemWeaponRanged)
			{
				ItemWeaponRanged gun = (ItemWeaponRanged)player.getHeldItem().getItem();
				gun.selectNextAmmoType(player.getHeldItem(), player);
				int a = player.getHeldItem().getTagCompound().getInteger("Ammo");
				int c = player.getHeldItem().getTagCompound().getInteger("Capacity");
				if(a+1 > c)
				{
					if(gun.reload(player.getHeldItem(), player, gun.reloadAmount))
					{
						player.worldObj.playSoundAtEntity(player, "bioshock:item.weapon.shotgun.reload.single", 0.8F, 1.0F);
					}
				}
			}
		}
	}
	if(KeyBindings.WeaponReload != null)
	{
		if(KeyBindings.WeaponReload.isPressed())
		{
			EntityPlayer player = mc.thePlayer;
			if(player.getHeldItem() != null) if(player.getHeldItem().getItem() instanceof ItemWeaponRanged)
			{
				if(player.getHeldItem().getTagCompound().getInteger("Ammo")+1 <= player.getHeldItem().getTagCompound().getInteger("Capacity"))
				{
					ItemWeaponRanged gun = (ItemWeaponRanged)player.getHeldItem().getItem();
					player.worldObj.playSoundAtEntity(player, "bioshock:item.weapon.shotgun.reload.single", 0.8F, 1.0F);
					int a = player.getHeldItem().getTagCompound().getInteger("Ammo");
					int c = player.getHeldItem().getTagCompound().getInteger("Capacity");
					if(a+1 > c)
					{
						if(gun.reload(player.getHeldItem(), player, gun.reloadAmount))
						{
							player.worldObj.playSoundAtEntity(player, "bioshock:item.weapon.shotgun.reload.single", 0.8F, 1.0F);
						}
					}
				}
				else
				{
					player.worldObj.playSoundAtEntity(player, "random.click", 0.3F, 1.6F);
				}
			}
		}
	}
}
}

 

ItemWeaponRanged Class:

public class ItemWeaponRanged extends ItemGeneric
{
public Item ammoItem;

public int fireRate;
public int capacity;
public float spread;
public float recoil;
public int reloadAmount;

public String upgrade1Name;
public String upgrade2Name;

public String[] ammoNames;

public IIcon defaultTexture;
public IIcon upgrade1Texture;
public IIcon upgrade2Texture;
public IIcon upgradeBothTexture;

/**
 * Base class for ranged weapons and other similar things that use ammunition
 * @param int Ammunition maximum capacity
 * @param int Fire rate
 * @param float Spread
 * @param float Recoil
 * @param String name for first upgrade
 * @param String name for second upgrade
 * @param String name for first type of ammunition
 * @param String name for second type of ammunition
 * @param String name for third type of ammunition
 */
public ItemWeaponRanged(int capacity, int fireRate, float spread, float recoil, int reloadAmount, String upgrade1Name, String upgrade2Name, String[] ammoNames)
{
	this.capacity = capacity;
	this.fireRate = fireRate;
	this.spread = spread;
	this.recoil = recoil;
	this.reloadAmount = reloadAmount;
	this.upgrade1Name = upgrade1Name;
	this.upgrade2Name = upgrade2Name;
	this.ammoNames = ammoNames;
	this.setMaxStackSize(1);
	this.setCreativeTab(BioshockMod.tabBioshockModWeapons);
	this.setUnlocalizedName("weapon");
	this.setTextureName("bioshock:weapon");
	this.setMaxDamage(100);
	this.setNoRepair();
	this.setHasSubtypes(true);
}

/**
 * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
 */
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs creativeTab, List list)
{
	ItemStack itemstack1 = new ItemStack(item, 1, 1);
	itemstack1.setTagCompound(new NBTTagCompound());
	itemstack1.stackTagCompound.setString("AmmoType", this.ammoNames[0]);
	ItemStack itemstack2 = new ItemStack(item, 1, 1);
	itemstack2.setTagCompound(new NBTTagCompound());
	itemstack2.stackTagCompound.setString("AmmoType", this.ammoNames[0]);
	ItemStack itemstack3 = new ItemStack(item, 1, 1);
	itemstack3.setTagCompound(new NBTTagCompound());
	itemstack3.stackTagCompound.setString("AmmoType", this.ammoNames[0]);
	ItemStack itemstack4 = new ItemStack(item, 1, 1);
	itemstack4.setTagCompound(new NBTTagCompound());
	itemstack4.stackTagCompound.setString("AmmoType", this.ammoNames[0]);

	itemstack2.stackTagCompound.setBoolean("Upgrade1", true);
	itemstack3.stackTagCompound.setBoolean("Upgrade2", true);
	itemstack4.stackTagCompound.setBoolean("Upgrade1", true);
	itemstack4.stackTagCompound.setBoolean("Upgrade2", true);

	this.createNbt(itemstack1);
	this.createNbt(itemstack2);
	this.createNbt(itemstack3);
	this.createNbt(itemstack4);

	list.add(itemstack1);
	list.add(itemstack2);
	list.add(itemstack3);
	list.add(itemstack4);
}

public void registerIcons(IIconRegister iconReg)
{
	this.defaultTexture = iconReg.registerIcon(this.iconString);
	this.upgrade1Texture = iconReg.registerIcon(this.iconString);
	this.upgrade2Texture = iconReg.registerIcon(this.iconString);
	this.upgradeBothTexture = iconReg.registerIcon(this.iconString+"_upgrade_both");
}

public void registerIcons(IIconRegister iconReg, String update1, String update2)
{
	this.defaultTexture = iconReg.registerIcon(this.iconString);
	this.upgrade1Texture = iconReg.registerIcon(this.iconString + "_upgrade_"+update1);
	this.upgrade2Texture = iconReg.registerIcon(this.iconString+"_upgrade_"+update2);
	this.upgradeBothTexture = iconReg.registerIcon(this.iconString+"_upgrade_both");
}

public IIcon getIconIndex(ItemStack itemstack)
{
	this.createNbt(itemstack);
	if(itemstack.stackTagCompound.getBoolean("Upgrade1") && itemstack.stackTagCompound.getBoolean("Upgrade2"))
	{
		return this.upgradeBothTexture;
	}
	else if(itemstack.stackTagCompound.getBoolean("Upgrade1"))
	{
		return this.upgrade1Texture;
	}
	else if(itemstack.stackTagCompound.getBoolean("Upgrade2"))
	{
		return this.upgrade2Texture;
	}
	else
	{
		return this.defaultTexture;
	}
}

public IIcon getIcon(ItemStack itemstack, int pass)
{
	return this.getIconIndex(itemstack);
}

/**
 * allows items to add custom lines of information to the mouseover description
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean bool)
{
	this.createNbt(itemstack);
	if(itemstack.stackTagCompound.hasKey("Capacity") && itemstack.stackTagCompound.hasKey("Ammo"))
	{
		list.add("Ammo: ");
		list.add(Integer.toString(itemstack.stackTagCompound.getInteger("Ammo")) + "/" + Integer.toString(itemstack.stackTagCompound.getInteger("Capacity")));
		if(itemstack.stackTagCompound.getInteger("Ammo") > 0)
		{
			for(int z = 0; z < this.ammoNames.length; ++z)
			{
				if(itemstack.stackTagCompound.getString("AmmoType") == this.ammoNames[z])
				{
					list.add("(" + this.ammoNames[z] + ")");
				}
			}
		}
	}
	if(itemstack.stackTagCompound.hasKey("FireRate"))
	{
		list.add("Fire Rate: ");
		list.add(Float.toString(itemstack.stackTagCompound.getInteger("FireRate")/20F));
	}
	if(itemstack.stackTagCompound.getBoolean("UpgradeClip") || itemstack.stackTagCompound.getBoolean("UpgradeDamage"))
	{
		list.add("Upgrades: ");
		if(itemstack.stackTagCompound.getBoolean("Upgrade1"))
		{
			list.add("-" + this.upgrade1Name + " Upgrade");
		}
		if(itemstack.stackTagCompound.getBoolean("Upgrade2"))
		{
			list.add("-" + this.upgrade2Name + " Upgrade");
		}
	}
	this.addInformationCustomUpgrades(itemstack, player, list, bool);
}

public void addInformationCustomAmmo(ItemStack itemstack, EntityPlayer player, List list, boolean bool) {}

public void addInformationCustomUpgrades(ItemStack itemstack, EntityPlayer player, List list, boolean bool) {}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int par4, boolean par5)
{
	this.createNbt(itemstack);
	if(itemstack.stackTagCompound.getInteger("FireRateTimer") > 0)
	{
		itemstack.stackTagCompound.setInteger("FireRateTimer", itemstack.stackTagCompound.getInteger("FireRateTimer")-1);
	}
	if(entity instanceof EntityPlayer && itemstack.stackTagCompound.getInteger("RecoilTimer") > 0)
	{
		itemstack.stackTagCompound.setInteger("RecoilTimer", itemstack.stackTagCompound.getInteger("RecoilTimer")-1);
		((EntityPlayer)entity).rotationPitch = ((EntityPlayer)entity).rotationPitch+this.recoil/6;
	}
	/*if(!itemstack.hasDisplayName())
	{
		String a = null;
		if(world.isRemote)
		{
			a = StatCollector.translateToLocal(itemstack.getItem().getUnlocalizedName(itemstack));
		}
		if(a != null)
		{
			itemstack.setStackDisplayName("§r" + a);
		}
	}*/
}

@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
	EntityExtendedPlayer props = EntityExtendedPlayer.get(player);
	if(itemstack.stackTagCompound.getInteger("FireRateTimer") <= 0)
	{
		if(itemstack.stackTagCompound.getInteger("Ammo") > 0)
		{
			this.fireBullet(itemstack, world, player);
			itemstack.stackTagCompound.setInteger("Ammo", itemstack.stackTagCompound.getInteger("Ammo")-1);
			if(!player.capabilities.isCreativeMode)
			{
				if (itemstack.stackTagCompound.getInteger("Ammo") <= 0)
				{
					itemstack.stackTagCompound.setInteger("FireRateTimer", 0);
					itemstack.stackTagCompound.setInteger("Ammo", 0);
					world.playSoundAtEntity(player, "random.click", 2.0F, 2.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
				}
				else
				{
					this.setFireRate(itemstack);
				}
			}
			player.rotationPitch = player.rotationPitch-this.recoil;
			player.rotationYaw = player.rotationYaw+this.hi(0.01F);
			itemstack.stackTagCompound.setInteger("RecoilTimer", 6);
		}
		else
		{
			world.playSoundAtEntity(player, "random.click", 2.0F, 2.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
		}
	}
	return itemstack;
}

public void setupUpgradeNbt(ItemStack itemstack) {}

public void createNbt(ItemStack itemstack)
{
	if(itemstack.stackTagCompound == null)
	{
		itemstack.setTagCompound(new NBTTagCompound());
	}
	this.setupUpgradeNbt(itemstack);
	if(!itemstack.stackTagCompound.hasKey("Capacity"))
	{
		itemstack.stackTagCompound.setInteger("Capacity", capacity);
	}
	if(!itemstack.stackTagCompound.hasKey("Ammo"))
	{
		itemstack.stackTagCompound.setInteger("Ammo", capacity);
	}
	if(!itemstack.stackTagCompound.hasKey("AmmoType"))
	{
		itemstack.stackTagCompound.setString("AmmoType", this.ammoNames[1]);
	}
	if(!itemstack.stackTagCompound.hasKey("FireRate"))
	{
		itemstack.stackTagCompound.setInteger("FireRate", fireRate);
	}
	if(!itemstack.stackTagCompound.hasKey("FireRateTimer"))
	{
		itemstack.stackTagCompound.setInteger("FireRateTimer", 0);
	}
	if(!itemstack.stackTagCompound.hasKey("Upgrade1"))
	{
		itemstack.stackTagCompound.setBoolean("Upgrade1", false);
	}
	if(!itemstack.stackTagCompound.hasKey("Upgrade2"))
	{
		itemstack.stackTagCompound.setBoolean("Upgrade2", false);
	}
}

public void setFireRate(ItemStack itemstack)
{
	itemstack.stackTagCompound.setInteger("FireRateTimer", itemstack.stackTagCompound.getInteger("FireRate"));
}

public void fireBullet(ItemStack itemstack, World world, EntityPlayer player) {}

protected float hi(float input)
{
	return (this.itemRand.nextFloat()*input*2)-input;
}

public void selectNextAmmoType(ItemStack itemstack, EntityPlayer player)
{
	this.selectAmmoType(itemstack, player, this.getAmmoNameIndex(itemstack, 1));
}

public void selectAmmoType(ItemStack itemstack, EntityPlayer player, int ammoNameNumber)
{
	if(this.ammoItem != null)
	{
		player.dropItem(this.ammoItem, itemstack.getTagCompound().getInteger("Ammo"));
	}
	itemstack.getTagCompound().setString("AmmoType", this.ammoNames[ammoNameNumber]);
}

protected int getAmmoNameIndex(ItemStack itemstack, int modifier)
{
	int a = -1;
	String texture = itemstack.getTagCompound().getString("AmmoType");
	for(int i = this.ammoNames.length-1; i >= 0 && i < this.ammoNames.length-1; --i)
	{
		if(texture == this.ammoNames[i])
		{
			a = i;
			break;
		}
	}
	if(a >= 0)
	{
		if(modifier != 0)
		{
			int b = this.ammoNames.length-1;
			int i;
			for(i = a + modifier; i < b; i -= b)
			{
				a = i - modifier;
			}
		}
	}
	else
	{
		a = 0;
	}
	return a;
}

public boolean reload(ItemStack itemstack, EntityPlayer player, int requestedAmount)
{
	if(itemstack.getItem() instanceof ItemWeaponRanged)
	{
		Item ammoItem = ((ItemWeaponRanged)itemstack.getItem()).ammoItem;
		if(ammoItem != null)
		{
			int i = this.lookForItemInInventory(this.ammoItem, player, requestedAmount);
			if(i > 0)
			{
				int c = itemstack.getTagCompound().getInteger("Capacity");
				itemstack.getTagCompound().setInteger("Ammo", i > c ? c : i);
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

protected int lookForItemInInventory(Item item, EntityPlayer player, int requestedAmount)
{
	int amount = 0;
	for(int slot = player.inventory.getSizeInventory()-1; slot >= 0 && amount < requestedAmount; --slot)
	{
		if(player.inventory.getStackInSlot(slot) != null)
		{
			if(player.inventory.getStackInSlot(slot).getItem() == item)
			{
				++amount;
				--player.inventory.getStackInSlot(slot).stackSize;
				return amount;
			}
		}
	}
	return amount;
}
}

 

ItemWeaponShotgun Class:

public class ItemWeaponShotgun extends ItemWeaponRanged
{
public Item ammoItem = BioshockMod.WeaponShotgunAmmo00;

public int fireRate2;

/**
 * @param int Ammunition maximum capacity
 * @param int Fire rate without upgrade (in ticks)
 * @param int Fire rate with upgrade (in ticks)
 * @param float Spread
 * @param float Recoil
 * @param String name for first upgrade
 * @param String name for second upgrade
 * @param String name for first type of ammunition
 * @param String name for second type of ammunition
 * @param String name for third type of ammunition
 * @param String name for fourth type of ammunition
 */
public ItemWeaponShotgun(int capacity, int fireRate, int fireRate2, float spread, float recoil, int reloadAmount, String upgrade1Name, String upgrade2Name, String[] ammoNames)
{
	super(capacity, fireRate, spread, recoil, reloadAmount, upgrade1Name, upgrade2Name, ammoNames);
	this.fireRate2 = fireRate2;
	this.setUnlocalizedName("weaponShotgunRapture");
	this.setTextureName("bioshock:shotgun_rapture");
}

public void registerIcons(IIconRegister iconReg)
{
	super.registerIcons(iconReg, "fire_rate", "damage");
}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int par4, boolean par5)
{
	if(!itemstack.stackTagCompound.getBoolean("Upgrade1"))
	{
		if(itemstack.stackTagCompound.getInteger("FireRateTimer") == itemstack.stackTagCompound.getInteger("FireRate")-
		{
			world.playSoundAtEntity(entity, "bioshock:item.weapon.shotgun.pump", 0.8F, 1.0F);
		}
	}
	super.onUpdate(itemstack, world, entity, par4, par5);
}

public void setupUpgradeNbt(ItemStack itemstack)
{
	if(!itemstack.stackTagCompound.hasKey("FireRate") || itemstack.stackTagCompound.getInteger("FireRate") == this.fireRate || itemstack.stackTagCompound.getInteger("FireRate") == this.fireRate2)
	{
		if(!itemstack.stackTagCompound.getBoolean("Upgrade1"))
		{
			itemstack.stackTagCompound.setInteger("FireRate", this.fireRate);
		}
		else
		{
			itemstack.stackTagCompound.setInteger("FireRate", this.fireRate2);
		}
	}
}

public void fireBullet(ItemStack itemstack, World world, EntityPlayer player)
{
	world.playSoundAtEntity(player, "fireworks.blast", 1.8F, 1.5F / (itemRand.nextFloat() * 0.4F + 0.8F));
	world.playSoundAtEntity(player, "random.explode", 0.3F, (1.0F + (this.itemRand.nextFloat() - this.itemRand.nextFloat()) * 0.2F) * 2.7F);
	world.playSoundAtEntity(player, "mob.blaze.hit", 0.015F, 0.08F / (itemRand.nextFloat() * 0.4F + 0.8F));
	world.playSoundAtEntity(player, "fireworks.blast", 1.8F, 1.5F / (itemRand.nextFloat() * 0.4F + 0.8F));
	world.playSoundAtEntity(player, "random.explode", 0.3F, (1.0F + (this.itemRand.nextFloat() - this.itemRand.nextFloat()) * 0.2F) * 2.7F);
	world.playSoundAtEntity(player, "mob.blaze.hit", 0.015F, 0.08F / (itemRand.nextFloat() * 0.4F + 0.8F));

	if(itemstack.stackTagCompound.getString("AmmoType") != this.ammoNames[3])
	{
		for(int a = 8; a > 0; --a)
		{
			if(!world.isRemote)
			{
				float power = 0.9F;
				float damage = 35F;
				EntityBullet bullet = new EntityBullet(world, player, null);
				if(a < 4)
				{
					bullet.silent = true;
				}
				bullet.onTickDamageModifier = 0.7F;
				bullet.ignoresArmour = true;
				bullet.damageName = "shotgun";
				if(itemstack.stackTagCompound.getString("AmmoType") == this.ammoNames[0])
				{
					//yo bro whatchugonnadoabutit
				}
				if(itemstack.stackTagCompound.getString("AmmoType") == this.ammoNames[1])
				{
					//bullet.dealsPhysicalDamage = false;
					bullet.electric = true;
				}
				if(itemstack.stackTagCompound.getString("AmmoType") == this.ammoNames[2])
				{
					//bullet.dealsPhysicalDamage = false;
					bullet.burning = true;
					power = power*4;
					damage = damage/0.7F;
				}
				if(itemstack.stackTagCompound.getBoolean("Upgrade2"))
				{
					bullet.damage = damage+damage/4;
					bullet.power = power*4;
				}
				else
				{
					bullet.damage = damage;
					bullet.power = power;
				}
				bullet.setVelocity(bullet.motionX+hi(this.spread/50), bullet.motionY+hi(this.spread/50), bullet.motionZ+hi(this.spread/50));
				world.spawnEntityInWorld(bullet);
			}
		}
	}
	else
	{
		if(!world.isRemote)
		{
			float power = 2.4F;
			float damage = 58F;
			EntityBullet bullet = new EntityBullet(world, player, null);
			bullet.onTickDamageModifier = 0.98F;
			bullet.ignoresArmour = true;
			bullet.damageName = "shotgun";
			bullet.piercing = true;
			if(itemstack.stackTagCompound.getBoolean("Upgrade2"))
			{
				bullet.damage = damage+damage/4;
				bullet.power = power*4;
			}
			else
			{
				bullet.damage = damage;
				bullet.power = power;
			}
			world.spawnEntityInWorld(bullet);
		}
	}
	EntityBullet bullet = new EntityBullet(world, player);
	player.setVelocity(player.motionX-bullet.motionX/200, player.motionX-bullet.motionY/200, player.motionX-bullet.motionZ/200);
	bullet.setDead();
}
}

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Posted

i followed your tutorial, but i still cant get it to work. i dont know what's wrong.

this is my key binding class:

public class KeyBindings extends ClientRegistry
{
public static KeyBinding WeaponNextAmmoType;
public static KeyBinding WeaponReload;
public Minecraft mc = Minecraft.getMinecraft();

public static void init()
{
	WeaponNextAmmoType = new KeyBinding("key.WeaponNextAmmoTypeSelection", Keyboard.KEY_B, "key.categories.bioshock.weapon");
	WeaponReload = new KeyBinding("key.WeaponReload", Keyboard.KEY_R, "key.categories.bioshock.weapon");

	ClientRegistry.registerKeyBinding(WeaponNextAmmoType);
	ClientRegistry.registerKeyBinding(WeaponReload);
}

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event)
{
	if(KeyBindings.WeaponNextAmmoType != null)
	{
		if(KeyBindings.WeaponNextAmmoType.isPressed())
		{
			BioshockMod.network.sendToServer(new KeyPackets("WeaponNextAmmoType"));
		}
	}
	if(KeyBindings.WeaponReload != null)
	{
		if(KeyBindings.WeaponReload.isPressed())
		{
			BioshockMod.network.sendToServer(new KeyPackets("WeaponReload"));
		}
	}
}
}

 

this is my packet class:

public class KeyPackets implements IMessage
{
private String string;

public KeyPackets() {}

public KeyPackets(String string)
{
	this.string = string;
}

@Override
public void fromBytes(ByteBuf buf)
{
	string = ByteBufUtils.readUTF8String(buf);
}

@Override
public void toBytes(ByteBuf buf)
{
	ByteBufUtils.writeUTF8String(buf, string);
}

public static class Handler implements IMessageHandler<KeyPackets, IMessage>
{
	@Override
	public IMessage onMessage(KeyPackets message, MessageContext context)
	{
		String string = message.string;
		EntityPlayer player = context.getServerHandler().playerEntity;
		if(string == "WeaponNextAmmoType")
		{
			if(player.getHeldItem() != null) if(player.getHeldItem().getItem() instanceof ItemWeaponRanged)
			{
				if(player.getHeldItem().getTagCompound().getInteger("Ammo")+1 <= player.getHeldItem().getTagCompound().getInteger("Capacity"))
				{
					ItemWeaponRanged gun = (ItemWeaponRanged)player.getHeldItem().getItem();
					player.worldObj.playSoundAtEntity(player, "bioshock:item.weapon.shotgun.reload.single", 0.8F, 1.0F);
					int a = player.getHeldItem().getTagCompound().getInteger("Ammo");
					int c = player.getHeldItem().getTagCompound().getInteger("Capacity");
					if(a+1 > c)
					{
						if(gun.reload(player.getHeldItem(), player, gun.reloadAmount))
						{
							player.worldObj.playSoundAtEntity(player, "bioshock:item.weapon.shotgun.reload.single", 0.8F, 1.0F);
						}
					}
				}
				else
				{
					player.worldObj.playSoundAtEntity(player, "random.click", 0.3F, 1.6F);
				}
			}
		}
		else if(string == "WeaponReload")
		{
			if(player.getHeldItem() != null) if(player.getHeldItem().getItem() instanceof ItemWeaponRanged)
			{
				ItemWeaponRanged gun = (ItemWeaponRanged)player.getHeldItem().getItem();
				gun.selectNextAmmoType(player.getHeldItem(), player);
				int a = player.getHeldItem().getTagCompound().getInteger("Ammo");
				int c = player.getHeldItem().getTagCompound().getInteger("Capacity");
				if(a+1 > c)
				{
					if(gun.reload(player.getHeldItem(), player, gun.reloadAmount))
					{
						player.worldObj.playSoundAtEntity(player, "bioshock:item.weapon.shotgun.reload.single", 0.8F, 1.0F);
					}
				}
			}
		}
		System.out.println(String.format("Received %s from %s", message.string, context.getServerHandler().playerEntity.getDisplayName()));
		return null;
	}
}
}

 

this is how i call it from preInit in the main class:

	network = NetworkRegistry.INSTANCE.newSimpleChannel("BioshockPacketChannel");
	network.registerMessage(KeyPackets.Handler.class, KeyPackets.class, 0, Side.SERVER);

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.