use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onDrawBlockHighlightEventFirst.
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onDrawBlockHighlightEventFirst(DrawBlockHighlightEvent event) {
GL11.glPushMatrix();
BlockPos pos = Minecraft.getMinecraft().objectMouseOver.getBlockPos();
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, pos);
if (physicsObject.isPresent()) {
RayTraceResult objectOver = Minecraft.getMinecraft().objectMouseOver;
if (objectOver != null && objectOver.hitVec != null) {
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
oldXOff = buffer.xOffset;
oldYOff = buffer.yOffset;
oldZOff = buffer.zOffset;
buffer.setTranslation(-physicsObject.get().getShipRenderer().offsetPos.getX(), -physicsObject.get().getShipRenderer().offsetPos.getY(), -physicsObject.get().getShipRenderer().offsetPos.getZ());
physicsObject.get().getShipRenderer().applyRenderTransform(event.getPartialTicks());
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BlockCaptainsChair method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(worldIn, pos);
if (physicsObject.isPresent()) {
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileEntityCaptainsChair) {
Vector3d playerPos = new Vector3d(playerIn.posX, playerIn.posY, playerIn.posZ);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.SUBSPACE_TO_GLOBAL);
playerIn.posX = playerPos.x;
playerIn.posY = playerPos.y;
playerIn.posZ = playerPos.z;
// Only mount the player if they're standing on the ship.
final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(playerIn);
if (entityShipMovementData.getTicksSinceTouchedShip() == 0 && (entityShipMovementData.getLastTouchedShip() == physicsObject.get().getShipData())) {
Vector3dc localMountPos = getPlayerMountOffset(state, pos);
ValkyrienUtils.fixEntityToShip(playerIn, localMountPos, physicsObject.get());
}
((TileEntityCaptainsChair) tileEntity).setPilotEntity(playerIn);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(playerPos, TransformType.GLOBAL_TO_SUBSPACE);
playerIn.posX = playerPos.x;
playerIn.posY = playerPos.y;
playerIn.posZ = playerPos.z;
}
}
}
return true;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method spawnParticle.
/**
* This is easier to have as an overwrite because there's less laggy hackery to be done then :P
*
* @author DaPorkchop_
*/
@Overwrite
public void spawnParticle(int particleID, boolean ignoreRange, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, int... parameters) {
BlockPos pos = new BlockPos(x, y, z);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
if (physicsObject.isPresent()) {
Vector3d newPosVec = new Vector3d(x, y, z);
// RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform,
// newPosVec);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(newPosVec, TransformType.SUBSPACE_TO_GLOBAL);
x = newPosVec.x;
y = newPosVec.y;
z = newPosVec.z;
}
for (int i = 0; i < this.eventListeners.size(); ++i) {
this.eventListeners.get(i).spawnParticle(particleID, ignoreRange, x, y, z, xSpeed, ySpeed, zSpeed, parameters);
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method preGetCollisionBoxes.
/**
* Used for two purposes. The first, is to prevent the game from freezing by limiting the size of aabb. The second
* is to fix player sneaking on ships.
*/
@Inject(method = "getCollisionBoxes(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/AxisAlignedBB;ZLjava/util/List;)Z", at = @At("HEAD"), cancellable = true)
private void preGetCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb, boolean p_191504_3_, @Nullable List<AxisAlignedBB> outList, CallbackInfoReturnable<Boolean> callbackInfo) {
double deltaX = Math.abs(aabb.maxX - aabb.minX);
double deltaY = Math.abs(aabb.maxY - aabb.minY);
double deltaZ = Math.abs(aabb.maxZ - aabb.minZ);
if (Math.max(deltaX, Math.max(deltaY, deltaZ)) > 99999D) {
System.err.println(entityIn + "\ntried going extremely fast during the collision step");
new Exception().printStackTrace();
callbackInfo.setReturnValue(Boolean.FALSE);
callbackInfo.cancel();
}
// direction, and uses that to determine if can you sneak.
if (entityIn instanceof EntityPlayer && entityIn.isSneaking()) {
// Add at most once ship block AABB that is colliding with the player. This is ONLY to properly allow
// players to sneak while on ships.
List<PhysicsObject> ships = getManager().getPhysObjectsInAABB(aabb);
for (PhysicsObject wrapper : ships) {
Polygon playerInLocal = new Polygon(aabb, wrapper.getShipTransformationManager().getCurrentTickTransform(), TransformType.GLOBAL_TO_SUBSPACE);
AxisAlignedBB bb = playerInLocal.getEnclosedAABB();
if ((bb.maxX - bb.minX) * (bb.maxZ - bb.minZ) > 9898989) {
// This is too big, something went wrong here
System.err.println("Why did transforming a players bounding box result in a giant bounding box?");
System.err.println(bb + "\n" + wrapper.getShipData() + "\n" + entityIn.toString());
new Exception().printStackTrace();
return;
}
List<AxisAlignedBB> collidingBBs = getCollisionBoxes(null, bb);
Polygon entityPoly = new Polygon(aabb.grow(-.2, 0, -.2));
for (AxisAlignedBB inLocal : collidingBBs) {
ShipPolygon poly = new ShipPolygon(inLocal, wrapper.getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL, wrapper.getShipTransformationManager().normals, wrapper);
EntityPolygonCollider collider = new EntityPolygonCollider(entityPoly, poly, poly.normals, new Vector3d());
collider.processData();
if (!collider.arePolygonsSeparated()) {
outList.add(inLocal);
// vanilla sneak code will work correctly.
return;
}
}
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method getEntitiesInAABBexcluding.
/**
* aa
*
* @author xd
*/
@Overwrite
public List<Entity> getEntitiesInAABBexcluding(@Nullable Entity entityIn, AxisAlignedBB boundingBox, @Nullable Predicate<? super Entity> predicate) {
if (isBoundingBoxTooLarge(boundingBox)) {
new Exception("Tried getting entities from giant bounding box of " + boundingBox).printStackTrace();
return new ArrayList<>();
}
List<Entity> toReturn = this.getEntitiesInAABBexcludingOriginal(entityIn, boundingBox, predicate);
BlockPos pos = new BlockPos((boundingBox.minX + boundingBox.maxX) / 2D, (boundingBox.minY + boundingBox.maxY) / 2D, (boundingBox.minZ + boundingBox.maxZ) / 2D);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
if (physicsObject.isPresent()) {
Polygon poly = new Polygon(boundingBox, physicsObject.get().getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL);
boundingBox = poly.getEnclosedAABB().shrink(.3D);
if (isBoundingBoxTooLarge(boundingBox)) {
new Exception("Tried getting entities from giant bounding box of " + boundingBox).printStackTrace();
return new ArrayList<>();
}
toReturn.addAll(this.getEntitiesInAABBexcludingOriginal(entityIn, boundingBox, predicate));
}
return toReturn;
}
Aggregations