Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BoltcasterItem extends ShootableItem implements IVanishable {
- private final double damage;
- private final int velocity;
- public BoltcasterItem(double damageIn,int velocityIn, Properties builder) {
- super(builder);
- this.damage = damageIn;
- this.velocity = velocityIn;
- ItemModelsProperties.registerProperty(this, new ResourceLocation("loaded"), (stack, world, player) -> {
- if(player != null)
- return player.isHandActive() && player.getActiveItemStack() == stack ? 1.0F : player.findAmmo(stack).getCount();
- else
- return 0.0F;
- });
- }
- @Override
- public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
- ItemStack stack = playerIn.getHeldItem(handIn);
- boolean flag = playerIn.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
- ItemStack arrowstack = playerIn.findAmmo(stack);
- if (!arrowstack.isEmpty() || flag) {
- if (arrowstack.isEmpty()) {
- arrowstack = new ItemStack(Items.ARROW);
- }
- }
- float f = getArrowVelocity(10 + this.velocity);
- boolean flag1 = playerIn.abilities.isCreativeMode || (arrowstack.getItem() instanceof ArrowItem && ((ArrowItem) arrowstack.getItem()).isInfinite(arrowstack, stack, playerIn));
- boolean flag2 = !playerIn.findAmmo(stack).isEmpty();
- if (!worldIn.isRemote) {
- if (!playerIn.abilities.isCreativeMode && !flag2) {
- worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.BLOCK_DISPENSER_FAIL, SoundCategory.NEUTRAL, 1.0F, 1.5F);
- } else {
- ArrowItem arrowitem = (ArrowItem) (arrowstack.getItem() instanceof ArrowItem ? arrowstack.getItem() : Items.ARROW);
- AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, arrowstack, playerIn);
- abstractarrowentity = customArrow(abstractarrowentity);
- abstractarrowentity.func_234612_a_(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, f * 3.0F, 1.0F);
- abstractarrowentity.setDamage(abstractarrowentity.getDamage() + this.damage);
- if (f == 1.0F) {
- abstractarrowentity.setIsCritical(true);
- }
- int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
- if (j > 0) {
- abstractarrowentity.setDamage(abstractarrowentity.getDamage() + (double) j * 0.5D + 0.5D);
- }
- int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
- if (k > 0) {
- abstractarrowentity.setKnockbackStrength(k);
- }
- if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
- abstractarrowentity.setFire(100);
- }
- stack.damageItem(1, playerIn, (p_220009_1_) -> {
- p_220009_1_.sendBreakAnimation(playerIn.getActiveHand());
- });
- if (flag1 || playerIn.abilities.isCreativeMode && (arrowstack.getItem() == Items.SPECTRAL_ARROW || arrowstack.getItem() == Items.TIPPED_ARROW)) {
- abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
- }
- worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ITEM_CROSSBOW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.5F);
- worldIn.addEntity(abstractarrowentity);
- }
- if (!flag1 && !playerIn.abilities.isCreativeMode) {
- arrowstack.shrink(1);
- if (arrowstack.isEmpty()) {
- playerIn.inventory.deleteStack(arrowstack);
- }
- }
- }
- ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(stack, worldIn, playerIn, handIn, flag);
- if (ret != null) return ret;
- if (!playerIn.abilities.isCreativeMode && !flag2) {
- stack.getCapability(CoolDownCapability.COOLDOWN_CAPABILITY).map(h -> {
- boolean canCoolDown = h.getCanCoolDown();
- h.getCoolDownTracker().setCooldown(this, 30);
- ProjectDawn.LOGGER.info("empty side");
- return canCoolDown;
- }).orElse(null);
- return ActionResult.resultFail(stack);
- } else {
- playerIn.setActiveHand(handIn);
- stack.getCapability(CoolDownCapability.COOLDOWN_CAPABILITY).map(h -> {
- boolean canCoolDown = h.getCanCoolDown();
- h.getCoolDownTracker().setCooldown(this, 30);
- ProjectDawn.LOGGER.info("loaded side");
- return canCoolDown;
- }).orElse(null);
- return ActionResult.resultConsume(stack);
- }
- }
- @Override
- public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
- if (this.getClass() == BoltcasterItem.class)
- return new CoolDownProvider();
- else
- return super.initCapabilities(stack, nbt);
- }
- public static float getArrowVelocity(int charge) {
- float f = (float)charge / 20.0F;
- f = (f * f + f * 2.0F) / 3.0F;
- if (f > 1.0F) {
- f = 1.0F;
- }
- return f;
- }
- public AbstractArrowEntity customArrow(AbstractArrowEntity arrow) {
- return arrow;
- }
- @Override
- public Predicate<ItemStack> getInventoryAmmoPredicate() {
- return ARROWS;
- }
- @Override
- public int func_230305_d_() { return 8; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement