use of blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet in project ImmersiveEngineering by BluSunrize.
the class ItemBullet method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
if (stack.getItemDamage() == 2) {
String key = ItemNBTHelper.getString(stack, "bullet");
IBullet bullet = BulletHandler.getBullet(key);
if (bullet != null)
bullet.addTooltip(stack, player, list, advanced);
}
}
use of blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet in project ImmersiveEngineering by BluSunrize.
the class EntityRevolvershot method secondaryImpact.
public void secondaryImpact(RayTraceResult mop) {
if (bulletElectro && mop.entityHit instanceof EntityLivingBase) {
IBullet bullet = BulletHandler.getBullet(bulletType);
float percentualDrain = .15f / (bullet == null ? 1 : bullet.getProjectileCount(shootingEntity instanceof EntityPlayer ? (EntityPlayer) this.shootingEntity : null));
((EntityLivingBase) mop.entityHit).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 15, 4));
for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
ItemStack stack = ((EntityLivingBase) mop.entityHit).getItemStackFromSlot(slot);
if (EnergyHelper.isFluxItem(stack) && EnergyHelper.getEnergyStored(stack) > 0) {
int drain = (int) Math.max(EnergyHelper.getEnergyStored(stack), EnergyHelper.getMaxEnergyStored(stack) * percentualDrain);
int hasDrained = 0;
while (hasDrained < drain) {
int actualDrain = EnergyHelper.forceExtractFlux(stack, drain, false);
if (actualDrain <= 0)
break;
hasDrained += actualDrain;
}
}
}
}
// if(bulletType==6)
// {
// Vec3d v = new Vec3d(-motionX, -motionY, -motionZ);
// int split = 6;
// for(int i=0; i<split; i++)
// {
// float angle = i * (360f/split);
// Matrix4 matrix = new Matrix4();
// matrix.rotate(angle, v.xCoord,v.yCoord,v.zCoord);
// Vec3d vecDir = new Vec3d(0, 1, 0);
// vecDir = matrix.apply(vecDir);
//
// EntityWolfpackShot bullet = new EntityWolfpackShot(world, this.shootingEntity, vecDir.xCoord*1.5,vecDir.yCoord*1.5,vecDir.zCoord*1.5, this.bulletType, null);
// if(mop.entityHit instanceof EntityLivingBase)
// bullet.targetOverride = (EntityLivingBase)mop.entityHit;
// bullet.setPosition(posX+vecDir.xCoord, posY+vecDir.yCoord, posZ+vecDir.zCoord);
// bullet.motionX = vecDir.xCoord*.375;
// bullet.motionY = vecDir.yCoord*.375;
// bullet.motionZ = vecDir.zCoord*.375;
// world.spawnEntity(bullet);
// }
// }
// if(bulletType==8 && bulletPotion!=null && bulletPotion.getItem() instanceof ItemPotion)
// {
// PotionType potionType = PotionUtils.getPotionFromItem(bulletPotion);
// List<PotionEffect> effects = PotionUtils.getEffectsFromStack(bulletPotion);
// if(effects!=null)
// if(bulletPotion.getItem() instanceof ItemLingeringPotion)
// {
// EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.world, this.posX, this.posY, this.posZ);
// entityareaeffectcloud.setOwner(shootingEntity);
// entityareaeffectcloud.setRadius(3.0F);
// entityareaeffectcloud.setRadiusOnUse(-0.5F);
// entityareaeffectcloud.setWaitTime(10);
// entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float)entityareaeffectcloud.getDuration());
// entityareaeffectcloud.setPotion(potionType);
// for(PotionEffect potioneffect : effects)
// entityareaeffectcloud.addEffect(new PotionEffect(potioneffect.getPotion(), potioneffect.getDuration(), potioneffect.getAmplifier()));
// this.world.spawnEntity(entityareaeffectcloud);
// }
// else if(bulletPotion.getItem() instanceof ItemSplashPotion)
// {
// List<EntityLivingBase> livingEntities = this.world.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D));
// if(livingEntities!=null && !livingEntities.isEmpty())
// for(EntityLivingBase living : livingEntities)
// if(living.canBeHitWithPotion())
// {
// double dist = this.getDistanceSqToEntity(living);
// if(dist<16D)
// {
// double dist2 = 1-Math.sqrt(dist)/4D;
// if(living == mop.entityHit)
// dist2 = 1D;
// for(PotionEffect p : effects)
// if(p.getPotion().isInstant())
// p.getPotion().affectEntity(this, this.shootingEntity, living, p.getAmplifier(), dist2);
// else
// {
// int j = (int)(dist2*p.getDuration()+.5D);
// if(j>20)
// living.addPotionEffect(new PotionEffect(p.getPotion(),j, p.getAmplifier()));
// }
// }
// }
//
// }
// else if(mop.entityHit instanceof EntityLivingBase)
// for(PotionEffect p : effects)
// {
// if(p.getDuration()<1)
// p = new PotionEffect(p.getPotion(),1);
// ((EntityLivingBase)mop.entityHit).addPotionEffect(p);
// }
// world.playEvent(2002, new BlockPos(this), PotionType.getID(potionType));
// }
}
use of blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet in project ImmersiveEngineering by BluSunrize.
the class ItemRevolver method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
ItemStack revolver = player.getHeldItem(hand);
if (!world.isRemote) {
if (player.isSneaking()) {
CommonProxy.openGuiForItem(player, hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
} else if (player.getCooledAttackStrength(1) >= 1) {
if (this.getUpgrades(revolver).getBoolean("nerf"))
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1f, 0.6f);
else {
if (getShootCooldown(revolver) > 0 || ItemNBTHelper.hasKey(revolver, "reload"))
return new ActionResult(EnumActionResult.PASS, revolver);
NonNullList<ItemStack> bullets = getBullets(revolver);
if (isEmpty(revolver, false))
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i);
if (stack.getItem() instanceof ItemSpeedloader && !((ItemSpeedloader) stack.getItem()).isEmpty(stack)) {
for (ItemStack b : bullets) if (!b.isEmpty())
world.spawnEntity(new EntityItem(world, player.posX, player.posY, player.posZ, b));
setBullets(revolver, ((ItemSpeedloader) stack.getItem()).getContainedItems(stack), true);
((ItemSpeedloader) stack.getItem()).setContainedItems(stack, NonNullList.withSize(8, ItemStack.EMPTY));
player.inventory.markDirty();
if (player instanceof EntityPlayerMP)
ImmersiveEngineering.packetHandler.sendTo(new MessageSpeedloaderSync(i, hand), (EntityPlayerMP) player);
ItemNBTHelper.setInt(revolver, "reload", 60);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
}
if (!ItemNBTHelper.hasKey(revolver, "reload")) {
if (!bullets.get(0).isEmpty() && bullets.get(0).getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(bullets.get(0), "bullet")) {
String key = ItemNBTHelper.getString(bullets.get(0), "bullet");
IBullet bullet = BulletHandler.getBullet(key);
if (bullet != null) {
Vec3d vec = player.getLookVec();
boolean electro = getUpgrades(revolver).getBoolean("electro");
int count = bullet.getProjectileCount(player);
if (count == 1) {
Entity entBullet = getBullet(player, vec, vec, key, bullets.get(0), electro);
player.world.spawnEntity(bullet.getProjectile(player, bullets.get(0), entBullet, electro));
} else
for (int i = 0; i < count; i++) {
Vec3d vecDir = vec.add(player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1);
Entity entBullet = getBullet(player, vec, vecDir, key, bullets.get(0), electro);
player.world.spawnEntity(bullet.getProjectile(player, bullets.get(0), entBullet, electro));
}
bullets.set(0, bullet.getCasing(bullets.get(0)).copy());
float noise = 0.5f;
if (hasUpgradeValue(revolver, RevolverPerk.NOISE.getNBTKey()))
noise *= (float) getUpgradeValue_d(revolver, RevolverPerk.NOISE.getNBTKey());
Utils.attractEnemies(player, 64 * noise);
SoundEvent sound = bullet.getSound();
if (sound == null)
sound = IESounds.revolverFire;
world.playSound(null, player.posX, player.posY, player.posZ, sound, SoundCategory.PLAYERS, noise, 1f);
} else
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
} else
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
rotateCylinder(revolver, player, true, bullets);
ItemNBTHelper.setInt(revolver, "cooldown", getMaxShootCooldown(revolver));
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
}
}
} else if (!player.isSneaking() && revolver.getItemDamage() == 0) {
if (getShootCooldown(revolver) > 0 || ItemNBTHelper.hasKey(revolver, "reload"))
return new ActionResult(EnumActionResult.PASS, revolver);
NonNullList<ItemStack> bullets = getBullets(revolver);
if (!bullets.get(0).isEmpty() && bullets.get(0).getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(bullets.get(0), "bullet")) {
Triple<ItemStack, ShaderRegistryEntry, ShaderCase> shader = ShaderRegistry.getStoredShaderAndCase(revolver);
if (shader != null) {
Vec3d pos = Utils.getLivingFrontPos(player, .75, player.height * .75, hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(), false, 1);
shader.getMiddle().getEffectFunction().execute(world, shader.getLeft(), revolver, shader.getRight().getShaderType(), pos, player.getForward(), .125f);
}
}
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
use of blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet in project ImmersiveEngineering by BluSunrize.
the class TileEntityTurretGun method activate.
@Override
protected void activate() {
int energy = IEConfig.Machines.turret_gun_consumption;
ItemStack bulletStack = inventory.get(0);
if (!bulletStack.isEmpty() && this.energyStorage.extractEnergy(energy, true) == energy) {
String key = ItemNBTHelper.getString(bulletStack, "bullet");
IBullet bullet = BulletHandler.getBullet(key);
if (bullet != null && bullet.isValidForTurret()) {
ItemStack casing = bullet.getCasing(bulletStack);
if (expelCasings || casing.isEmpty() || inventory.get(1).isEmpty() || (OreDictionary.itemMatches(casing, inventory.get(1), false) && inventory.get(1).getCount() + casing.getCount() <= inventory.get(1).getMaxStackSize())) {
this.energyStorage.extractEnergy(energy, false);
this.sendRenderPacket();
Vec3d vec = getGunToTargetVec(target).normalize();
int count = bullet.getProjectileCount(null);
if (count == 1) {
Entity entBullet = getBulletEntity(world, vec, bullet);
world.spawnEntity(bullet.getProjectile(null, bulletStack, entBullet, false));
} else
for (int i = 0; i < count; i++) {
Vec3d vecDir = vec.add(Utils.RAND.nextGaussian() * .1, Utils.RAND.nextGaussian() * .1, Utils.RAND.nextGaussian() * .1);
Entity entBullet = getBulletEntity(world, vecDir, bullet);
world.spawnEntity(bullet.getProjectile(null, bulletStack, entBullet, false));
}
bulletStack.shrink(1);
if (bulletStack.getCount() <= 0)
inventory.set(0, ItemStack.EMPTY);
if (!casing.isEmpty()) {
if (expelCasings) {
double cX = getPos().getX() + .5;
double cY = getPos().getY() + 1.375;
double cZ = getPos().getZ() + .5;
Vec3d vCasing = vec.rotateYaw(-1.57f);
world.spawnParticle(EnumParticleTypes.REDSTONE, cX + vCasing.x, cY + vCasing.y, cZ + vCasing.z, 0, 0, 0, 1, 0);
EntityItem entCasing = new EntityItem(world, cX + vCasing.x, cY + vCasing.y, cZ + vCasing.z, casing.copy());
entCasing.motionX = 0;
entCasing.motionY = -0.01;
entCasing.motionZ = 0;
world.spawnEntity(entCasing);
} else {
if (inventory.get(1).isEmpty())
inventory.set(1, casing.copy());
else
inventory.get(1).grow(casing.getCount());
}
}
SoundEvent sound = bullet.getSound();
if (sound == null)
sound = IESounds.revolverFire;
world.playSound(null, getPos(), sound, SoundCategory.BLOCKS, 1, 1);
}
}
}
}
use of blusunrize.immersiveengineering.api.tool.BulletHandler.IBullet in project ImmersiveEngineering by BluSunrize.
the class ItemRevolver method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack revolver, World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote) {
if (player.isSneaking() || revolver.getItemDamage() == 1) {
CommonProxy.openGuiForItem(player, hand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
} else if (this.getUpgrades(revolver).getBoolean("nerf"))
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1f, 0.6f);
else {
if (ItemNBTHelper.getInt(revolver, "cooldown") > 0)
return new ActionResult(EnumActionResult.PASS, revolver);
ItemStack[] bullets = getBullets(revolver);
if (isEmpty(revolver)) {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack loader = player.inventory.getStackInSlot(i);
if (loader != null && loader.getItem() == this && loader.getItemDamage() == 1 && !isEmpty(loader)) {
int dc = 0;
for (ItemStack b : bullets) if (b != null) {
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, b));
dc++;
}
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.PLAYERS, .5f, 3f);
ItemNBTHelper.setDelayedSoundsForStack(revolver, "casings", "random.successful_hit", .05f, 5, dc / 2, 8, 2);
setBullets(revolver, getBullets(loader));
setBullets(loader, new ItemStack[8]);
player.inventory.setInventorySlotContents(i, loader);
player.inventory.markDirty();
if (player instanceof EntityPlayerMP)
ImmersiveEngineering.packetHandler.sendTo(new MessageSpeedloaderSync(i), (EntityPlayerMP) player);
ItemNBTHelper.setBoolean(revolver, "blocked", true);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
}
}
if (!ItemNBTHelper.getBoolean(revolver, "blocked")) {
if (bullets[0] != null && bullets[0].getItem() instanceof ItemBullet && ItemNBTHelper.hasKey(bullets[0], "bullet")) {
String key = ItemNBTHelper.getString(bullets[0], "bullet");
IBullet bullet = BulletHandler.getBullet(key);
if (bullet != null) {
Vec3d vec = player.getLookVec();
boolean electro = getUpgrades(revolver).getBoolean("electro");
int count = bullet.getProjectileCount(player);
if (count == 1) {
Entity entBullet = getBullet(player, vec, vec, key, bullets[0], electro);
player.worldObj.spawnEntityInWorld(bullet.getProjectile(player, bullets[0], entBullet, electro));
} else
for (int i = 0; i < count; i++) {
Vec3d vecDir = vec.addVector(player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1, player.getRNG().nextGaussian() * .1);
Entity entBullet = getBullet(player, vec, vecDir, key, bullets[0], electro);
player.worldObj.spawnEntityInWorld(bullet.getProjectile(player, bullets[0], entBullet, electro));
}
bullets[0] = bullet.getCasing(bullets[0]);
world.playSound(null, player.posX, player.posY, player.posZ, IESounds.revolverFire, SoundCategory.PLAYERS, 1f, 1f);
} else
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
} else
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_HAT, SoundCategory.PLAYERS, 1f, 1f);
ItemStack[] cycled = new ItemStack[getBulletSlotAmount(revolver)];
for (int i = 1; i < cycled.length; i++) cycled[i - 1] = bullets[i];
cycled[cycled.length - 1] = bullets[0];
setBullets(revolver, cycled);
ItemNBTHelper.setInt(revolver, "cooldown", 10);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
}
} else if (!player.isSneaking() && revolver.getItemDamage() == 0)
return new ActionResult(ItemNBTHelper.getInt(revolver, "cooldown") > 0 ? EnumActionResult.PASS : EnumActionResult.SUCCESS, revolver);
return new ActionResult(EnumActionResult.SUCCESS, revolver);
}
Aggregations