use of net.minecraft.entity.projectile.ArrowEntity in project Fragile-Glass by fredtargaryen.
the class EntityDataManager method addCapabilityIfPossible.
public void addCapabilityIfPossible(Entity e, AttachCapabilitiesEvent<Entity> evt) {
// A player would reasonably expect many existing entities to be able to break fragile blocks, but it is
// very unlikely that anyone would go to the trouble of writing out all the config lines for every entity.
// The following code does some type checks and creates BreakerDatas if the entity probably would break a block.
BreakerData breakerData = this.data.get(e.getType());
if (breakerData == null) {
// A breakerdata for this entitytype has not been created yet
if (e instanceof LivingEntity || e instanceof ArrowEntity || e instanceof FireballEntity || e instanceof MinecartEntity || e instanceof FireworkRocketEntity || e instanceof BoatEntity || e instanceof TNTEntity || e instanceof FallingBlockEntity) {
breakerData = new BreakerData(DataReference.MINIMUM_ENTITY_SPEED_SQUARED, DataReference.MAXIMUM_ENTITY_SPEED_SQUARED, new String[] {});
this.data.put(e.getType(), breakerData);
}
}
if (breakerData != null) {
// The entity was predefined (via configs or commands) as being able to break a block,
// or a BreakerData was automatically created above.
ICapabilityProvider iCapProv = new ICapabilityProvider() {
IBreakCapability inst = new IBreakCapability() {
@Override
public void init(Entity e) {
}
@Override
public void update(Entity e) {
}
@Override
public double getSpeedSquared(Entity e) {
Vector3d motion = e.getMotion();
return motion.x * motion.x + motion.y * motion.y + motion.z * motion.z;
}
@Override
public boolean isAbleToBreak(Entity e, double speedSq) {
BreakerData breakerData = EntityDataManager.this.data.get(e.getType());
if (breakerData == null)
return false;
return speedSq >= breakerData.getMinSpeedSquared() && speedSq <= breakerData.getMaxSpeedSquared();
}
@Override
public double getMotionX(Entity e) {
return e.getMotion().x;
}
@Override
public double getMotionY(Entity e) {
return e.getMotion().y;
}
@Override
public double getMotionZ(Entity e) {
return e.getMotion().z;
}
@Override
public byte getNoOfBreaks(Entity e) {
return 1;
}
};
@Nullable
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
return capability == FragileGlassBase.BREAKCAP ? LazyOptional.of(() -> (T) inst) : LazyOptional.empty();
}
};
evt.addCapability(DataReference.BREAK_LOCATION, iCapProv);
}
}
use of net.minecraft.entity.projectile.ArrowEntity in project BleachHack by BleachDrinker420.
the class ProjectileSimulator method summonProjectile.
public static Entity summonProjectile(PlayerEntity thrower, boolean allowThrowables, boolean allowXp, boolean allowPotions) {
ItemStack hand = (isThrowable(thrower.getInventory().getMainHandStack().getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().getMainHandStack() : isThrowable(thrower.getInventory().offHand.get(0).getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().offHand.get(0) : null);
if (hand == null) {
return null;
}
if (hand.getItem() instanceof RangedWeaponItem) {
float charged = hand.getItem() == Items.CROSSBOW && CrossbowItem.isCharged(hand) ? 1f : hand.getItem() == Items.CROSSBOW ? 0f : BowItem.getPullProgress(thrower.getItemUseTime());
if (charged > 0f) {
Entity e = new ArrowEntity(mc.world, mc.player);
initProjectile(e, thrower, 0f, charged * 3);
return e;
}
} else if (hand.getItem() instanceof SnowballItem || hand.getItem() instanceof EggItem || hand.getItem() instanceof EnderPearlItem) {
Entity e = new SnowballEntity(mc.world, mc.player);
initProjectile(e, thrower, 0f, 1.5f);
return e;
} else if (hand.getItem() instanceof ExperienceBottleItem) {
Entity e = new ExperienceBottleEntity(mc.world, mc.player);
initProjectile(e, thrower, -20f, 0.7f);
return e;
} else if (hand.getItem() instanceof ThrowablePotionItem) {
Entity e = new PotionEntity(mc.world, mc.player);
initProjectile(e, thrower, -20f, 0.5f);
return e;
} else if (hand.getItem() instanceof TridentItem) {
Entity e = new TridentEntity(mc.world, mc.player, hand);
initProjectile(e, thrower, 0f, 2.5f);
return e;
}
return null;
}
use of net.minecraft.entity.projectile.ArrowEntity in project minecolonies by ldtteam.
the class EntityAIArcherTraining method shoot.
/**
* The ranged attack modus
*
* @return the next state to go to.
*/
protected IAIState shoot() {
if (currentShootingTarget == null || !isSetup()) {
worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
return START_WORKING;
}
if (worker.isUsingItem()) {
WorkerUtil.faceBlock(currentShootingTarget, worker);
worker.swing(Hand.MAIN_HAND);
final ArrowEntity arrow = ModEntities.MC_NORMAL_ARROW.create(world);
arrow.setBaseDamage(0);
arrow.setOwner(worker);
arrow.setPos(worker.getX(), worker.getY() + 1, worker.getZ());
final double xVector = currentShootingTarget.getX() - worker.getX();
final double yVector = currentShootingTarget.getY() - arrow.getY();
final double zVector = currentShootingTarget.getZ() - worker.getZ();
final double distance = (double) MathHelper.sqrt(xVector * xVector + zVector * zVector);
final double chance = HIT_CHANCE_DIVIDER / (getPrimarySkillLevel() / 2.0 + 1);
arrow.shoot(xVector, yVector + distance * RANGED_AIM_SLIGHTLY_HIGHER_MULTIPLIER, zVector, RANGED_VELOCITY, (float) chance);
worker.playSound(SoundEvents.SKELETON_SHOOT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom()));
worker.level.addFreshEntity(arrow);
final double xDiff = currentShootingTarget.getX() - worker.getX();
final double zDiff = currentShootingTarget.getZ() - worker.getZ();
final double goToX = xDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
final double goToZ = zDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
worker.move(MoverType.SELF, new Vector3d(goToX, 0, goToZ));
if (worker.getRandom().nextBoolean()) {
worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
}
worker.stopUsingItem();
this.incrementActionsDoneAndDecSaturation();
arrowInProgress = arrow;
currentAttackDelay = RANGED_ATTACK_DELAY_BASE;
} else {
reduceAttackDelay();
if (currentAttackDelay <= 0) {
worker.startUsingItem(Hand.MAIN_HAND);
}
return ARCHER_SHOOT;
}
return ARCHER_CHECK_SHOT;
}
Aggregations