initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package studio.halbear.hem_custom.mixin;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.settings.PointOfView;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static studio.halbear.hem_custom.vehicles.VehicleCameraSettings.GetCameraOffsets;
|
||||
|
||||
@Mixin(ActiveRenderInfo.class)
|
||||
public abstract class CameraMixins {
|
||||
|
||||
@Inject(method = "update", at = @At(value = "TAIL"),cancellable = true)
|
||||
private void update(IBlockReader currentRenderedLevel, Entity entity, boolean isDetached, boolean isMirrored, float partialTicks, CallbackInfo ci){
|
||||
|
||||
if(entity.isPassenger() && Minecraft.getInstance().gameSettings.getPointOfView() != PointOfView.FIRST_PERSON && entity.getRidingEntity().getClass().getName().contains("studio.halbear.hem.entity")){
|
||||
Vector3f Position = GetCameraOffsets();
|
||||
this.movePosition(-this.calcCameraDistance(Position.getZ()), Position.getY(), Position.getX());
|
||||
}
|
||||
}
|
||||
@Shadow protected abstract void movePosition(double p_216782_1_, double p_216782_3_, double p_216782_5_);
|
||||
@Shadow protected abstract double calcCameraDistance(double p_216779_1_);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package studio.halbear.hem_custom.vehicles;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.PointOfView;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.client.event.EntityViewRenderEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class VehicleCameraSettings {
|
||||
private static Vector3f CamOffset = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
private static Vector3f CamTransformations = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
private static float CamFOV = 0.0f;
|
||||
private static float CamFOVExternal = 0.0f;
|
||||
private static String CurrentEntity = "";
|
||||
private static boolean HemVehicle = false;
|
||||
|
||||
public static Vector3f GetCameraOffsets(){
|
||||
return CamOffset;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void PlayerTickEvent(TickEvent.PlayerTickEvent event) {
|
||||
Minecraft minecraftInstance = Minecraft.getInstance();
|
||||
if (minecraftInstance.player != null && minecraftInstance.player.isPassenger() && minecraftInstance.player.getRidingEntity() != null
|
||||
&& CurrentEntity != minecraftInstance.player.getRidingEntity().getClass().getName()) {
|
||||
CurrentEntity = minecraftInstance.player.getRidingEntity().getClass().getName();
|
||||
HemVehicle = CurrentEntity.contains("studio.halbear.hem.entity");
|
||||
switch (CurrentEntity) {
|
||||
case "studio.halbear.hem.entity.HotAirBalloonEntity$CustomEntity" : //yeah i hardcoded ts
|
||||
CamOffset = new Vector3f(0.0f, 1.0f, 4.0f);
|
||||
CamTransformations = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
CamFOV = 70.0f;
|
||||
CamFOVExternal = 80.0f;
|
||||
break;
|
||||
case "studio.halbear.hem.entity.AirboatEntity$CustomEntity" :
|
||||
CamOffset = new Vector3f(0.0f, 4.0f, 16.0f);
|
||||
CamTransformations = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
CamFOV = 70.0f;
|
||||
CamFOVExternal = 65.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (minecraftInstance.player != null && (!minecraftInstance.player.isPassenger() || !HemVehicle)
|
||||
&& (CamFOVExternal != (float) Minecraft.getInstance().gameSettings.fov
|
||||
|| CamFOV != (float) Minecraft.getInstance().gameSettings.fov || CamOffset.getX() != 0 || CamOffset.getY() != 0
|
||||
|| CamOffset.getZ() != 0 || CamTransformations.getX() != 0 || CamTransformations.getY() != 0
|
||||
|| CamTransformations.getZ() != 0)) {
|
||||
CamOffset = new Vector3f(0.0f, 0.0f, 0.0f);// reset if the players not riding an entity and if any the values aren't 0
|
||||
CamTransformations = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
CamFOV = (float) Minecraft.getInstance().gameSettings.fov;
|
||||
CamFOVExternal = (float) Minecraft.getInstance().gameSettings.fov;
|
||||
if (!minecraftInstance.player.isPassenger())
|
||||
CurrentEntity = "";
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onCameraSetup(EntityViewRenderEvent.CameraSetup event) { // sets the Yaw, Roll, and Pitch for the camera, ONLY if its a HEM vehcile as to avoid unnecessary ticks
|
||||
if (HemVehicle) {
|
||||
event.setRoll(event.getRoll() + CamTransformations.getX());
|
||||
event.setYaw(event.getYaw() + CamTransformations.getY());
|
||||
event.setPitch(event.getPitch() + CamTransformations.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onCameraSetup(EntityViewRenderEvent.FOVModifier event) { // sets the FOV
|
||||
if (HemVehicle) {
|
||||
Minecraft minecraftInstance = Minecraft.getInstance();
|
||||
if (minecraftInstance.player != null && minecraftInstance.gameRenderer != null) {
|
||||
PointOfView Cam = minecraftInstance.gameSettings.getPointOfView();
|
||||
if (Cam == PointOfView.FIRST_PERSON) {
|
||||
event.setFOV(CamFOV);
|
||||
} else {
|
||||
event.setFOV(CamFOVExternal);
|
||||
}
|
||||
}
|
||||
} else if (event.getFOV() != Minecraft.getInstance().gameSettings.fov) {
|
||||
event.setFOV(Minecraft.getInstance().gameSettings.fov);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user