use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.
the class ServerWorldEventMixin method playSound.
/**
* @author RyanHCode
*/
@Overwrite(remap = false)
public void playSound(@Nullable PlayerEntity pPlayer, double pX, double pY, double pZ, SoundEvent pSound, SoundCategory pCategory, float pVolume, float pPitch) {
if (((Object) this) instanceof ServerWorld && ((ServerWorld) (Object) this).dimension() == AirshipDimensionManager.WORLD_ID) {
// get position of entity
Vector3d pos = new Vector3d(pX, pY, pZ);
BlockPos bPos = new BlockPos(pos);
// get airship plot id
int id = AirshipManager.getIdFromPlotPos(bPos);
BlockPos plotPos = AirshipManager.getPlotPosFromId(id);
// get airship
AirshipContraptionEntity airship = AirshipManager.INSTANCE.AllAirships.get(id);
if (airship != null) {
Vector3d position = new Vector3d(bPos.getX(), bPos.getY(), bPos.getZ());
position = position.subtract(plotPos.getX(), plotPos.getY(), plotPos.getZ());
position = airship.toGlobalVector(position, 1.0f);
airship.level.playSound(pPlayer, position.x, position.y, position.z, pSound, pCategory, pVolume, pPitch);
return;
}
}
net.minecraftforge.event.entity.PlaySoundAtEntityEvent event = net.minecraftforge.event.ForgeEventFactory.onPlaySoundAtEntity(pPlayer, pSound, pCategory, pVolume, pPitch);
if (event.isCanceled() || event.getSound() == null)
return;
pSound = event.getSound();
pCategory = event.getCategory();
pVolume = event.getVolume();
server.getPlayerList().broadcast(pPlayer, pX, pY, pZ, pVolume > 1.0F ? (double) (16.0F * pVolume) : 16.0D, ((ServerWorld) (Object) this).dimension(), new SPlaySoundEffectPacket(pSound, pCategory, pX, pY, pZ, pVolume, pPitch));
}
use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.
the class ServerWorldEventMixin method sendParticles.
/**
* @author RyanHCode
*/
@Overwrite(remap = false)
private boolean sendParticles(ServerPlayerEntity pPlayer, boolean pLongDistance, double pPosX, double pPosY, double pPosZ, IPacket<?> pPacket) {
if (pPlayer.getLevel() != ((ServerWorld) (Object) this)) {
if (((Object) this) instanceof ServerWorld && ((ServerWorld) (Object) this).dimension() == AirshipDimensionManager.WORLD_ID) {
// get position of entity
Vector3d pos = new Vector3d(pPosX, pPosY, pPosZ);
BlockPos bPos = new BlockPos(pos);
// get airship plot id
int id = AirshipManager.getIdFromPlotPos(bPos);
BlockPos plotPos = AirshipManager.getPlotPosFromId(id);
// get airship
AirshipContraptionEntity airship = AirshipManager.INSTANCE.AllAirships.get(id);
if (airship != null) {
Vector3d position = new Vector3d(bPos.getX(), bPos.getY(), bPos.getZ());
position = position.subtract(plotPos.getX(), plotPos.getY(), plotPos.getZ());
position = airship.toGlobalVector(position, 1.0f);
BlockPos blockpos = pPlayer.blockPosition();
SSpawnParticlePacket newPacket = null;
if (pPacket instanceof SSpawnParticlePacket) {
SSpawnParticlePacket spawnPacket = (SSpawnParticlePacket) pPacket;
newPacket = new SSpawnParticlePacket(spawnPacket.getParticle(), pLongDistance, position.x, position.y, position.z, spawnPacket.getXDist(), spawnPacket.getYDist(), spawnPacket.getZDist(), spawnPacket.getMaxSpeed(), spawnPacket.getCount());
}
if (blockpos.closerThan(position, pLongDistance ? 512.0D : 32.0D)) {
pPlayer.connection.send(newPacket != null ? newPacket : pPacket);
return true;
} else {
return false;
}
}
}
return false;
} else {
BlockPos blockpos = pPlayer.blockPosition();
if (blockpos.closerThan(new Vector3d(pPosX, pPosY, pPosZ), pLongDistance ? 512.0D : 32.0D)) {
pPlayer.connection.send(pPacket);
return true;
} else {
return false;
}
}
}
use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.
the class RenderEvents method renderList.
/**
* Renders block outline for contraptions
*/
/*public static void drawLine(VertexConsumer consumer, Matrix4f matrix, Vector3d vecA, Vector3d vecB, Vector3d normal, int r, int g, int b, int a)
{
consumer.vertex(matrix, (float)vecA.x, (float)vecA.y, (float)vecA.z).color(r, g, b, a).normal((float) normal.x, (float) normal.y, (float) normal.z).endVertex();
consumer.vertex(matrix, (float)vecB.x, (float)vecB.y, (float)vecB.z).color(r, g, b, a).normal((float) normal.x, (float) normal.y, (float) normal.z).endVertex();
}*/
@SubscribeEvent
public static void renderList(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getInstance();
mc.getProfiler().push("renderVehicleDebug");
ClientPlayerEntity player = mc.player;
if (player == null)
return;
Vector3d origin = RaycastHelper.getTraceOrigin(mc.player);
double reach = mc.gameMode.getPickRange();
if (mc.hitResult != null && mc.hitResult.getLocation() != null)
reach = Math.max(mc.hitResult.getLocation().distanceTo(origin), reach);
Vector3d target = RaycastHelper.getTraceTarget(mc.player, reach, origin);
for (AirshipContraptionEntity contraptionEntity : mc.level.getEntitiesOfClass(AirshipContraptionEntity.class, new AxisAlignedBB(origin, target))) {
Vector3d localOrigin = contraptionEntity.toLocalVector(origin, 1);
Vector3d localTarget = contraptionEntity.toLocalVector(target, 1);
Contraption contraption = contraptionEntity.getContraption();
MutableObject<BlockRayTraceResult> mutableResult = new MutableObject<>();
AtomicReference<VoxelShape> voxelShape = new AtomicReference();
RaycastHelper.PredicateTraceResult predicateResult = RaycastHelper.rayTraceUntil(localOrigin, localTarget, p -> {
Template.BlockInfo blockInfo = contraption.getBlocks().get(p);
if (blockInfo == null)
return false;
BlockState state = blockInfo.state;
VoxelShape raytraceShape = state.getShape(Minecraft.getInstance().level, BlockPos.ZERO.below());
if (raytraceShape.isEmpty())
return false;
BlockRayTraceResult rayTrace = raytraceShape.clip(localOrigin, localTarget, p);
if (rayTrace != null) {
mutableResult.setValue(rayTrace);
voxelShape.set(raytraceShape);
return true;
}
return false;
});
if (predicateResult == null || predicateResult.missed())
return;
BlockRayTraceResult rayTraceResult = mutableResult.getValue();
BlockPos blockPos = rayTraceResult.getBlockPos();
renderBlockOutline(contraptionEntity, event.getMatrixStack(), voxelShape.get(), blockPos, event.getPartialTicks());
}
mc.getProfiler().pop();
}
use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.
the class ContraptionRenderInfoMixin method onSetupMatrices.
@Inject(locals = LocalCapture.CAPTURE_FAILHARD, remap = false, method = "setupMatrices", at = @At(remap = false, value = "INVOKE", target = "Lcom/mojang/blaze3d/matrix/MatrixStack;translate(DDD)V"))
public void onSetupMatrices(MatrixStack viewProjection, double camX, double camY, double camZ, CallbackInfo ci, AbstractContraptionEntity entity, double x, double y, double z) {
if (entity instanceof ControlledContraptionEntity && entity.level.dimension() == AirshipDimensionManager.WORLD_ID) {
int plotId = AirshipManager.getIdFromPlotPos(entity.blockPosition());
AirshipContraptionEntity airshipEntity = AirshipManager.INSTANCE.AllAirships.get(plotId);
BlockPos anchorPos = AirshipManager.getPlotPosFromId(plotId);
// viewProjection.popPose();
// viewProjection.pushPose();
// Vector3d v = airshipEntity .position().add(entity.position()).subtract(new Vector3d(anchorPos.getX(),anchorPos.getY(),anchorPos.getZ()));
// viewProjection.translate(v.x-camX,v.y-camY,v.z-camZ);
// x=v.x-camX;
}
}
use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.
the class ContraptionRenderMixin method renderTileEntities.
/**
* @author Eriksonn
*/
@Overwrite(remap = false)
public static void renderTileEntities(World world, PlacementSimulationWorld renderWorld, Contraption c, ContraptionMatrices matrices, IRenderTypeBuffer buffer) {
MatrixStack ms = matrices.getModelViewProjection();
if (c instanceof AirshipContraption) {
int plotId = ((AirshipContraptionEntity) c.entity).plotId;
BlockPos anchorPos = AirshipManager.getPlotPosFromId(plotId);
ms.translate(0, -anchorPos.getY(), 0);
}
// if(world.dimension() == AirshipDimensionManager.WORLD_ID)
// {
// int plotId = AirshipManager.getIdFromPlotPos(c.anchor);
// AirshipContraptionEntity entity = AirshipManager.INSTANCE.AllAirships.get(plotId);
// }
TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, ms, matrices.getLight(), buffer);
}
Aggregations