Search in sources :

Example 26 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ValkyrienUtils method getMountedShipAndPos.

public EntityShipMountData getMountedShipAndPos(Entity entity) {
    Entity ridingEntity = entity.ridingEntity;
    if (ridingEntity instanceof EntityMountable) {
        EntityMountable mountable = (EntityMountable) ridingEntity;
        Optional<PhysicsObject> mountedShip = mountable.getMountedShip();
        if (mountedShip.isPresent()) {
            return new EntityShipMountData(mountedShip.get(), mountable.getMountPos());
        }
    }
    return new EntityShipMountData();
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) EntityMountable(org.valkyrienskies.mod.common.entity.EntityMountable) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 27 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSWorldPhysicsLoop method tickThePhysicsAndCollision.

/**
 * Ticks physics and collision for the List of PhysicsWrapperEntity passed in.
 */
private void tickThePhysicsAndCollision(List<PhysicsObject> shipsWithPhysics, double timeStep) {
    final List<ShipCollisionTask> collisionTasks = new ArrayList<>(shipsWithPhysics.size() * 2);
    final List<WaterForcesTask> waterForcesTasks = new ArrayList<>();
    for (PhysicsObject wrapper : shipsWithPhysics) {
        // Update the physics simulation
        try {
            wrapper.getPhysicsCalculations().rawPhysTickPreCol(timeStep);
            // Do water collision and buoyancy
            wrapper.getPhysicsCalculations().getWorldWaterCollider().tickUpdatingTheCollisionCache();
            // Add water forces tasks to be processed in parallel
            waterForcesTasks.addAll(wrapper.getPhysicsCalculations().getWorldWaterCollider().generateWaterForceTasks());
            // Update the collision task if necessary
            wrapper.getPhysicsCalculations().getWorldCollision().tickUpdatingTheCollisionCache();
            // Take the big collision and split into tiny ones
            wrapper.getPhysicsCalculations().getWorldCollision().splitIntoCollisionTasks(collisionTasks);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    final List<Callable<Void>> allTasks = new ArrayList<>();
    allTasks.addAll(collisionTasks);
    allTasks.addAll(waterForcesTasks);
    try {
        // Run all the block collision and water physics tasks
        ValkyrienSkiesMod.getPhysicsThreadPool().invokeAll(allTasks);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Handle the results of water force tasks
    for (final WaterForcesTask waterForcesTask : waterForcesTasks) {
        waterForcesTask.addForcesToShip();
    }
    // this thread. Thankfully this step is not cpu intensive.
    for (ShipCollisionTask task : collisionTasks) {
        task.getToTask().processCollisionTask(task);
    }
    for (PhysicsObject wrapper : shipsWithPhysics) {
        try {
            wrapper.getPhysicsCalculations().rawPhysTickPostCol();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ShipCollisionTask(org.valkyrienskies.mod.common.collision.ShipCollisionTask) WaterForcesTask(org.valkyrienskies.mod.common.collision.WaterForcesTask) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Callable(java.util.concurrent.Callable)

Example 28 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinRenderGlobal method drawBlockDamageTexture.

/**
 * aa
 *
 * @author xd
 */
@Overwrite
public void drawBlockDamageTexture(Tessellator tessellatorIn, BufferBuilder worldRendererIn, Entity entityIn, float partialTicks) {
    double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * partialTicks;
    double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * partialTicks;
    double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * partialTicks;
    if (!this.damagedBlocks.isEmpty()) {
        this.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        this.preRenderDamagedBlocks();
        worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
        worldRendererIn.setTranslation(-d0, -d1, -d2);
        worldRendererIn.noColor();
        Iterator<DestroyBlockProgress> iterator = this.damagedBlocks.values().iterator();
        while (iterator.hasNext()) {
            DestroyBlockProgress destroyblockprogress = iterator.next();
            BlockPos blockpos = destroyblockprogress.getPosition();
            double d3 = blockpos.getX() - d0;
            double d4 = blockpos.getY() - d1;
            double d5 = blockpos.getZ() - d2;
            Block block = this.world.getBlockState(blockpos).getBlock();
            TileEntity te = this.world.getTileEntity(blockpos);
            boolean hasBreak = block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockSign || block instanceof BlockSkull;
            if (!hasBreak) {
                hasBreak = te != null && te.canRenderBreaking();
            }
            if (!hasBreak) {
                Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, blockpos);
                if (!physicsObject.isPresent() && (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D)) {
                    iterator.remove();
                } else {
                    IBlockState iblockstate = this.world.getBlockState(blockpos);
                    if (physicsObject.isPresent()) {
                        physicsObject.get().getShipRenderer().applyRenderTransform(partialTicks);
                        worldRendererIn.setTranslation(-physicsObject.get().getShipRenderer().offsetPos.getX(), -physicsObject.get().getShipRenderer().offsetPos.getY(), -physicsObject.get().getShipRenderer().offsetPos.getZ());
                    }
                    if (iblockstate.getMaterial() != Material.AIR) {
                        int i = destroyblockprogress.getPartialBlockDamage();
                        TextureAtlasSprite textureatlassprite = this.destroyBlockIcons[i];
                        BlockRendererDispatcher blockrendererdispatcher = this.mc.getBlockRendererDispatcher();
                        try {
                            blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, this.world);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    worldRendererIn.setTranslation(-d0, -d1, -d2);
                    // TODO: Reverse the Matrix Transforms here
                    if (physicsObject.isPresent()) {
                        tessellatorIn.draw();
                        worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
                        physicsObject.get().getShipRenderer().applyInverseTransform(partialTicks);
                    }
                }
            }
        }
        tessellatorIn.draw();
        worldRendererIn.setTranslation(0.0D, 0.0D, 0.0D);
        this.postRenderDamagedBlocks();
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 29 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinWorldClient method vs_showBarrierParticles.

private void vs_showBarrierParticles(int x, int y, int z, int offset, Random random, boolean holdingBarrier, BlockPos.MutableBlockPos pos, final List<PhysicsObject> nearbyShipObjects, final Vector3d temp0) {
    final int i = x + random.nextInt(offset) - random.nextInt(offset);
    final int j = y + random.nextInt(offset) - random.nextInt(offset);
    final int k = z + random.nextInt(offset) - random.nextInt(offset);
    pos.setPos(i, j, k);
    vs_displayTickPos(pos, holdingBarrier, random);
    for (final PhysicsObject physicsObject : nearbyShipObjects) {
        if (!aabbContains(physicsObject.getShipBB(), i, j, k)) {
            continue;
        }
        final Vector3dc posInShip = physicsObject.getShipTransformationManager().getRenderTransform().transformPositionNew(temp0.set(i + .5, j + .5, k + .5), TransformType.GLOBAL_TO_SUBSPACE);
        final double randomXOffset = random.nextDouble();
        final double randomYOffset = random.nextDouble();
        final double randomZOffset = random.nextDouble();
        pos.setPos(posInShip.x() + randomXOffset, posInShip.y() + randomYOffset, posInShip.z() + randomZOffset);
        vs_displayTickPos(pos, holdingBarrier, random);
    }
}
Also used : Vector3dc(org.joml.Vector3dc) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 30 with PhysicsObject

use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinWorldClient method doVoidFogParticles.

/**
 * Adds torch particles to ships.
 * @author Tri0de
 */
@Overwrite
public void doVoidFogParticles(int posX, int posY, int posZ) {
    final int i = 32;
    final Random random = ThreadLocalRandom.current();
    ItemStack itemstack = this.mc.player.getHeldItemMainhand();
    boolean flag = this.mc.playerController.getCurrentGameType() == GameType.CREATIVE && !itemstack.isEmpty() && itemstack.getItem() == Item.getItemFromBlock(Blocks.BARRIER);
    BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
    final AxisAlignedBB shipDetectionBB = new AxisAlignedBB(posX - i, posY - i, posZ - i, posX + i, posY + i, posZ + i);
    final List<PhysicsObject> nearbyShipObjects = ValkyrienUtils.getPhysObjWorld(thisAsWorldClient).getPhysObjectsInAABB(shipDetectionBB);
    final Vector3d temp0 = new Vector3d();
    for (int j = 0; j < 667; ++j) {
        this.vs_showBarrierParticles(posX, posY, posZ, 16, random, flag, blockpos$mutableblockpos, nearbyShipObjects, temp0);
        this.vs_showBarrierParticles(posX, posY, posZ, 32, random, flag, blockpos$mutableblockpos, nearbyShipObjects, temp0);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)54 World (net.minecraft.world.World)21 Vector3d (org.joml.Vector3d)21 BlockPos (net.minecraft.util.math.BlockPos)20 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)10 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)10 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 Vector3dc (org.joml.Vector3dc)9 TileEntity (net.minecraft.tileentity.TileEntity)8 Inject (org.spongepowered.asm.mixin.injection.Inject)8 Polygon (org.valkyrienskies.mod.common.collision.Polygon)8 ShipPolygon (org.valkyrienskies.mod.common.collision.ShipPolygon)8 Entity (net.minecraft.entity.Entity)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 IBlockState (net.minecraft.block.state.IBlockState)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 ArrayList (java.util.ArrayList)4 IThreadListener (net.minecraft.util.IThreadListener)4 Vec3d (net.minecraft.util.math.Vec3d)4