use of net.minecraft.util.math.Vec3d in project SpongeCommon by SpongePowered.
the class EntityUtil method rayTraceFromEntity.
public static RayTraceResult rayTraceFromEntity(Entity source, double traceDistance, float partialTicks) {
Vec3d traceStart = EntityUtil.getPositionEyes(source, partialTicks);
Vec3d lookDir = source.getLook(partialTicks).scale(traceDistance);
Vec3d traceEnd = traceStart.add(lookDir);
return source.world.rayTraceBlocks(traceStart, traceEnd, false, false, true);
}
use of net.minecraft.util.math.Vec3d in project SpongeCommon by SpongePowered.
the class MixinCommandTeleport method execute.
/**
* @author Aaron1011 - August 15, 2016
* @reason Prevent 'notifyCommandListener' from being called the event is cancelled
*/
@Overwrite
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 4) {
throw new WrongUsageException("commands.teleport.usage", new Object[0]);
} else {
Entity entity = getEntity(server, sender, args[0]);
if (entity.world != null) {
// int i = 4096;
Vec3d vec3d = sender.getPositionVector();
int j = 1;
CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(vec3d.x, args[j++], true);
CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(vec3d.y, args[j++], -4096, 4096, false);
CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(vec3d.z, args[j++], true);
Entity entity1 = sender.getCommandSenderEntity() == null ? entity : sender.getCommandSenderEntity();
CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate(args.length > j ? (double) entity1.rotationYaw : (double) entity.rotationYaw, args.length > j ? args[j] : "~", false);
++j;
CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate(args.length > j ? (double) entity1.rotationPitch : (double) entity.rotationPitch, args.length > j ? args[j] : "~", false);
// Sponge start - check shouldNotifyCommandListener before calling 'notifyCommandListener'
// Guard against any possible re-entrance
boolean shouldNotify = shouldNotifyCommandListener;
doTeleport(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
if (shouldNotifyCommandListener) {
notifyCommandListener(sender, this, "commands.tp.success.coordinates", new Object[] { entity.getName(), Double.valueOf(commandbase$coordinatearg.getResult()), Double.valueOf(commandbase$coordinatearg1.getResult()), Double.valueOf(commandbase$coordinatearg2.getResult()) });
}
shouldNotifyCommandListener = shouldNotify;
// Sponge end
}
}
}
use of net.minecraft.util.math.Vec3d in project SpongeCommon by SpongePowered.
the class MixinExplosion method doExplosionA.
// TODO fix this whereever it was called from?
// @Override
// public Cause createCause() {
// if (this.createdCause != null) {
// return this.createdCause;
// }
// Object source;
// Object projectileSource = null;
// Object igniter = null;
// if (this.exploder == null) {
// source = getWorld().getBlock(getLocation().getPosition().toInt());
// } else {
// source = this.exploder;
// if (source instanceof Projectile) {
// projectileSource = ((Projectile) this.exploder).getShooter();
// }
//
// // Don't use the exploder itself as igniter
// igniter = getExplosivePlacedBy();
// if (this.exploder == igniter) {
// igniter = null;
// }
// }
//
// final Cause.Builder builder = Cause.source(source);
// if (projectileSource != null) {
// if (igniter != null) {
// builder.named(NamedCause.of("ProjectileSource", projectileSource)).named(NamedCause.of("Igniter", igniter));
// } else {
// builder.named(NamedCause.of("ProjectileSource", projectileSource));
// }
// } else if (igniter != null) {
// builder.named(NamedCause.of("Igniter", igniter));
// }
// if (PhaseTracker.ENABLED) {
// final PhaseData phaseData = PhaseTracker.getInstance().getCurrentPhaseData();
// phaseData.state.getPhase().appendExplosionCause(phaseData);
// }
// return this.createdCause = builder.build();
// }
//
// @Override
// public Cause getCreatedCause() {
// if (this.createdCause == null) {
// createCause();
// }
// return this.createdCause;
// }
/**
* @author gabizou - September 8th, 2016
* @reason Rewrites to use our own hooks that will patch with forge perfectly well,
* and allows for maximal capability.
*/
@Final
@Overwrite
public void doExplosionA() {
// Sponge Start - If the explosion should not break blocks, don't bother calculating it
if (this.shouldBreakBlocks) {
// Sponge End
Set<BlockPos> set = Sets.<BlockPos>newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
double d4 = this.x;
double d6 = this.y;
double d8 = this.z;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = this.world.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
float f2 = this.exploder != null ? this.exploder.getExplosionResistance((net.minecraft.world.Explosion) (Object) this, this.world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance((Entity) null);
f -= (f2 + 0.3F) * 0.3F;
}
if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock((net.minecraft.world.Explosion) (Object) this, this.world, blockpos, iblockstate, f))) {
set.add(blockpos);
}
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
}
}
}
}
}
this.affectedBlockPositions.addAll(set);
}
// Sponge - Finish if statement
float f3 = this.size * 2.0F;
int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D);
int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D);
int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D);
int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D);
int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D);
int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D);
// Sponge Start - Check if this explosion should damage entities
List<Entity> list = this.shouldDamageEntities ? this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1)) : Collections.emptyList();
// Now we can throw our Detonate Event
final List<Location<World>> blockPositions = new ArrayList<>(this.affectedBlockPositions.size());
final List<org.spongepowered.api.entity.Entity> entities = new ArrayList<>(list.size());
for (BlockPos pos : this.affectedBlockPositions) {
blockPositions.add(new Location<>((World) this.world, pos.getX(), pos.getY(), pos.getZ()));
}
for (Entity entity : list) {
entities.add((org.spongepowered.api.entity.Entity) entity);
}
ExplosionEvent.Detonate detonate = SpongeEventFactory.createExplosionEventDetonate(Sponge.getCauseStackManager().getCurrentCause(), blockPositions, entities, this, (World) this.world);
SpongeImpl.postEvent(detonate);
if (detonate.isCancelled()) {
this.affectedBlockPositions.clear();
return;
}
this.affectedBlockPositions.clear();
if (this.shouldBreakBlocks) {
for (Location<World> worldLocation : detonate.getAffectedLocations()) {
this.affectedBlockPositions.add(((IMixinLocation) (Object) worldLocation).getBlockPos());
}
}
list.clear();
if (this.shouldDamageEntities) {
for (org.spongepowered.api.entity.Entity entity : detonate.getEntities()) {
try {
list.add(EntityUtil.toNative(entity));
} catch (Exception e) {
// Do nothing, a plugin tried to use the wrong entity somehow.
}
}
}
// Sponge End
Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
for (int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = list.get(k2);
if (!entity.isImmuneToExplosions()) {
double d12 = entity.getDistance(this.x, this.y, this.z) / (double) f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - this.x;
double d7 = entity.posY + (double) entity.getEyeHeight() - this.y;
double d9 = entity.posZ - this.z;
double d13 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = (double) this.world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
double d10 = (1.0D - d12) * d14;
entity.attackEntityFrom(DamageSource.causeExplosionDamage((net.minecraft.world.Explosion) (Object) this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
double d11 = 1.0D;
if (entity instanceof EntityLivingBase) {
d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
}
entity.motionX += d5 * d11;
entity.motionY += d7 * d11;
entity.motionZ += d9 * d11;
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class RenderTileMaterialGrader method renderItem.
private void renderItem(World world, ItemStack stack, int rotationYaw) {
RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem();
if (StackHelper.isValid(stack)) {
// GlStateManager.translate(0.5, 0.5, 0.5);
EntityItem entityitem = new EntityItem(world, 0.0D, 0.0D, 0.0D, StackHelper.safeCopy(stack));
StackHelper.setCount(entityitem.getItem(), 1);
entityitem.hoverStart = 0.0F;
GlStateManager.pushMatrix();
GlStateManager.disableLighting();
Vec3d vec = new Vec3d(0.0, 0.0, 0.0);
GlStateManager.translate(vec.x, vec.y, vec.z);
GlStateManager.rotate(rotationYaw, 0.0F, 1.0F, 0);
GlStateManager.rotate(-90, 1.0F, 0.0F, 0);
float scale = 0.5f;
GlStateManager.scale(scale, scale, scale);
GlStateManager.pushAttrib();
RenderHelper.enableStandardItemLighting();
itemRenderer.renderItem(entityitem.getItem(), ItemCameraTransforms.TransformType.FIXED);
RenderHelper.disableStandardItemLighting();
GlStateManager.popAttrib();
GlStateManager.enableLighting();
GlStateManager.popMatrix();
}
}
use of net.minecraft.util.math.Vec3d in project SilentGems by SilentChaos512.
the class EntityChaosProjectile method setStartingVelocity.
protected void setStartingVelocity(EntityLivingBase shooter, Random random) {
Vec3d vec = shooter.getLookVec();
motionX = vec.x;
motionY = vec.y;
motionZ = vec.z;
motionX += shooter.motionX;
motionY += shooter.motionY;
motionZ += shooter.motionZ;
motionX *= SPEED_MULTI;
motionY *= SPEED_MULTI;
motionZ *= SPEED_MULTI;
}
Aggregations