mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-22 11:56:21 +01:00
Implemented Camel, Llama and Chicken passenger offsets
This commit is contained in:
parent
baf48de0b8
commit
f63ff90711
@ -15,10 +15,11 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.mappings;
|
||||
package de.florianmichael.viafabricplus.definition;
|
||||
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.minecraft.entity.EntityPose;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
|
||||
@ -30,54 +31,106 @@ import net.minecraft.entity.vehicle.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class EntityHeightOffsetMappings {
|
||||
public class EntityHeightOffsetsPre1_20_2 {
|
||||
|
||||
public static double getMountedHeightOffset(final Entity entity) {
|
||||
double offset = entity.getHeight() * 0.75;
|
||||
public static void clamPassengerYaw(final Entity entity, final Entity passenger) {
|
||||
if (entity instanceof CamelEntity camelEntity) {
|
||||
passenger.setBodyYaw(camelEntity.getYaw());
|
||||
final float passengerYaw = passenger.getYaw();
|
||||
|
||||
if (entity instanceof LlamaEntity) {
|
||||
offset = entity.getHeight() * 0.6;
|
||||
final float deltaDegrees = MathHelper.wrapDegrees(passengerYaw - camelEntity.getYaw());
|
||||
final float clampedDelta = MathHelper.clamp(deltaDegrees, -160.0f, 160.0f);
|
||||
passenger.prevYaw += clampedDelta - deltaDegrees;
|
||||
|
||||
final float newYaw = passengerYaw + clampedDelta - deltaDegrees;
|
||||
passenger.setYaw(newYaw);
|
||||
passenger.setHeadYaw(newYaw);
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3f getMountedHeightOffset(final Entity entity, final Entity passenger) {
|
||||
double yOffset = entity.getHeight() * 0.75;
|
||||
|
||||
if (entity instanceof LlamaEntity llamaEntity) {
|
||||
yOffset = entity.getHeight() * 0.6;
|
||||
|
||||
final float xOffset = MathHelper.sin(llamaEntity.bodyYaw * 0.017453292F);
|
||||
final float zOffset = MathHelper.cos(llamaEntity.bodyYaw * 0.017453292F);
|
||||
|
||||
return new Vector3f(0.3F * xOffset, (float) yOffset, -(0.3F * zOffset));
|
||||
} else if (entity instanceof CamelEntity camelEntity) {
|
||||
offset = entity.getDimensions(camelEntity.isSitting() ? EntityPose.SITTING : EntityPose.STANDING).height - (camelEntity.isBaby() ? 0.35F : 0.6F);
|
||||
yOffset = entity.getDimensions(camelEntity.isSitting() ? EntityPose.SITTING : EntityPose.STANDING).height - (camelEntity.isBaby() ? 0.35F : 0.6F);
|
||||
|
||||
final int passengerIndex = camelEntity.getPassengerList().indexOf(passenger);
|
||||
final boolean firstIndex = passengerIndex == 0;
|
||||
|
||||
if (passengerIndex >= 0) {
|
||||
float zOffset = 0.5f;
|
||||
if (camelEntity.isRemoved()) {
|
||||
yOffset = 0.01f;
|
||||
} else {
|
||||
final var fakeDimension = EntityDimensions.fixed(0F, (0.375F * camelEntity.getScaleFactor()) + (float) yOffset); // Reverts original calculation to set yOffset to our field
|
||||
|
||||
yOffset = camelEntity.getPassengerAttachmentY(firstIndex, 0.0f, fakeDimension, camelEntity.getScaleFactor());
|
||||
}
|
||||
|
||||
if (camelEntity.getPassengerList().size() > 1) {
|
||||
if (!firstIndex) {
|
||||
zOffset = -0.7f;
|
||||
}
|
||||
if (passenger instanceof AnimalEntity) {
|
||||
zOffset += 0.2f;
|
||||
}
|
||||
}
|
||||
|
||||
return new Vector3f(0, (float) yOffset, zOffset);
|
||||
}
|
||||
} else if (entity instanceof SnifferEntity) {
|
||||
offset = 1.8;
|
||||
yOffset = 1.8;
|
||||
} else if (entity instanceof EnderDragonEntity enderDragonEntity) {
|
||||
offset = enderDragonEntity.body.getHeight();
|
||||
yOffset = enderDragonEntity.body.getHeight();
|
||||
} else if (entity instanceof PiglinEntity) {
|
||||
offset = entity.getHeight() * 0.92;
|
||||
yOffset = entity.getHeight() * 0.92;
|
||||
} else if (entity instanceof HoglinEntity hoglinEntity) {
|
||||
offset = entity.getHeight() - (hoglinEntity.isBaby() ? 0.2 : 0.15);
|
||||
yOffset = entity.getHeight() - (hoglinEntity.isBaby() ? 0.2 : 0.15);
|
||||
} else if (entity instanceof SkeletonHorseEntity) {
|
||||
offset -= 0.1875;
|
||||
yOffset -= 0.1875;
|
||||
} else if (entity instanceof PhantomEntity) {
|
||||
offset = entity.getEyeHeight(entity.getPose());
|
||||
yOffset = entity.getEyeHeight(entity.getPose());
|
||||
} else if (entity instanceof RavagerEntity) {
|
||||
offset = 2.1;
|
||||
yOffset = 2.1;
|
||||
} else if (entity instanceof ZoglinEntity zoglinEntity) {
|
||||
offset = (double) entity.getHeight() - (zoglinEntity.isBaby() ? 0.2 : 0.15);
|
||||
yOffset = (double) entity.getHeight() - (zoglinEntity.isBaby() ? 0.2 : 0.15);
|
||||
} else if (entity instanceof BoatEntity boatEntity) {
|
||||
final var version = ProtocolHack.getTargetVersion();
|
||||
if (version.isOlderThanOrEqualTo(VersionEnum.r1_8)) {
|
||||
offset = -0.3;
|
||||
yOffset = -0.3;
|
||||
} else {
|
||||
offset = boatEntity.getVariant() == BoatEntity.Type.BAMBOO ? version.isOlderThanOrEqualTo(VersionEnum.r1_19_4) ? 0.3 : 0.25 : -0.1;
|
||||
yOffset = boatEntity.getVariant() == BoatEntity.Type.BAMBOO ? 0.25 : -0.1;
|
||||
}
|
||||
} else if (entity instanceof StriderEntity striderEntity) {
|
||||
float var1 = Math.min(0.25F, striderEntity.limbAnimator.getSpeed());
|
||||
float var2 = striderEntity.limbAnimator.getPos();
|
||||
offset = (double) striderEntity.getHeight() - 0.19 + (double) (0.12F * MathHelper.cos(var2 * 1.5F) * 2.0F * var1);
|
||||
final var var1 = Math.min(0.25F, striderEntity.limbAnimator.getSpeed());
|
||||
final var var2 = striderEntity.limbAnimator.getPos();
|
||||
|
||||
yOffset = (double) striderEntity.getHeight() - 0.19 + (double) (0.12F * MathHelper.cos(var2 * 1.5F) * 2.0F * var1);
|
||||
} else if (entity instanceof SpiderEntity) {
|
||||
offset = entity.getHeight() * 0.5F;
|
||||
yOffset = entity.getHeight() * 0.5F;
|
||||
} else if (entity instanceof ChickenEntity chickenEntity) {
|
||||
final var xOffset = MathHelper.sin(chickenEntity.bodyYaw * (MathHelper.PI / 180));
|
||||
final var zOffset = MathHelper.cos(chickenEntity.bodyYaw * (MathHelper.PI / 180));
|
||||
|
||||
return new Vector3f(0.1f * xOffset, (float) (chickenEntity.getBodyY(0.5) - chickenEntity.getY()), -(0.1f * zOffset));
|
||||
}
|
||||
|
||||
if (entity instanceof AbstractDonkeyEntity) {
|
||||
offset -= 0.25;
|
||||
yOffset -= 0.25;
|
||||
} else if (entity instanceof AbstractMinecartEntity) {
|
||||
offset = 0.0;
|
||||
yOffset = 0.0;
|
||||
}
|
||||
|
||||
return offset;
|
||||
return new Vector3f(0.0F, (float) yOffset, 0.0F);
|
||||
}
|
||||
|
||||
public static double getHeightOffset(final Entity entity) {
|
||||
@ -90,7 +143,7 @@ public class EntityHeightOffsetMappings {
|
||||
} else if (entity instanceof ShulkerEntity shulkerEntity) {
|
||||
final var vehicleType = shulkerEntity.getVehicle().getType();
|
||||
|
||||
return !(shulkerEntity.getVehicle() instanceof BoatEntity) && vehicleType != EntityType.MINECART ? 0 : 0.1875 - getMountedHeightOffset(shulkerEntity.getVehicle());
|
||||
return !(shulkerEntity.getVehicle() instanceof BoatEntity) && vehicleType != EntityType.MINECART ? 0 : 0.1875 - getMountedHeightOffset(shulkerEntity.getVehicle(), null).y;
|
||||
} else if (entity instanceof SilverfishEntity) {
|
||||
return 0.1;
|
||||
} else if (entity instanceof VexEntity) {
|
@ -1,7 +1,7 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
|
||||
|
||||
import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings;
|
||||
import de.florianmichael.viafabricplus.mappings.EntityHeightOffsetMappings;
|
||||
import de.florianmichael.viafabricplus.definition.EntityHeightOffsetsPre1_20_2;
|
||||
import de.florianmichael.viafabricplus.injection.access.IBoatEntity;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import net.minecraft.block.Block;
|
||||
@ -284,7 +284,7 @@ public abstract class MixinBoatEntity extends Entity implements IBoatEntity {
|
||||
if (hasPassenger(passenger)) {
|
||||
double dx = Math.cos(this.getYaw() * Math.PI / 180) * 0.4;
|
||||
double dz = Math.sin(this.getYaw() * Math.PI / 180) * 0.4;
|
||||
passenger.setPosition(getX() + dx, getY() + EntityHeightOffsetMappings.getMountedHeightOffset(this), getZ() + dz);
|
||||
passenger.setPosition(getX() + dx, getY() + EntityHeightOffsetsPre1_20_2.getMountedHeightOffset(this, passenger).y, getZ() + dz);
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
|
@ -1,14 +1,23 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
|
||||
|
||||
import de.florianmichael.viafabricplus.definition.EntityHeightOffsetsPre1_20_2;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.passive.AbstractHorseEntity;
|
||||
import net.minecraft.entity.passive.CamelEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(CamelEntity.class)
|
||||
public class MixinCamelEntity {
|
||||
public abstract class MixinCamelEntity extends AbstractHorseEntity {
|
||||
|
||||
public MixinCamelEntity(EntityType<? extends AbstractHorseEntity> entityType, World world) {
|
||||
super(entityType, world);
|
||||
}
|
||||
|
||||
@Redirect(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CamelEntity;isBaby()Z", ordinal = 0))
|
||||
public boolean removeIfCase(CamelEntity instance) {
|
||||
@ -17,4 +26,20 @@ public class MixinCamelEntity {
|
||||
}
|
||||
return instance.isBaby();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPassengerLookAround(Entity passenger) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1) && this.getControllingPassenger() != passenger) {
|
||||
EntityHeightOffsetsPre1_20_2.clamPassengerYaw(this, passenger);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updatePassengerPosition(Entity passenger, PositionUpdater positionUpdater) {
|
||||
super.updatePassengerPosition(passenger, positionUpdater);
|
||||
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
||||
EntityHeightOffsetsPre1_20_2.clamPassengerYaw(this, passenger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
|
||||
|
||||
import de.florianmichael.viafabricplus.mappings.EntityHeightOffsetMappings;
|
||||
import de.florianmichael.viafabricplus.definition.EntityHeightOffsetsPre1_20_2;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
@ -198,14 +198,14 @@ public abstract class MixinEntity {
|
||||
@Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true)
|
||||
public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable<Float> cir) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
||||
cir.setReturnValue((float) EntityHeightOffsetMappings.getHeightOffset((Entity) (Object) this));
|
||||
cir.setReturnValue((float) EntityHeightOffsetsPre1_20_2.getHeightOffset((Entity) (Object) this));
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "getPassengerRidingPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPassengerAttachmentPos(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/EntityDimensions;F)Lorg/joml/Vector3f;"))
|
||||
public Vector3f revertStaticRidingOffsetCalculation(Entity instance, Entity passenger, EntityDimensions dimensions, float scaleFactor) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
||||
return new Vector3f(0.0F, (float) EntityHeightOffsetMappings.getMountedHeightOffset(instance), 0.0F);
|
||||
return EntityHeightOffsetsPre1_20_2.getMountedHeightOffset(instance, passenger);
|
||||
}
|
||||
return getPassengerAttachmentPos(passenger, dimensions, scaleFactor);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.WrapWithCondition;
|
||||
import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings;
|
||||
import de.florianmichael.viafabricplus.mappings.EntityHeightOffsetMappings;
|
||||
import de.florianmichael.viafabricplus.definition.EntityHeightOffsetsPre1_20_2;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.TrapdoorBlock;
|
||||
@ -211,14 +211,14 @@ public abstract class MixinLivingEntity extends Entity {
|
||||
@Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true)
|
||||
public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable<Float> cir) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
||||
cir.setReturnValue((float) EntityHeightOffsetMappings.getHeightOffset((Entity) (Object) this));
|
||||
cir.setReturnValue((float) EntityHeightOffsetsPre1_20_2.getHeightOffset((Entity) (Object) this));
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "getPassengerRidingPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPassengerAttachmentPos(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/EntityDimensions;F)Lorg/joml/Vector3f;"))
|
||||
public Vector3f revertStaticRidingOffsetCalculation(LivingEntity instance, Entity entity, EntityDimensions entityDimensions, float v) {
|
||||
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
|
||||
return new Vector3f(0.0F, (float) EntityHeightOffsetMappings.getMountedHeightOffset(instance), 0.0F);
|
||||
return EntityHeightOffsetsPre1_20_2.getMountedHeightOffset(instance, entity);
|
||||
}
|
||||
return getPassengerAttachmentPos(entity, entityDimensions, v);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ accessible field net/minecraft/entity/boss/dragon/EnderDragonEntity body Lnet/mi
|
||||
|
||||
accessible method net/minecraft/screen/GenericContainerScreenHandler <init> (Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;I)V
|
||||
accessible method net/minecraft/client/font/FontStorage$GlyphPair <init> (Lnet/minecraft/client/font/Glyph;Lnet/minecraft/client/font/Glyph;)V
|
||||
accessible method net/minecraft/entity/passive/CamelEntity getPassengerAttachmentY (ZFLnet/minecraft/entity/EntityDimensions;F)D
|
||||
|
||||
accessible class net/minecraft/client/gui/screen/GameModeSelectionScreen$GameModeSelection
|
||||
accessible class net/minecraft/client/font/FontStorage$GlyphPair
|
||||
|
Loading…
Reference in New Issue
Block a user