Skip to content

Commit

Permalink
Tracer mostly finished
Browse files Browse the repository at this point in the history
  • Loading branch information
2piradians committed Jun 3, 2017
1 parent 525a98a commit 8336d0a
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public EntityReaperBullet(World worldIn, EntityLivingBase throwerIn, EnumHand ha
double y = throwerIn.posY + throwerIn.getEyeHeight() - Math.sin(throwerIn.rotationPitch*Math.PI/180);
double z = throwerIn.posZ + Math.cos(throwerIn.rotationPitch*Math.PI/180)*Math.sin(throwerIn.rotationYawHead*Math.PI/180 + Math.PI/2);
if (hand == EnumHand.MAIN_HAND) {
x -= 0.8d;
y -= 0.4d;
z -= 0.1d;
x -= Math.cos(throwerIn.rotationYawHead*Math.PI/180)/3;
y -= 0.15d - Math.sin(throwerIn.rotationPitch*Math.PI/180)/2;
z -= Math.sin(throwerIn.rotationYawHead*Math.PI/180)/3;
}
else {
x += 0.45d;
y -= 0.2d;
z += 0.3d;
x += Math.cos(throwerIn.rotationYawHead*Math.PI/180)/3;
y -= 0.15d - Math.sin(throwerIn.rotationPitch*Math.PI/180)/2;
z += Math.sin(throwerIn.rotationYawHead*Math.PI/180)/3;
}
this.setPosition(x, y, z);
this.setRotation(0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
Expand All @@ -23,17 +24,26 @@ public EntityTracerBullet(World worldIn) {
}

//Client doesn't read here
public EntityTracerBullet(World worldIn, EntityLivingBase throwerIn) {
public EntityTracerBullet(World worldIn, EntityLivingBase throwerIn, EnumHand hand) {
super(worldIn, throwerIn);
this.setNoGravity(true);
this.setSize(0.1f, 0.1f);
//TODO adjust for which gun fires
double velX = Math.cos(throwerIn.rotationPitch*Math.PI/180) * Math.cos(throwerIn.rotationYawHead*Math.PI/180 + Math.PI/2) + (Math.random() - 0.5d)*0.1d;
double velY = - Math.sin(throwerIn.rotationPitch*Math.PI/180) + (Math.random() - 0.5d)*0.1d;
double velZ = Math.cos(throwerIn.rotationPitch*Math.PI/180) * Math.sin(throwerIn.rotationYawHead*Math.PI/180 + Math.PI/2) + (Math.random() - 0.5d)*0.1d;
double x = throwerIn.posX + Math.cos(throwerIn.rotationPitch*Math.PI/180)*Math.cos(throwerIn.rotationYawHead*Math.PI/180 + Math.PI/2);
double y = throwerIn.posY + throwerIn.getEyeHeight() - Math.sin(throwerIn.rotationPitch*Math.PI/180);
double z = throwerIn.posZ + Math.cos(throwerIn.rotationPitch*Math.PI/180)*Math.sin(throwerIn.rotationYawHead*Math.PI/180 + Math.PI/2);
if (hand == EnumHand.MAIN_HAND) {
x -= Math.cos(throwerIn.rotationYawHead*Math.PI/180)/3;
y -= 0.15d - Math.sin(throwerIn.rotationPitch*Math.PI/180)/2;
z -= Math.sin(throwerIn.rotationYawHead*Math.PI/180)/3;
}
else {
x += Math.cos(throwerIn.rotationYawHead*Math.PI/180)/3;
y -= 0.15d - Math.sin(throwerIn.rotationPitch*Math.PI/180)/2;
z += Math.sin(throwerIn.rotationYawHead*Math.PI/180)/3;
}
this.setPosition(x, y, z);
this.setRotation(0, 0);
double speed = 5.0d;
Expand All @@ -44,7 +54,6 @@ public EntityTracerBullet(World worldIn, EntityLivingBase throwerIn) {
this.motionX = velX;
this.motionY = velY;
this.motionZ = velZ;
//setVelocity(velX, velY, velZ);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package twopiradians.minewatch.common.item.weapon;

import java.util.Iterator;
import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import twopiradians.minewatch.common.Minewatch;
import twopiradians.minewatch.common.entity.EntityAnaBullet;
Expand All @@ -30,4 +38,35 @@ public void onShoot(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ModSoundEvents.reaperShotgun, SoundCategory.PLAYERS, 1.0f, worldIn.rand.nextFloat()/2+0.75f);
}
}

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {

if (entityIn != null && entityIn instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)entityIn;

//Ana's Rifle
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemAnaRifle
&& Minewatch.keyMode.isKeyDown(player) && entityIn.ticksExisted % 10 == 0) {
AxisAlignedBB aabb = entityIn.getEntityBoundingBox().expandXyz(30);
List<Entity> list = entityIn.world.getEntitiesWithinAABBExcludingEntity(entityIn, aabb);
if (!list.isEmpty()) {
Iterator<Entity> iterator = list.iterator();
while (iterator.hasNext()) {
Entity entityInArea = iterator.next();
if (entityInArea != null && entityInArea instanceof EntityPlayer
&& ((EntityPlayer)entityInArea).isOnSameTeam(player)
&& ((EntityPlayer)entityInArea).getHealth() < ((EntityPlayer)entityInArea).getMaxHealth()) {
Minewatch.proxy.spawnParticlesHealthPlus(player.world, entityInArea.posX,
entityInArea.posY+2.5d, entityInArea.posZ, 0, 0, 0, 3);
}
else if (entityInArea != null && entityInArea instanceof EntityLiving) {
entityInArea.world.spawnParticle(EnumParticleTypes.HEART, entityInArea.posX,
entityInArea.posY+2d, entityInArea.posZ, 0, 1, 0, new int[0]);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import twopiradians.minewatch.common.item.ModItems;
import twopiradians.minewatch.common.item.armor.ModArmor;
import twopiradians.minewatch.common.sound.ModSoundEvents;
Expand All @@ -24,6 +27,7 @@ public ItemReinhardtHammer() {
super();
this.material = ModItems.reinhardt;
this.setMaxDamage(100);
MinecraftForge.EVENT_BUS.register(this);
}

@Override
Expand Down Expand Up @@ -58,4 +62,17 @@ public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity en
}
return false;
}

/**Reinhardt Hammer attack*/
@SubscribeEvent
public void onEvent(PlayerInteractEvent.LeftClickEmpty event) {
if (event.getWorld() != null && event.getEntityPlayer().getHeldItemMainhand() != null
&& event.getEntityPlayer().getHeldItemMainhand().getItem() instanceof ItemReinhardtHammer) {
EntityPlayer player = event.getEntityPlayer();
if (player.getCooldownTracker().hasCooldown(player.getHeldItemMainhand().getItem())) {
player.world.playSound(player, player.posX, player.posY, player.posZ,
ModSoundEvents.reinhardtRocketHammer, SoundCategory.PLAYERS, 1.0f, event.getWorld().rand.nextFloat()/2+0.75f);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package twopiradians.minewatch.common.item.weapon;

import java.util.UUID;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
Expand All @@ -10,22 +9,27 @@
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.EntityViewRenderEvent.FOVModifier;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import twopiradians.minewatch.common.entity.EntityTracerBullet;
import twopiradians.minewatch.common.item.ModItems;
import twopiradians.minewatch.common.item.armor.ModArmor;
import twopiradians.minewatch.common.sound.ModSoundEvents;

public class ItemTracerPistol extends ModWeapon
{
protected static final UUID MOVEMENT_SPEED_UUID = UUID.fromString("308e48ee-a300-4846-9b56-05e53e35eb8f");

{
public ItemTracerPistol() {
super();
this.setMaxDamage(100);
this.hasOffhand = true;
this.material = ModItems.tracer;
this.cooldown = 20;
this.cooldown = 40;
MinecraftForge.EVENT_BUS.register(this);
}

@Override
Expand All @@ -36,34 +40,65 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer play

@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
//FIXME player slowed down while using
if (!player.world.isRemote && player instanceof EntityPlayer) {
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() != Items.AIR && player.getHeldItemMainhand().getItem() instanceof ItemTracerPistol
&& player.ticksExisted % 2 == 0) {
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() != Items.AIR && player.getHeldItemMainhand().getItem() instanceof ItemTracerPistol) {
for (int i=0; i<2; i++)
player.world.spawnEntity(new EntityTracerBullet(player.world, player));
player.world.playSound(null, player.posX, player.posY, player.posZ,
ModSoundEvents.tracerPistol, SoundCategory.PLAYERS, 1.0f, player.world.rand.nextFloat()/20+0.95f);
player.world.spawnEntity(new EntityTracerBullet(player.world, player, EnumHand.MAIN_HAND));
player.world.playSound(null, player.posX, player.posY, player.posZ, ModSoundEvents.tracerPistol, SoundCategory.PLAYERS, 1.0f, player.world.rand.nextFloat()/20+0.95f);
if (count == 20 && !ModArmor.isSet((EntityPlayer)player, ModItems.tracer))
player.getHeldItemMainhand().damageItem(1, player);
}
if (player.getHeldItemOffhand() != null && player.getHeldItemOffhand().getItem() != Items.AIR && player.getHeldItemOffhand().getItem() instanceof ItemTracerPistol
&& player.ticksExisted % 2 == 1) {
if (player.getHeldItemOffhand() != null && player.getHeldItemOffhand().getItem() != Items.AIR && player.getHeldItemOffhand().getItem() instanceof ItemTracerPistol) {
for (int i=0; i<2; i++)
player.world.spawnEntity(new EntityTracerBullet(player.world, player));
player.world.playSound(null, player.posX, player.posY, player.posZ,
ModSoundEvents.tracerPistol, SoundCategory.PLAYERS, 1.0f, player.world.rand.nextFloat()/20+0.95f);
player.world.spawnEntity(new EntityTracerBullet(player.world, player, EnumHand.OFF_HAND));
player.world.playSound(null, player.posX, player.posY, player.posZ, ModSoundEvents.tracerPistol, SoundCategory.PLAYERS, 1.0f, player.world.rand.nextFloat()/20+0.95f);
if (count == 20 && !ModArmor.isSet((EntityPlayer)player, ModItems.tracer))
player.getHeldItemOffhand().damageItem(1, player);
}

if (count <= 1)
doCooldown((EntityPlayer)player, player.getActiveHand());
}
if (player.world.isRemote) {

float f6 = 0.91F;
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain(player.posX, player.getEntityBoundingBox().minY - 1.0D, player.posZ);
if (player.onGround)
f6 = player.world.getBlockState(blockpos$pooledmutableblockpos).getBlock().slipperiness * 0.91F;
float f7 = 0.16277136F / (f6 * f6 * f6);
float friction = 0;
if (player.onGround)
friction = player.getAIMoveSpeed() * f7;
else if (player.isInWater() || player.isInLava())
friction = 0.02f;
else
friction = player.jumpMovementFactor;
double slow = 1;
if (player.isInWater())
slow = 0.08d;
else if (player.isInLava())
slow = 0.05d;
player.motionX *= slow;
player.motionY *= slow;
player.motionZ *= slow;
player.moveRelative(player.moveStrafing*5f, player.moveForward*5f, friction);
}
}

/** How long it takes to use or consume an item*/
@Override
public int getMaxItemUseDuration(ItemStack stack) {
return 20;
}

/**Change the FOV when scoped*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onEvent(FOVModifier event) {
if (event.getEntity() != null && event.getEntity() instanceof EntityPlayer
&& ((((EntityPlayer)event.getEntity()).getHeldItemMainhand() != null && ((EntityPlayer)event.getEntity()).getHeldItemMainhand().getItem() instanceof ItemTracerPistol)
|| (((EntityPlayer)event.getEntity()).getHeldItemOffhand() != null && ((EntityPlayer)event.getEntity()).getHeldItemOffhand().getItem() instanceof ItemTracerPistol))) {
event.setFOV(Minecraft.getMinecraft().gameSettings.fovSetting);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package twopiradians.minewatch.common.item.weapon;

import java.util.Iterator;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
Expand All @@ -17,21 +13,16 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.client.event.EntityViewRenderEvent.FOVModifier;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import twopiradians.minewatch.common.Minewatch;
import twopiradians.minewatch.common.item.armor.ModArmor;
import twopiradians.minewatch.common.sound.ModSoundEvents;

public class ModWeapon extends Item
{
Expand All @@ -50,9 +41,7 @@ public class ModWeapon extends Item
protected void onShoot(World worldIn, EntityPlayer playerIn, EnumHand hand) {}

@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
System.out.println(player.ticksExisted+"hi");
}
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {}

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
Expand Down Expand Up @@ -96,32 +85,6 @@ public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSl
if (stack.getTagCompound().getInteger("cooldown") > 0)
stack.getTagCompound().setInteger("cooldown", --cooldown);
}
if (entityIn != null && entityIn instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)entityIn;

//Ana's Rifle
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemAnaRifle
&& Minewatch.keyMode.isKeyDown(player) && entityIn.ticksExisted % 10 == 0) {
AxisAlignedBB aabb = entityIn.getEntityBoundingBox().expandXyz(30);
List<Entity> list = entityIn.world.getEntitiesWithinAABBExcludingEntity(entityIn, aabb);
if (!list.isEmpty()) {
Iterator<Entity> iterator = list.iterator();
while (iterator.hasNext()) {
Entity entityInArea = iterator.next();
if (entityInArea != null && entityInArea instanceof EntityPlayer
&& ((EntityPlayer)entityInArea).isOnSameTeam(player)
&& ((EntityPlayer)entityInArea).getHealth() < ((EntityPlayer)entityInArea).getMaxHealth()) {
Minewatch.proxy.spawnParticlesHealthPlus(player.world, entityInArea.posX,
entityInArea.posY+2.5d, entityInArea.posZ, 0, 0, 0, 3);
}
else if (entityInArea != null && entityInArea instanceof EntityLiving) {
entityInArea.world.spawnParticle(EnumParticleTypes.HEART, entityInArea.posX,
entityInArea.posY+2d, entityInArea.posZ, 0, 1, 0, new int[0]);
}
}
}
}
}
}

public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
Expand All @@ -134,6 +97,8 @@ public int getItemStackLimit(ItemStack stack) {
return 1;
}

//Custom ------------------------------------------------------------------------

public EnumHand getInactiveHand(EntityPlayer player) {
if (!(player.getHeldItemMainhand().getItem() instanceof ModWeapon))
return EnumHand.MAIN_HAND;
Expand All @@ -154,9 +119,8 @@ public void doCooldown(EntityPlayer playerIn, EnumHand hand) {
else
playerIn.getCooldownTracker().setCooldown(playerIn.getHeldItem(hand).getItem(), cooldown);
}


//Events
//Events ------------------------------------------------------------------------

/**Change the FOV when scoped*/
@SideOnly(Side.CLIENT)
Expand All @@ -171,19 +135,6 @@ public void onEvent(FOVModifier event) {
}
}

/**Reinhardt Hammer attack*/
@SubscribeEvent
public void onEvent(PlayerInteractEvent.LeftClickEmpty event) {
if (event.getWorld() != null && event.getEntityPlayer().getHeldItemMainhand() != null
&& event.getEntityPlayer().getHeldItemMainhand().getItem() instanceof ItemReinhardtHammer) {
EntityPlayer player = event.getEntityPlayer();
if (player.getCooldownTracker().hasCooldown(player.getHeldItemMainhand().getItem())) {
player.world.playSound(player, player.posX, player.posY, player.posZ,
ModSoundEvents.reinhardtRocketHammer, SoundCategory.PLAYERS, 1.0f, event.getWorld().rand.nextFloat()/2+0.75f);
}
}
}

/**Rendering the scopes for rifles*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8336d0a

Please sign in to comment.