mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 02:45:13 +00:00
Shave some legacy crap off Vector3, change some places to use vanilla's class instead, now that it's available on both sides
This commit is contained in:
1 parent
9269aeb73d
commit
e372f903cd
10 files changed
+63
-79
No files matched your search
@@ -31,6 +31,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
@@ -313,8 +314,8 @@ public class TileLightRelay extends TileMod implements ITickableTileEntity, IWan
|
||||
}
|
||||
remove();
|
||||
} else {
|
||||
Vector3 thisVec = Vector3.fromEntity(this);
|
||||
Vector3 motVec = thisVec.negate().add(exitPos.getX() + 0.5, exitPos.getY() + 0.5, exitPos.getZ() + 0.5).normalize().multiply(0.5);
|
||||
Vector3d thisVec = getPositionVec();
|
||||
Vector3d motVec = thisVec.inverse().add(exitPos.getX() + 0.5, exitPos.getY() + 0.5, exitPos.getZ() + 0.5).normalize().scale(0.5);
|
||||
|
||||
int color;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.state.enums.AlfPortalState;
|
||||
@@ -52,7 +53,7 @@ public class TilePylon extends TileEntity implements ITickableTileEntity {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 centerBlock = new Vector3(centerPos.getX() + 0.5, centerPos.getY() + 0.75 + (Math.random() - 0.5 * 0.25), centerPos.getZ() + 0.5);
|
||||
Vector3d centerBlock = new Vector3d(centerPos.getX() + 0.5, centerPos.getY() + 0.75 + (Math.random() - 0.5 * 0.25), centerPos.getZ() + 0.5);
|
||||
|
||||
if (variant == BlockPylon.Variant.NATURA) {
|
||||
if (ConfigHandler.CLIENT.elfPortalParticlesEnabled.get()) {
|
||||
@@ -64,9 +65,9 @@ public class TilePylon extends TileEntity implements ITickableTileEntity {
|
||||
double x = pos.getX() + 0.5 + Math.cos(worldTime) * r;
|
||||
double z = pos.getZ() + 0.5 + Math.sin(worldTime) * r;
|
||||
|
||||
Vector3 ourCoords = new Vector3(x, pos.getY() + 0.25, z);
|
||||
centerBlock = centerBlock.subtract(new Vector3(0, 0.5, 0));
|
||||
Vector3 movementVector = centerBlock.subtract(ourCoords).normalize().multiply(0.2);
|
||||
Vector3d ourCoords = new Vector3d(x, pos.getY() + 0.25, z);
|
||||
centerBlock = centerBlock.subtract(0, 0.5, 0);
|
||||
Vector3d movementVector = centerBlock.subtract(ourCoords).normalize().scale(0.2);
|
||||
|
||||
WispParticleData data = WispParticleData.wisp(0.25F + (float) Math.random() * 0.1F, (float) Math.random() * 0.25F, 0.75F + (float) Math.random() * 0.25F, (float) Math.random() * 0.25F, 1);
|
||||
world.addParticle(data, x, pos.getY() + 0.25, z, 0, -(-0.075F - (float) Math.random() * 0.015F), 0);
|
||||
@@ -76,8 +77,8 @@ public class TilePylon extends TileEntity implements ITickableTileEntity {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Vector3 ourCoords = Vector3.fromTileEntityCenter(this).add(0, 1 + (Math.random() - 0.5 * 0.25), 0);
|
||||
Vector3 movementVector = centerBlock.subtract(ourCoords).normalize().multiply(0.2);
|
||||
Vector3d ourCoords = Vector3d.func_237489_a_(getPos()).add(0, 1 + (Math.random() - 0.5 * 0.25), 0);
|
||||
Vector3d movementVector = centerBlock.subtract(ourCoords).normalize().scale(0.2);
|
||||
|
||||
Block block = world.getBlockState(pos.down()).getBlock();
|
||||
if (block instanceof BlockModFlower) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -44,6 +45,7 @@ import vazkii.botania.common.block.tile.TileExposedSimpleInventory;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
import vazkii.botania.common.core.handler.ManaNetworkHandler;
|
||||
import vazkii.botania.common.core.handler.ModSounds;
|
||||
import vazkii.botania.common.core.helper.MathHelper;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.entity.EntityManaBurst;
|
||||
import vazkii.botania.common.entity.EntityManaBurst.PositionProperties;
|
||||
@@ -640,20 +642,20 @@ public class TileSpreader extends TileExposedSimpleInventory implements IManaCol
|
||||
|
||||
@Override
|
||||
public boolean bindTo(PlayerEntity player, ItemStack wand, BlockPos pos, Direction side) {
|
||||
Vector3 thisVec = Vector3.fromTileEntityCenter(this);
|
||||
Vector3 blockVec = new Vector3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
Vector3d thisVec = Vector3d.func_237489_a_(getPos());
|
||||
Vector3d blockVec = Vector3d.func_237489_a_(pos);
|
||||
|
||||
VoxelShape shape = player.world.getBlockState(pos).getShape(player.world, pos);
|
||||
AxisAlignedBB axis = shape.isEmpty() ? new AxisAlignedBB(pos) : shape.getBoundingBox().offset(pos);
|
||||
|
||||
if (!blockVec.isInside(axis)) {
|
||||
blockVec = new Vector3(axis.minX + (axis.maxX - axis.minX) / 2, axis.minY + (axis.maxY - axis.minY) / 2, axis.minZ + (axis.maxZ - axis.minZ) / 2);
|
||||
if (!axis.contains(blockVec)) {
|
||||
blockVec = new Vector3d(axis.minX + (axis.maxX - axis.minX) / 2, axis.minY + (axis.maxY - axis.minY) / 2, axis.minZ + (axis.maxZ - axis.minZ) / 2);
|
||||
}
|
||||
|
||||
Vector3 diffVec = blockVec.subtract(thisVec);
|
||||
Vector3 diffVec2D = new Vector3(diffVec.x, diffVec.z, 0);
|
||||
Vector3 rotVec = new Vector3(0, 1, 0);
|
||||
double angle = rotVec.angle(diffVec2D) / Math.PI * 180.0;
|
||||
Vector3d diffVec = blockVec.subtract(thisVec);
|
||||
Vector3d diffVec2D = new Vector3d(diffVec.x, diffVec.z, 0);
|
||||
Vector3d rotVec = new Vector3d(0, 1, 0);
|
||||
double angle = MathHelper.angleBetween(rotVec, diffVec2D) / Math.PI * 180.0;
|
||||
|
||||
if (blockVec.x < thisVec.x) {
|
||||
angle = -angle;
|
||||
@@ -661,8 +663,8 @@ public class TileSpreader extends TileExposedSimpleInventory implements IManaCol
|
||||
|
||||
rotationX = (float) angle + 90;
|
||||
|
||||
rotVec = new Vector3(diffVec.x, 0, diffVec.z);
|
||||
angle = diffVec.angle(rotVec) * 180F / Math.PI;
|
||||
rotVec = new Vector3d(diffVec.x, 0, diffVec.z);
|
||||
angle = MathHelper.angleBetween(diffVec, rotVec) * 180F / Math.PI;
|
||||
if (blockVec.y < thisVec.y) {
|
||||
angle = -angle;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,14 @@
|
||||
package vazkii.botania.common.core.helper;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
public final class MathHelper {
|
||||
|
||||
public static double angleBetween(Vector3d a, Vector3d b) {
|
||||
return Math.acos(a.normalize().dotProduct(b.normalize()));
|
||||
}
|
||||
|
||||
public static float pointDistanceSpace(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
return (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.util.Objects;
|
||||
public class Vector3 {
|
||||
public static final Vector3 ZERO = new Vector3(0, 0, 0);
|
||||
public static final Vector3 ONE = new Vector3(1, 1, 1);
|
||||
public static final Vector3 CENTER = new Vector3(0.5, 0.5, 0.5);
|
||||
|
||||
public final double x;
|
||||
public final double y;
|
||||
@@ -48,10 +47,6 @@ public class Vector3 {
|
||||
return new Vector3(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static Vector3 fromEntity(Entity e) {
|
||||
return new Vector3(e.getPosX(), e.getPosY(), e.getPosZ());
|
||||
}
|
||||
|
||||
public static Vector3 fromEntityCenter(Entity e) {
|
||||
return new Vector3(e.getPosX(), e.getPosY() - e.getYOffset() + e.getHeight() / 2, e.getPosZ());
|
||||
}
|
||||
@@ -170,33 +165,10 @@ public class Vector3 {
|
||||
return Math.acos(normalize().dotProduct(vec.normalize()));
|
||||
}
|
||||
|
||||
public boolean isInside(AxisAlignedBB aabb) {
|
||||
return x >= aabb.minX && y >= aabb.maxY && z >= aabb.minZ && x < aabb.maxX && y < aabb.maxY && z < aabb.maxZ;
|
||||
}
|
||||
|
||||
public boolean isZero() {
|
||||
return x == 0 && y == 0 && z == 0;
|
||||
}
|
||||
|
||||
public boolean isAxial() {
|
||||
return x == 0 ? y == 0 || z == 0 : y == 0 && z == 0;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public Vector3f vector3f() {
|
||||
return new Vector3f((float) x, (float) y, (float) z);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public Vector4f vector4f() {
|
||||
return new Vector4f((float) x, (float) y, (float) z, 1);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void glVertex() {
|
||||
GL11.glVertex3d(x, y, z);
|
||||
}
|
||||
|
||||
public Vector3 negate() {
|
||||
return new Vector3(-x, -y, -z);
|
||||
}
|
||||
|
||||
@@ -126,18 +126,17 @@ public class EntityBabylonWeapon extends EntityThrowableCopy {
|
||||
if (liveTime < delay) {
|
||||
setMotion(Vector3d.ZERO);
|
||||
} else if (liveTime == delay && player != null) {
|
||||
Vector3 playerLook;
|
||||
Vector3d playerLook;
|
||||
BlockRayTraceResult rtr = ToolCommons.raytraceFromEntity(player, 64, true);
|
||||
if (rtr.getType() != RayTraceResult.Type.BLOCK) {
|
||||
playerLook = new Vector3(player.getLookVec()).multiply(64).add(Vector3.fromEntity(player));
|
||||
playerLook = player.getLookVec().scale(64).add(player.getPositionVec());
|
||||
} else {
|
||||
playerLook = new Vector3(rtr.getPos().getX() + 0.5, rtr.getPos().getY() + 0.5, rtr.getPos().getZ() + 0.5);
|
||||
playerLook = Vector3d.func_237489_a_(rtr.getPos());
|
||||
}
|
||||
|
||||
Vector3 thisVec = Vector3.fromEntityCenter(this);
|
||||
Vector3 motionVec = playerLook.subtract(thisVec).normalize().multiply(2);
|
||||
|
||||
mot = motionVec.toVector3d();
|
||||
mot = playerLook.subtract(thisVec.x, thisVec.y, thisVec.z).normalize().scale(2);
|
||||
world.playSound(null, getPosX(), getPosY(), getPosZ(), ModSounds.babylonAttack, SoundCategory.PLAYERS, 2F, 0.1F + world.rand.nextFloat() * 3F);
|
||||
}
|
||||
setLiveTicks(liveTime + 1);
|
||||
|
||||
@@ -412,10 +412,10 @@ public class EntityManaBurst extends ThrowableEntity implements IManaBurst {
|
||||
double iterY = getPosY();
|
||||
double iterZ = getPosZ();
|
||||
|
||||
Vector3 currentPos = Vector3.fromEntity(this);
|
||||
Vector3 oldPos = new Vector3(prevPosX, prevPosY, prevPosZ);
|
||||
Vector3 diffVec = oldPos.subtract(currentPos);
|
||||
Vector3 diffVecNorm = diffVec.normalize();
|
||||
Vector3d currentPos = getPositionVec();
|
||||
Vector3d oldPos = new Vector3d(prevPosX, prevPosY, prevPosZ);
|
||||
Vector3d diffVec = oldPos.subtract(currentPos);
|
||||
Vector3d diffVecNorm = diffVec.normalize();
|
||||
|
||||
double distance = 0.095;
|
||||
|
||||
@@ -436,12 +436,12 @@ public class EntityManaBurst extends ThrowableEntity implements IManaBurst {
|
||||
iterY += diffVecNorm.y * distance;
|
||||
iterZ += diffVecNorm.z * distance;
|
||||
|
||||
currentPos = new Vector3(iterX, iterY, iterZ);
|
||||
currentPos = new Vector3d(iterX, iterY, iterZ);
|
||||
diffVec = oldPos.subtract(currentPos);
|
||||
if (getPersistentData().contains(ItemTinyPlanet.TAG_ORBIT)) {
|
||||
break;
|
||||
}
|
||||
} while (Math.abs(diffVec.mag()) > distance);
|
||||
} while (Math.abs(diffVec.length()) > distance);
|
||||
|
||||
WispParticleData data = WispParticleData.wisp(0.1F * size, or, og, ob, depth);
|
||||
world.addParticle(data, iterX, iterY, iterZ, (float) (Math.random() - 0.5F) * 0.06F, (float) (Math.random() - 0.5F) * 0.06F, (float) (Math.random() - 0.5F) * 0.06F);
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.potion.Effects;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
@@ -43,14 +44,14 @@ public class ItemStarSword extends ItemManasteelSword {
|
||||
if (player.getHeldItemMainhand() == stack && player.swingProgress == check && !world.isRemote) {
|
||||
BlockRayTraceResult pos = ToolCommons.raytraceFromEntity(player, 48, false);
|
||||
if (pos.getType() == RayTraceResult.Type.BLOCK) {
|
||||
Vector3 posVec = Vector3.fromBlockPos(pos.getPos());
|
||||
Vector3 motVec = new Vector3((0.5 * Math.random() - 0.25) * 18, 24, (0.5 * Math.random() - 0.25) * 18);
|
||||
Vector3d posVec = Vector3d.func_237491_b_(pos.getPos());
|
||||
Vector3d motVec = new Vector3d((0.5 * Math.random() - 0.25) * 18, 24, (0.5 * Math.random() - 0.25) * 18);
|
||||
posVec = posVec.add(motVec);
|
||||
motVec = motVec.normalize().negate().multiply(1.5);
|
||||
motVec = motVec.normalize().inverse().scale(1.5);
|
||||
|
||||
EntityFallingStar star = new EntityFallingStar(player, world);
|
||||
star.setPosition(posVec.x, posVec.y, posVec.z);
|
||||
star.setMotion(motVec.toVector3d());
|
||||
star.setMotion(motVec);
|
||||
world.addEntity(star);
|
||||
|
||||
if (!world.isRaining()
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.entity.projectile.ThrowableEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
import vazkii.botania.api.internal.IManaBurst;
|
||||
import vazkii.botania.api.mana.IManaReceiver;
|
||||
@@ -69,17 +70,17 @@ public class LensMagnet extends Lens {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 burstVec = Vector3.fromEntity(entity);
|
||||
Vector3 tileVec = Vector3.fromTileEntityCenter(tile).add(0, -0.1, 0);
|
||||
Vector3 motionVec = new Vector3(entity.getMotion());
|
||||
Vector3d burstVec = entity.getPositionVec();
|
||||
Vector3d tileVec = Vector3d.func_237489_a_(tile.getPos()).add(0, -0.1, 0);
|
||||
Vector3d motionVec = entity.getMotion();
|
||||
|
||||
Vector3 normalMotionVec = motionVec.normalize();
|
||||
Vector3 magnetVec = tileVec.subtract(burstVec).normalize();
|
||||
Vector3 differenceVec = normalMotionVec.subtract(magnetVec).multiply(motionVec.mag() * 0.1);
|
||||
Vector3d normalMotionVec = motionVec.normalize();
|
||||
Vector3d magnetVec = tileVec.subtract(burstVec).normalize();
|
||||
Vector3d differenceVec = normalMotionVec.subtract(magnetVec).scale(motionVec.length() * 0.1);
|
||||
|
||||
Vector3 finalMotionVec = motionVec.subtract(differenceVec);
|
||||
Vector3d finalMotionVec = motionVec.subtract(differenceVec);
|
||||
if (!magnetized) {
|
||||
finalMotionVec = finalMotionVec.multiply(0.75);
|
||||
finalMotionVec = finalMotionVec.scale(0.75);
|
||||
entity.getPersistentData().putBoolean(TAG_MAGNETIZED, true);
|
||||
entity.getPersistentData().putInt(TAG_MAGNETIZED_X, tile.getPos().getX());
|
||||
entity.getPersistentData().putInt(TAG_MAGNETIZED_Y, tile.getPos().getY());
|
||||
|
||||
@@ -16,10 +16,12 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
import vazkii.botania.api.internal.IManaBurst;
|
||||
import vazkii.botania.api.mana.IDirectioned;
|
||||
import vazkii.botania.api.mana.IThrottledPacket;
|
||||
import vazkii.botania.common.core.helper.MathHelper;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
|
||||
public class LensRedirect extends Lens {
|
||||
@@ -34,8 +36,8 @@ public class LensRedirect extends Lens {
|
||||
if (tile instanceof IDirectioned) {
|
||||
if (!burst.isFake()) {
|
||||
IDirectioned redir = (IDirectioned) tile;
|
||||
Vector3 tileVec = Vector3.fromTileEntityCenter(tile);
|
||||
Vector3 sourceVec = new Vector3(coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5);
|
||||
Vector3d tileVec = Vector3d.func_237489_a_(tile.getPos());
|
||||
Vector3d sourceVec = Vector3d.func_237489_a_(coords);
|
||||
|
||||
AxisAlignedBB axis;
|
||||
VoxelShape collideShape = entity.world.getBlockState(coords).getCollisionShape(entity.world, coords);
|
||||
@@ -45,14 +47,14 @@ public class LensRedirect extends Lens {
|
||||
axis = collideShape.getBoundingBox().offset(coords); // todo 1.13 more granular collisions?
|
||||
}
|
||||
|
||||
if (!sourceVec.isInside(axis)) {
|
||||
sourceVec = new Vector3(axis.minX + (axis.maxX - axis.minX) / 2, axis.minY + (axis.maxY - axis.minY) / 2, axis.minZ + (axis.maxZ - axis.minZ) / 2);
|
||||
if (!axis.contains(sourceVec)) {
|
||||
sourceVec = new Vector3d(axis.minX + (axis.maxX - axis.minX) / 2, axis.minY + (axis.maxY - axis.minY) / 2, axis.minZ + (axis.maxZ - axis.minZ) / 2);
|
||||
}
|
||||
|
||||
Vector3 diffVec = sourceVec.subtract(tileVec);
|
||||
Vector3 diffVec2D = new Vector3(diffVec.x, diffVec.z, 0);
|
||||
Vector3 rotVec = new Vector3(0, 1, 0);
|
||||
double angle = rotVec.angle(diffVec2D) / Math.PI * 180.0;
|
||||
Vector3d diffVec = sourceVec.subtract(tileVec);
|
||||
Vector3d diffVec2D = new Vector3d(diffVec.x, diffVec.z, 0);
|
||||
Vector3d rotVec = new Vector3d(0, 1, 0);
|
||||
double angle = MathHelper.angleBetween(rotVec, diffVec2D) / Math.PI * 180.0;
|
||||
|
||||
if (sourceVec.x < tileVec.x) {
|
||||
angle = -angle;
|
||||
@@ -60,8 +62,8 @@ public class LensRedirect extends Lens {
|
||||
|
||||
redir.setRotationX((float) angle + 90F);
|
||||
|
||||
rotVec = new Vector3(diffVec.x, 0, diffVec.z);
|
||||
angle = diffVec.angle(rotVec) * 180F / Math.PI;
|
||||
rotVec = new Vector3d(diffVec.x, 0, diffVec.z);
|
||||
angle = MathHelper.angleBetween(diffVec, rotVec) * 180F / Math.PI;
|
||||
if (sourceVec.y < tileVec.y) {
|
||||
angle = -angle;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user