use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunnerClient method onOrientCamera.
public static void onOrientCamera(EntityRenderer renderer, float partialTicks) {
Entity entity = renderer.mc.getRenderViewEntity();
BlockPos playerPos = new BlockPos(entity);
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(entity.worldObj, playerPos);
if (wrapper != null) {
Vector playerPosNew = new Vector(entity.posX, entity.posY, entity.posZ);
RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, playerPosNew);
entity.posX = entity.prevPosX = entity.lastTickPosX = playerPosNew.X;
entity.posY = entity.prevPosY = entity.lastTickPosY = playerPosNew.Y;
entity.posZ = entity.prevPosZ = entity.lastTickPosZ = playerPosNew.Z;
}
Vector eyeVector = new Vector(0, entity.getEyeHeight(), 0);
if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
eyeVector.Y += .7D;
}
double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks;
double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks;
double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks;
PhysicsWrapperEntity fixedOnto = ValkyrienWarfareMod.physicsManager.getShipFixedOnto(entity);
//Probably overkill, but this should 100% fix the crash in issue #78
if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
double[] radians = orientationQuat.toRadians();
float moddedPitch = (float) Math.toDegrees(radians[0]);
float moddedYaw = (float) Math.toDegrees(radians[1]);
float moddedRoll = (float) Math.toDegrees(radians[2]);
double[] orientationMatrix = RotationMatrices.getRotationMatrix(moddedPitch, moddedYaw, moddedRoll);
RotationMatrices.applyTransform(orientationMatrix, eyeVector);
Vector playerPosition = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
RotationMatrices.applyTransform(fixedOnto.wrapping.coordTransform.RlToWTransform, playerPosition);
d0 = playerPosition.X;
d1 = playerPosition.Y;
d2 = playerPosition.Z;
// entity.posX = entity.prevPosX = entity.lastTickPosX = d0;
// entity.posY = entity.prevPosY = entity.lastTickPosY = d1;
// entity.posZ = entity.prevPosZ = entity.lastTickPosZ = d2;
}
d0 += eyeVector.X;
d1 += eyeVector.Y;
d2 += eyeVector.Z;
if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
if (!renderer.mc.gameSettings.debugCamEnable) {
//VW code starts here
if (fixedOnto != null) {
Vector playerPosInLocal = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
playerPosInLocal.subtract(.5D, .6875, .5);
playerPosInLocal.roundToWhole();
BlockPos bedPos = new BlockPos(playerPosInLocal.X, playerPosInLocal.Y, playerPosInLocal.Z);
IBlockState state = renderer.mc.theWorld.getBlockState(bedPos);
Block block = state.getBlock();
float angleYaw = 0;
if (block != null && block.isBed(state, entity.worldObj, bedPos, entity)) {
angleYaw = (float) (block.getBedDirection(state, entity.worldObj, bedPos).getHorizontalIndex() * 90);
angleYaw += 180;
}
entity.rotationYaw = entity.prevRotationYaw = angleYaw;
entity.rotationPitch = entity.prevRotationPitch = 0;
} else {
BlockPos blockpos = new BlockPos(entity);
IBlockState iblockstate = renderer.mc.theWorld.getBlockState(blockpos);
net.minecraftforge.client.ForgeHooksClient.orientBedCamera(renderer.mc.theWorld, blockpos, iblockstate, entity);
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
}
}
} else if (renderer.mc.gameSettings.thirdPersonView > 0) {
double d3 = (double) (renderer.thirdPersonDistancePrev + (4.0F - renderer.thirdPersonDistancePrev) * partialTicks);
if (ClientPilotingManager.isPlayerPilotingShip()) {
//TODO: Make this number scale with the Ship
d3 = 15D;
}
if (renderer.mc.gameSettings.debugCamEnable) {
GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
} else {
float f1 = entity.rotationYaw;
float f2 = entity.rotationPitch;
if (renderer.mc.gameSettings.thirdPersonView == 2) {
f2 += 180.0F;
}
double d4 = (double) (-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
double d5 = (double) (MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
double d6 = (double) (-MathHelper.sin(f2 * 0.017453292F)) * d3;
for (int i = 0; i < 8; ++i) {
float f3 = (float) ((i & 1) * 2 - 1);
float f4 = (float) ((i >> 1 & 1) * 2 - 1);
float f5 = (float) ((i >> 2 & 1) * 2 - 1);
f3 = f3 * 0.1F;
f4 = f4 * 0.1F;
f5 = f5 * 0.1F;
RayTraceResult raytraceresult = CallRunnerClient.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().theWorld, new Vec3d(d0 + (double) f3, d1 + (double) f4, d2 + (double) f5), new Vec3d(d0 - d4 + (double) f3 + (double) f5, d1 - d6 + (double) f4, d2 - d5 + (double) f5), false, false, false, ClientPilotingManager.getPilotedWrapperEntity());
if (raytraceresult != null) {
double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
if (d7 < d3) {
d3 = d7;
}
}
}
if (renderer.mc.gameSettings.thirdPersonView == 2) {
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
}
GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
}
} else {
GlStateManager.translate(0.0F, 0.0F, 0.05F);
}
if (!renderer.mc.gameSettings.debugCamEnable) {
float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
float roll = 0.0F;
if (entity instanceof EntityAnimal) {
EntityAnimal entityanimal = (EntityAnimal) entity;
yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
}
IBlockState state = ActiveRenderInfo.getBlockStateAtEntityViewpoint(renderer.mc.theWorld, entity, partialTicks);
net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(renderer, entity, state, partialTicks, yaw, pitch, roll);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
GlStateManager.rotate(event.getRoll(), 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(event.getPitch(), 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(event.getYaw(), 0.0F, 1.0F, 0.0F);
}
if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
double[] radians = orientationQuat.toRadians();
float moddedPitch = (float) Math.toDegrees(radians[0]);
float moddedYaw = (float) Math.toDegrees(radians[1]);
float moddedRoll = (float) Math.toDegrees(radians[2]);
GlStateManager.rotate(-moddedRoll, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(-moddedYaw, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(-moddedPitch, 1.0F, 0.0F, 0.0F);
}
GlStateManager.translate(-eyeVector.X, -eyeVector.Y, -eyeVector.Z);
d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks + eyeVector.X;
d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks + eyeVector.Y;
d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks + eyeVector.Z;
renderer.cloudFog = renderer.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunnerClient method onGetCombinedLight.
// TODO: This may become a performance issue
public static int onGetCombinedLight(World world, BlockPos pos, int lightValue) {
try {
int i = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, pos);
int j = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, pos);
AxisAlignedBB lightBB = new AxisAlignedBB(pos.getX() - 2, pos.getY() - 2, pos.getZ() - 2, pos.getX() + 2, pos.getY() + 2, pos.getZ() + 2);
List<PhysicsWrapperEntity> physEnts = ValkyrienWarfareMod.physicsManager.getManagerForWorld(world).getNearbyPhysObjects(lightBB);
for (PhysicsWrapperEntity physEnt : physEnts) {
BlockPos posInLocal = RotationMatrices.applyTransform(physEnt.wrapping.coordTransform.wToLTransform, pos);
int localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal);
int localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal);
if (localI == 0 && localJ == 0) {
localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal.up());
localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal.up());
}
if (localI == 0 && localJ == 0) {
localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal.down());
localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal.down());
}
if (localI == 0 && localJ == 0) {
localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal.north());
localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal.north());
}
if (localI == 0 && localJ == 0) {
localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal.south());
localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal.south());
}
if (localI == 0 && localJ == 0) {
localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal.east());
localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal.east());
}
if (localI == 0 && localJ == 0) {
localI = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, posInLocal.west());
localJ = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, posInLocal.west());
}
i = Math.min(localI, i);
j = Math.max(localJ, j);
}
if (j < lightValue) {
j = lightValue;
}
return i << 20 | j << 4;
} catch (Exception e) {
System.err.println("Something just went wrong here!!!!");
e.printStackTrace();
try {
return world.getCombinedLight(pos, lightValue);
} catch (Exception ee) {
ee.printStackTrace();
return 0;
}
}
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class CallRunnerClient method onDrawBlockDamageTexture.
public static void onDrawBlockDamageTexture(RenderGlobal renderGlobal, Tessellator tessellatorIn, VertexBuffer worldRendererIn, Entity entityIn, float partialTicks) {
double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double) partialTicks;
double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double) partialTicks;
double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double) partialTicks;
if (!renderGlobal.damagedBlocks.isEmpty()) {
renderGlobal.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
renderGlobal.preRenderDamagedBlocks();
worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
worldRendererIn.setTranslation(-d0, -d1, -d2);
worldRendererIn.noColor();
Iterator<DestroyBlockProgress> iterator = renderGlobal.damagedBlocks.values().iterator();
while (iterator.hasNext()) {
DestroyBlockProgress destroyblockprogress = (DestroyBlockProgress) iterator.next();
BlockPos blockpos = destroyblockprogress.getPosition();
double d3 = (double) blockpos.getX() - d0;
double d4 = (double) blockpos.getY() - d1;
double d5 = (double) blockpos.getZ() - d2;
Block block = renderGlobal.theWorld.getBlockState(blockpos).getBlock();
TileEntity te = renderGlobal.theWorld.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) {
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(renderGlobal.theWorld, blockpos);
if (wrapper == null && (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D)) {
iterator.remove();
} else {
IBlockState iblockstate = renderGlobal.theWorld.getBlockState(blockpos);
if (wrapper != null) {
wrapper.wrapping.renderer.setupTranslation(partialTicks);
worldRendererIn.setTranslation(-wrapper.wrapping.renderer.offsetPos.getX(), -wrapper.wrapping.renderer.offsetPos.getY(), -wrapper.wrapping.renderer.offsetPos.getZ());
}
if (iblockstate.getMaterial() != Material.AIR) {
int i = destroyblockprogress.getPartialBlockDamage();
TextureAtlasSprite textureatlassprite = renderGlobal.destroyBlockIcons[i];
BlockRendererDispatcher blockrendererdispatcher = renderGlobal.mc.getBlockRendererDispatcher();
try {
blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, renderGlobal.theWorld);
} catch (Exception e) {
e.printStackTrace();
}
}
worldRendererIn.setTranslation(-d0, -d1, -d2);
// TODO: Reverse the Matrix Transforms here
if (wrapper != null) {
tessellatorIn.draw();
worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
wrapper.wrapping.renderer.inverseTransform(partialTicks);
}
}
}
}
tessellatorIn.draw();
worldRendererIn.setTranslation(0.0D, 0.0D, 0.0D);
renderGlobal.postRenderDamagedBlocks();
}
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsClient method onClientTickEvent.
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onClientTickEvent(ClientTickEvent event) {
if (mc.theWorld != null) {
if (!mc.isGamePaused()) {
WorldPhysObjectManager manager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(mc.theWorld);
if (event.phase == Phase.END) {
for (PhysicsWrapperEntity wrapper : manager.physicsEntities) {
wrapper.wrapping.onPostTickClient();
}
EntityDraggable.tickAddedVelocityForWorld(mc.theWorld);
}
}
if (event.phase == Phase.END) {
Object o = Minecraft.getMinecraft().thePlayer;
EntityDraggable draggable = (EntityDraggable) o;
if (draggable.worldBelowFeet != null) {
PlayerShipRefrenceMessage playerPosMessage = new PlayerShipRefrenceMessage(Minecraft.getMinecraft().thePlayer, draggable.worldBelowFeet);
ValkyrienWarfareMod.physWrapperNetwork.sendToServer(playerPosMessage);
}
}
}
}
use of ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EventsCommon method onPlayerSleepInBedEvent.
@SubscribeEvent()
public void onPlayerSleepInBedEvent(PlayerSleepInBedEvent event) {
EntityPlayer player = event.getEntityPlayer();
BlockPos pos = event.getPos();
PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(player.worldObj, pos);
if (wrapper != null) {
if (player instanceof EntityPlayerMP) {
EntityPlayerMP playerMP = (EntityPlayerMP) player;
player.addChatMessage(new TextComponentString("Spawn Point Set!"));
player.setSpawnPoint(pos, true);
event.setResult(SleepResult.NOT_POSSIBLE_HERE);
}
}
}
Aggregations