Created
August 6, 2014 12:00
-
-
Save MultiMote/f7ed6f0fe0fcfb842552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.multimote.microz.item.guns; | |
import com.google.common.collect.HashMultimap; | |
import com.google.common.collect.Multimap; | |
import com.multimote.microz.Core; | |
import com.multimote.microz.entity.BulletEntity; | |
import com.multimote.microz.item.DayzWeapon; | |
import com.multimote.microz.utils.DayzPlayer; | |
import com.multimote.microz.utils.OtherUtils; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
import net.minecraft.block.Block; | |
import net.minecraft.client.resources.I18n; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.world.World; | |
/** | |
* Created by multimote on 02.06.14. | |
*/ | |
// implements Scoped{ | |
public class BaseGun extends DayzWeapon implements LeftClicking { | |
private int reloadCooldown = 30; | |
private int loudness = 30; | |
private boolean notConsumesBullets; | |
private int shootCooldown = 3; | |
private int modes = 1; | |
private String shootSound = "microz:pistol.pm.shoot"; | |
private String reloadSound = "microz:pistol.pm.reload"; | |
private String emptySound = "microz:weapon.empty"; | |
private int bulletDamage = 10; | |
public BaseGun() { | |
setMaxStackSize(1); | |
setCreativeTab(Core.dayztab); | |
setUnlocalizedName("basegun"); | |
} | |
public void Shoot(EntityPlayer player) { | |
ItemStack is = player.getHeldItem(); | |
if ((is != null && is.getItem() != this)) return; | |
if (!(getReloadCooldownLeft(is) <= 0 && getShootCooldownLeft(is) <= 0)) return; | |
if (getShotsLeft(is) > 0 && (!this.isConsumesBullets() || OtherUtils.ifPlayerHasCompatibleMag(this, player))) { | |
if (this.isConsumesBullets()) OtherUtils.consumeBullet(this, player); | |
player.worldObj.playSoundAtEntity(player, this.getShotSound(), (float) this.getLoudness() / 10F, 1F); | |
//todo отдача(пакет) | |
DayzPlayer.get(player).setVisibilityFor(this.getLoudness(), 10); | |
player.worldObj.spawnEntityInWorld(new BulletEntity(player.worldObj, player).setBulletDamage(this.getBulletDamage())); | |
if (this.isConsumesBullets()) decrementIntIfNotNull(is, "bullets"); | |
setIntIfNotNull(is, "shootcooldown", getShootCooldown()); | |
} else { | |
player.worldObj.playSoundAtEntity(player, this.getEmptySound(), 0.5F, 1F); | |
} | |
} | |
public void Reload(EntityPlayer player) { | |
ItemStack is = player.getHeldItem(); | |
if ((is != null && is.getItem() != this)) return; | |
if (is != null && is.getItem() == this && getReloadCooldownLeft(is) <= 0) {//чем чёрт не шутит | |
if (!isConsumesBullets()) setIntIfNotNull(is, "bullets", 999); | |
else | |
setIntIfNotNull(is, "bullets", OtherUtils.getBulletsToLoad(this, player)); | |
if (getShotsLeft(is) > 0) { | |
player.worldObj.playSoundAtEntity(player, this.getReloadSound(), 0.5F, 1F); | |
setIntIfNotNull(is, "reloadcooldown", getReloadCooldown()); | |
} | |
} | |
} | |
public void onUpdate(ItemStack is, World world, Entity entity, int par4, boolean par5) { | |
checkCompound(is); | |
if (!world.isRemote) { | |
if (getReloadCooldownLeft(is) > 0) decrementIntIfNotNull(is, "reloadcooldown"); | |
if (getShootCooldownLeft(is) > 0) decrementIntIfNotNull(is, "shootcooldown"); | |
if (entity instanceof EntityPlayer) { | |
if (getMode(is) == 2) { | |
if (getShotsLeft(is) > 0) { | |
if (getIntIfNotNull(is, "burstCount") > 0 && getShootCooldownLeft(is) < 1) { | |
System.out.println(getIntIfNotNull(is, "burstCount") + " " + getShootCooldownLeft(is)); | |
decrementIntIfNotNull(is, "burstCount"); | |
Shoot((EntityPlayer) entity); | |
} | |
} else setIntIfNotNull(is, "burstCount", 0); | |
} | |
} | |
} | |
} | |
public int getModeCount() { | |
return this.modes; | |
} | |
public int getMode(ItemStack is) { | |
int m = Math.min(getIntIfNotNull(is, "mode"), getModeCount() - 1); | |
return m < 0 ? 0 : m; | |
} | |
public void cycleMode(ItemStack is) { | |
int prev = getIntIfNotNull(is, "mode"); | |
if ((prev + 1) > getModeCount() - 1) { | |
setIntIfNotNull(is, "mode", 0); | |
} else { | |
setIntIfNotNull(is, "mode", prev + 1); | |
} | |
} | |
public boolean isIllegal() { | |
return !this.isConsumesBullets(); | |
} | |
protected boolean isConsumesBullets() { | |
return !this.notConsumesBullets; | |
} | |
public BaseGun makeIllegal() { | |
this.notConsumesBullets = true; | |
return this; | |
} | |
@Override | |
public Multimap getItemAttributeModifiers() { | |
return HashMultimap.create(); | |
} | |
@SideOnly(Side.CLIENT) | |
public String getModeString(ItemStack is) { | |
switch (getMode(is)) { | |
case 0: | |
return I18n.format("microz.weapon.mode.single"); | |
case 1: | |
return I18n.format("microz.weapon.mode.semi"); | |
case 2: | |
return I18n.format("microz.weapon.mode.burst"); | |
} | |
return "???"; | |
} | |
public int getShotsLeft(ItemStack is) { | |
return getIntIfNotNull(is, "bullets"); | |
} | |
public int getLoudness() { //in blocks | |
return this.loudness; | |
} | |
public BaseGun setLoudness(int l) { | |
this.loudness = l; | |
return this; | |
} | |
public int getShootCooldown() { | |
return this.shootCooldown; | |
} | |
public BaseGun setShootCooldown(int c) { | |
this.shootCooldown = c; | |
return this; | |
} | |
public int getShootCooldownLeft(ItemStack is) { | |
return getIntIfNotNull(is, "shootcooldown"); | |
} | |
//public float getKnockback() { | |
// return 25; | |
// } | |
public int getReloadCooldownLeft(ItemStack is) { | |
return getIntIfNotNull(is, "reloadcooldown"); | |
} | |
public int getReloadCooldown() { | |
return this.reloadCooldown; | |
} | |
public BaseGun setReloadCooldown(int c) { | |
this.reloadCooldown = c; | |
return this; | |
} | |
public BaseGun setShootSound(String s) { | |
this.shootSound = s; | |
return this; | |
} | |
public BaseGun setReloadSound(String s) { | |
this.reloadSound = s; | |
return this; | |
} | |
public BaseGun setEmptySound(String s) { | |
this.emptySound = s; | |
return this; | |
} | |
public BaseGun setModes(int modes) { | |
this.modes = modes; | |
return this; | |
} | |
public String getShotSound() { | |
return this.shootSound; | |
} | |
public String getReloadSound() { | |
return this.reloadSound; | |
} | |
public String getEmptySound() { | |
return this.emptySound; | |
} | |
public int getBulletDamage() { | |
return this.bulletDamage; | |
} | |
@Override | |
public float getDigSpeed(ItemStack itemstack, Block block, int metadata) { | |
return 0; | |
} | |
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer pl) { | |
pl.setItemInUse(par1ItemStack, 90000); | |
return par1ItemStack; | |
} | |
public boolean onEntitySwing(EntityLivingBase en, ItemStack st) { | |
return true; | |
} | |
@Override | |
public boolean isTickable(ItemStack is, World world, EntityPlayer player) { | |
return getMode(is) == 1 && getShotsLeft(is) > 0; | |
} | |
@Override | |
public void onItemLeftClick(ItemStack is, World world, EntityPlayer player) { | |
if (getMode(is) == 0 || getShotsLeft(is) == 0) Shoot(player); | |
else if (getMode(is) == 2 && getShotsLeft(is) > 0 && getIntIfNotNull(is, "burstCount") < 1 && getShootCooldownLeft(is) < 1) { | |
setIntIfNotNull(is, "burstCount", 3); | |
} | |
} | |
@Override | |
public void onItemLeftClickTick(ItemStack is, World world, EntityPlayer player) { | |
if (getShotsLeft(is) > 0) Shoot(player); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment