use of net.minecraft.entity.projectile.EntityThrowable in project SpongeCommon by SpongePowered.
the class InteractionPacketState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final EntityPlayerMP player = phaseContext.getPacketPlayer();
final ItemStack usedStack = phaseContext.getItemUsed();
final ItemStackSnapshot usedSnapshot = ItemStackUtil.snapshotOf(usedStack);
final Entity spongePlayer = EntityUtil.fromNative(player);
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(spongePlayer);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
final boolean hasBlocks = !phaseContext.getCapturedBlockSupplier().isEmpty();
final List<BlockSnapshot> capturedBlcoks = phaseContext.getCapturedBlocks();
@Nullable final BlockSnapshot firstBlockChange = hasBlocks ? capturedBlcoks.get(0) : null;
if (hasBlocks) {
if (!TrackingUtil.processBlockCaptures(capturedBlcoks, this, phaseContext)) {
// Stop entities like XP from being spawned
return;
}
} else {
phaseContext.getBlockItemDropSupplier().acceptIfNotEmpty(map -> {
if (ShouldFire.DROP_ITEM_EVENT_DESTRUCT) {
for (BlockSnapshot blockChange : capturedBlcoks) {
final Location<World> location = blockChange.getLocation().get();
final Vector3d position = location.getPosition();
final BlockPos blockPos = VecHelper.toBlockPos(position);
final Collection<EntityItem> entityItems = map.get(blockPos);
if (!entityItems.isEmpty()) {
final List<Entity> items = entityItems.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
final DropItemEvent.Destruct event = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), items);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
}
}
} else {
for (BlockSnapshot blockChange : capturedBlcoks) {
final Location<World> location = blockChange.getLocation().get();
final Vector3d position = location.getPosition();
final BlockPos blockPos = VecHelper.toBlockPos(position);
final Collection<EntityItem> entityItems = map.get(blockPos);
if (!entityItems.isEmpty()) {
processEntities(player, (Collection<Entity>) (Collection<?>) entityItems);
}
}
}
});
}
phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
final ArrayList<Entity> entities = new ArrayList<>();
for (EntityItem item : items) {
entities.add(EntityUtil.fromNative(item));
}
final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(dispense);
if (!dispense.isCancelled()) {
processSpawnedEntities(player, dispense);
}
});
phaseContext.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
if (map.isEmpty()) {
return;
}
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interaction").centre().hr();
printer.add("The item stacks captured are: ");
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
printer.add(" - Entity with UUID: %s", entry.getKey());
for (ItemDropData stack : entry.getValue()) {
printer.add(" - %s", stack);
}
}
printer.trace(System.err);
});
phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
final List<Entity> projectiles = new ArrayList<>(entities.size());
final List<Entity> spawnEggs = new ArrayList<>(entities.size());
final List<Entity> xpOrbs = new ArrayList<>(entities.size());
final List<Entity> normalPlacement = new ArrayList<>(entities.size());
final List<Entity> items = new ArrayList<>(entities.size());
for (Entity entity : entities) {
if (entity instanceof Projectile || entity instanceof EntityThrowable) {
projectiles.add(entity);
} else if (usedSnapshot.getType() == ItemTypes.SPAWN_EGG) {
spawnEggs.add(entity);
} else if (entity instanceof EntityItem) {
items.add(entity);
} else if (entity instanceof EntityXPOrb) {
xpOrbs.add(entity);
} else {
normalPlacement.add(entity);
}
}
if (!projectiles.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
Sponge.getCauseStackManager().pushCause(usedSnapshot);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), projectiles);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, projectiles);
}
}
if (!spawnEggs.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
Sponge.getCauseStackManager().pushCause(usedSnapshot);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), spawnEggs);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, spawnEggs);
}
}
if (!items.isEmpty()) {
if (ShouldFire.DROP_ITEM_EVENT_DISPENSE) {
final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), items);
if (!SpongeImpl.postEvent(dispense)) {
processSpawnedEntities(player, dispense);
}
} else {
processEntities(player, items);
}
}
if (!xpOrbs.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (firstBlockChange != null) {
stackFrame.pushCause(firstBlockChange);
}
stackFrame.addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), xpOrbs);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, xpOrbs);
}
}
if (!normalPlacement.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (firstBlockChange != null) {
stackFrame.pushCause(firstBlockChange);
}
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), normalPlacement);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, normalPlacement);
}
}
});
final IMixinContainer mixinContainer = ContainerUtil.toMixin(player.openContainer);
mixinContainer.setCaptureInventory(false);
mixinContainer.getCapturedTransactions().clear();
}
}
use of net.minecraft.entity.projectile.EntityThrowable in project SpongeCommon by SpongePowered.
the class ProjectileLauncher method defaultLaunch.
@SuppressWarnings("unchecked")
static <P extends Projectile> Optional<P> defaultLaunch(ProjectileSource source, Class<P> projectileClass, Location<?> loc) {
Optional<EntityType> opType = EntityTypeRegistryModule.getInstance().getEntity(projectileClass);
if (!opType.isPresent()) {
return Optional.empty();
}
Entity projectile = loc.getExtent().createEntity(opType.get(), loc.getPosition());
if (projectile instanceof EntityThrowable) {
configureThrowable((EntityThrowable) projectile);
}
return doLaunch(loc.getExtent(), (P) projectile);
}
use of net.minecraft.entity.projectile.EntityThrowable in project ClaySoldiersMod by SanAndreasP.
the class TileEntityClayNexus method updateEntity.
@Override
public void updateEntity() {
if (this.p_searchArea == null || this.p_damageArea == null) {
this.p_searchArea = AxisAlignedBB.getBoundingBox(this.xCoord - 63.0D, this.yCoord - 63.0D, this.zCoord - 63.0D, this.xCoord + 64.0D, this.yCoord + 64.0D, this.zCoord + 64.0D);
this.p_damageArea = AxisAlignedBB.getBoundingBox(this.xCoord + 0.1D, this.yCoord + 0.1D, this.zCoord + 0.1D, this.xCoord + 0.9D, this.yCoord + 0.9D, this.zCoord + 0.9D);
}
super.updateEntity();
boolean isRsPowered = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord) || this.worldObj.getIndirectPowerLevelTo(this.xCoord - 1, this.yCoord, this.zCoord, 1) > 0 || this.worldObj.getIndirectPowerLevelTo(this.xCoord, this.yCoord, this.zCoord + 1, 1) > 0 || this.worldObj.getIndirectPowerLevelTo(this.xCoord, this.yCoord, this.zCoord - 1, 1) > 0 || this.worldObj.getIndirectPowerLevelTo(this.xCoord + 1, this.yCoord, this.zCoord, 1) > 0;
if (!this.worldObj.isRemote && !this.p_prevRsPowerState && isRsPowered) {
this.isActive = !this.isActive;
this.markDirty();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
this.p_prevRsPowerState = isRsPowered;
if (this.isActive) {
if (this.p_health <= 0.0F) {
this.isActive = false;
} else {
this.ticksActive++;
}
if (!this.worldObj.isRemote && this.p_health > 0.0F) {
if (this.ticksActive % 20 == 0) {
int dmgEnemies = this.countDamagingEnemies();
if (dmgEnemies > 0) {
float healthDamage = 0.5F;
if (dmgEnemies > 1) {
healthDamage = 0.125F * dmgEnemies;
}
this.p_health -= healthDamage;
if (this.p_health < 0.0F) {
this.p_health = 0.0F;
}
this.markDirty();
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
List<EntityClayMan> enemies = this.getEnemies(true);
for (EntityClayMan dalek : enemies) {
if (!dalek.hasPath()) {
dalek.setPathToEntity(BugfixHelper.getEntityPathToXYZ(this.worldObj, dalek, this.xCoord, this.yCoord, this.zCoord, 64.0F, true, false, false, true));
}
}
}
if (ticksActive % this.spawnThrowableInterval == 0 && this.p_throwableSlot != null) {
List<EntityClayMan> clayMen = getEnemies(true);
if (clayMen.size() > 0) {
EntityClayMan target = clayMen.get(SAPUtils.RNG.nextInt(clayMen.size()));
double deltaX = target.posX - this.xCoord + 0.5F;
double deltaZ = target.posZ - this.zCoord + 0.5F;
try {
ISoldierProjectile<? extends EntityThrowable> projectile = this.p_tempThrowableCls.getConstructor(World.class, double.class, double.class, double.class).newInstance(this.worldObj, this.xCoord + 0.5F, this.yCoord + 0.875F, this.zCoord + 0.5F);
projectile.initProjectile(target, true, this.p_tempClayTeam.getTeamName());
EntityThrowable throwable = projectile.getProjectileEntity();
double d2 = (target.posY + target.getEyeHeight()) - 0.10000000298023224D - throwable.posY;
float f1 = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ) * 0.2F;
this.worldObj.spawnEntityInWorld(throwable);
throwable.setThrowableHeading(deltaX, d2 + f1, deltaZ, 0.6F, 12.0F);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
FMLLog.log(ClaySoldiersMod.MOD_LOG, Level.ERROR, "%1$s cannot be instantiated! %1$s is not thrown to target!", this.p_tempThrowableCls.getName());
e.printStackTrace();
}
}
}
if (this.p_soldierSlot != null) {
if (this.ticksActive % this.spawnSoldierInterval == 0 && this.p_spawningSoldierCounter <= 0) {
this.p_spawningSoldierCounter = Math.min(this.soldierSpawnCount, this.maxSoldierCount - this.countTeammates());
this.p_prevSpawningSoldierCounter = this.p_spawningSoldierCounter;
}
if (ticksActive % 5 == 0) {
if (this.p_spawningSoldierCounter > 0) {
this.p_spawningSoldierCounter = Math.min(this.p_prevSpawningSoldierCounter, this.maxSoldierCount - this.countTeammates());
this.p_prevSpawningSoldierCounter = this.p_spawningSoldierCounter - 1;
if (this.p_spawningSoldierCounter > 0) {
ItemClayManDoll.spawnClayMan(this.worldObj, this.p_tempClayTeam.getTeamName(), this.xCoord + 0.5F, this.yCoord + 0.2D, this.zCoord + 0.5F).nexusSpawn = true;
}
}
}
}
}
}
if (this.worldObj.isRemote) {
this.prevSpinAngle = this.spinAngle;
if (this.isActive && this.p_health > 0.0F) {
this.spinAngle += 4;
RGBAValues rgba = SAPUtils.getRgbaFromColorInt(ItemClayManDoll.getTeam(this.p_soldierSlot).getTeamColor());
ClaySoldiersMod.proxy.spawnParticles(EnumParticleFx.FX_NEXUS, Sextet.with((double) this.xCoord, (double) this.yCoord, (double) this.zCoord, rgba.getRed() / 255.0F, rgba.getGreen() / 255.0F, rgba.getBlue() / 255.0F));
} else if (this.spinAngle % 90 != 0) {
this.spinAngle += 2;
}
if (this.spinAngle >= 360) {
this.prevSpinAngle = -1;
this.spinAngle = 0;
}
}
}
use of net.minecraft.entity.projectile.EntityThrowable in project BloodMagic by WayofTime.
the class PotionEventHandlers method onEntityUpdate.
@SubscribeEvent
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND)) {
int d0 = 3;
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(event.getEntityLiving().posX - 0.5, event.getEntityLiving().posY - 0.5, event.getEntityLiving().posZ - 0.5, event.getEntityLiving().posX + 0.5, event.getEntityLiving().posY + 0.5, event.getEntityLiving().posZ + 0.5).expand(d0, d0, d0);
List<Entity> entityList = event.getEntityLiving().getEntityWorld().getEntitiesWithinAABB(Entity.class, axisAlignedBB);
for (Entity projectile : entityList) {
if (projectile == null)
continue;
if (!(projectile instanceof IProjectile))
continue;
Entity throwingEntity = null;
if (projectile instanceof EntityArrow)
throwingEntity = ((EntityArrow) projectile).shootingEntity;
else if (projectile instanceof EntityThrowable)
throwingEntity = ((EntityThrowable) projectile).getThrower();
if (throwingEntity != null && throwingEntity.equals(event.getEntityLiving()))
continue;
double delX = projectile.posX - event.getEntityLiving().posX;
double delY = projectile.posY - event.getEntityLiving().posY;
double delZ = projectile.posZ - event.getEntityLiving().posZ;
double angle = (delX * projectile.motionX + delY * projectile.motionY + delZ * projectile.motionZ) / (Math.sqrt(delX * delX + delY * delY + delZ * delZ) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
angle = Math.acos(angle);
if (angle < 3 * (Math.PI / 4))
// angle is < 135 degrees
continue;
if (throwingEntity != null) {
delX = -projectile.posX + throwingEntity.posX;
delY = -projectile.posY + (throwingEntity.posY + throwingEntity.getEyeHeight());
delZ = -projectile.posZ + throwingEntity.posZ;
}
double curVel = Math.sqrt(delX * delX + delY * delY + delZ * delZ);
delX /= curVel;
delY /= curVel;
delZ /= curVel;
double newVel = Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ);
projectile.motionX = newVel * delX;
projectile.motionY = newVel * delY;
projectile.motionZ = newVel * delZ;
}
}
}
use of net.minecraft.entity.projectile.EntityThrowable in project BloodMagic by WayofTime.
the class LivingArmourHandler method onEntityJoinedWorld.
// Applies: Storm Trooper
@SubscribeEvent
public static void onEntityJoinedWorld(EntityJoinWorldEvent event) {
Entity owner = null;
if (event.getEntity() instanceof EntityArrow) {
owner = ((EntityArrow) event.getEntity()).shootingEntity;
} else if (event.getEntity() instanceof EntityThrowable) {
owner = ((EntityThrowable) event.getEntity()).getThrower();
}
if (owner instanceof EntityPlayer) {
Entity projectile = event.getEntity();
EntityPlayer player = (EntityPlayer) owner;
if (LivingArmour.hasFullSet(player)) {
ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
if (armour != null) {
LivingArmourUpgrade upgrade = ItemLivingArmour.getUpgrade(BloodMagic.MODID + ".upgrade.stormTrooper", chestStack);
if (upgrade instanceof LivingArmourUpgradeStormTrooper) {
float velocityModifier = (float) (((LivingArmourUpgradeStormTrooper) upgrade).getArrowJiggle(player) * Math.sqrt(projectile.motionX * projectile.motionX + projectile.motionY * projectile.motionY + projectile.motionZ * projectile.motionZ));
projectile.motionX += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
projectile.motionY += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
projectile.motionZ += 2 * (event.getWorld().rand.nextDouble() - 0.5) * velocityModifier;
}
}
}
}
}
Aggregations