Implemented old 1.8 boat model back

This commit is contained in:
FlorianMichael 2023-09-24 00:48:07 +02:00
parent a407568f62
commit 670bf9fec2
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
12 changed files with 575 additions and 20 deletions

View File

@ -0,0 +1,58 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.definition.boat;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.model.*;
import net.minecraft.client.render.entity.model.CompositeEntityModel;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.util.Identifier;
public class BoatModel_1_8 extends CompositeEntityModel<BoatEntity> {
public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(new Identifier("viafabricplus", "boat_1_8"), "main");
private final ImmutableList<ModelPart> parts;
public BoatModel_1_8(ModelPart root) {
this.parts = ImmutableList.of(root.getChild("bottom"), root.getChild("back"), root.getChild("front"), root.getChild("right"), root.getChild("left"));
}
public static TexturedModelData getTexturedModelData() {
ModelData modelData = new ModelData();
ModelPartData root = modelData.getRoot();
final float width = 24;
final float wallHeight = 6;
final float baseWidth = 20;
final float pivotY = 4;
root.addChild("bottom", ModelPartBuilder.create().uv(0, 8).cuboid(-width / 2, -baseWidth / 2 + 2, -3, width, baseWidth - 4, 4), ModelTransform.of(0, pivotY, 0, (float) Math.PI / 2, 0, 0));
root.addChild("back", ModelPartBuilder.create().uv(0, 0).cuboid(-width / 2 + 2, -wallHeight - 1, -1, width - 4, wallHeight, 2), ModelTransform.of(-width / 2 + 1, pivotY, 0, 0, (float) Math.PI * 1.5f, 0));
root.addChild("front", ModelPartBuilder.create().uv(0, 0).cuboid(-width / 2 + 2, -wallHeight - 1, -1, width - 4, wallHeight, 2), ModelTransform.of(width / 2 - 1, pivotY, 0, 0, (float) Math.PI / 2, 0));
root.addChild("right", ModelPartBuilder.create().uv(0, 0).cuboid(-width / 2 + 2, -wallHeight - 1, -1, width - 4, wallHeight, 2), ModelTransform.of(0, pivotY, -baseWidth / 2 + 1, 0, (float) Math.PI, 0));
root.addChild("left", ModelPartBuilder.create().uv(0, 0).cuboid(-width / 2 + 2, -wallHeight - 1, -1, width - 4, wallHeight, 2), ModelTransform.pivot(0, pivotY, baseWidth / 2 - 1));
return TexturedModelData.of(modelData, 64, 32);
}
@Override
public Iterable<ModelPart> getParts() {
return parts;
}
@Override
public void setAngles(BoatEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
}
}

View File

@ -0,0 +1,69 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.definition.boat;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
public class BoatRenderer_1_8 extends EntityRenderer<BoatEntity> {
private static final Identifier TEXTURE = new Identifier("viafabricplus", "textures/boat_1_8.png");
private final BoatModel_1_8 model;
public BoatRenderer_1_8(EntityRendererFactory.Context ctx) {
super(ctx);
shadowRadius = 0.8f;
model = new BoatModel_1_8(ctx.getPart(BoatModel_1_8.MODEL_LAYER));
}
@Override
public Identifier getTexture(BoatEntity entity) {
return TEXTURE;
}
@Override
public void render(BoatEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
matrices.push();
matrices.translate(0, 0.375, 0);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - yaw));
float damageWobbleTicks = entity.getDamageWobbleTicks() - tickDelta;
float damageWobbleStrength = entity.getDamageWobbleStrength() - tickDelta;
if (damageWobbleStrength < 0) {
damageWobbleStrength = 0;
}
if (damageWobbleTicks > 0) {
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(MathHelper.sin(damageWobbleTicks) * damageWobbleTicks * damageWobbleStrength / 10 * entity.getDamageWobbleSide()));
}
matrices.scale(-1, -1, 1);
model.setAngles(entity, tickDelta, 0, -0.1f, 0, 0);
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(model.getLayer(TEXTURE));
model.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
matrices.pop();
super.render(entity, yaw, tickDelta, matrices, vertexConsumers, light);
}
}

View File

@ -0,0 +1,23 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.injection.access;
public interface IBoatEntity_1_8 {
void viafabricplus_setBoatEmpty(boolean boatEmpty);
}

View File

@ -1,23 +1,321 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity; package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import de.florianmichael.viafabricplus.mappings.EntityHeightOffsetMappings;
import de.florianmichael.viafabricplus.injection.access.IBoatEntity_1_8;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.entity.Entity; import net.minecraft.block.Block;
import net.minecraft.entity.EntityDimensions; import net.minecraft.block.Blocks;
import net.minecraft.entity.*;
import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import org.joml.Vector3f; import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(BoatEntity.class) @Mixin(BoatEntity.class)
public class MixinBoatEntity { public abstract class MixinBoatEntity extends Entity implements IBoatEntity_1_8 {
@Inject(method = "getPassengerAttachmentPos", at = @At("TAIL"), cancellable = true, locals = LocalCapture.CAPTURE_FAILEXCEPTION) @Shadow
public void modifyDimensionHeight(Entity passenger, EntityDimensions dimensions, float scaleFactor, CallbackInfoReturnable<Vector3f> cir, float f) { private double x;
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) {
cir.setReturnValue(new Vector3f(0F, 0.3F, f)); @Shadow
private double y;
@Shadow
private double z;
@Shadow
private double boatYaw;
@Shadow
private double boatPitch;
@Shadow
public abstract int getDamageWobbleTicks();
@Shadow
public abstract void setDamageWobbleTicks(int wobbleTicks);
@Shadow
public abstract float getDamageWobbleStrength();
@Shadow
public abstract void setDamageWobbleStrength(float wobbleStrength);
@Shadow
public abstract @Nullable LivingEntity getControllingPassenger();
@Shadow
private BoatEntity.Location location;
public MixinBoatEntity(EntityType<?> type, World world) {
super(type, world);
}
@Unique
private boolean viafabricplus_boatEmpty = true;
@Unique
private double viafabricplus_speedMultiplier = 0.07;
@Unique
private int viafabricplus_boatPosRotationIncrements;
@Unique
private double viafabricplus_velocityX;
@Unique
private double viafabricplus_velocityY;
@Unique
private double viafabricplus_velocityZ;
@Inject(method = "pushAwayFrom", at = @At("HEAD"), cancellable = true)
private void onPushAwayFrom(Entity entity, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
super.pushAwayFrom(entity);
ci.cancel();
} }
} }
@Inject(method = "updateTrackedPositionAndAngles", at = @At("HEAD"), cancellable = true)
private void onUpdateTrackedPositionAndAngles(double x, double y, double z, float yaw, float pitch, int interpolationSteps, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
if (hasPassengers()) {
this.prevX = x;
this.prevY = y;
this.prevZ = z;
this.viafabricplus_boatPosRotationIncrements = 0;
setPosition(x, y, z);
setRotation(yaw, pitch);
setVelocity(Vec3d.ZERO);
viafabricplus_velocityX = viafabricplus_velocityY = viafabricplus_velocityZ = 0;
} else {
if (viafabricplus_boatEmpty) {
viafabricplus_boatPosRotationIncrements = interpolationSteps + 5;
} else {
if (squaredDistanceTo(x, y, z) <= 1) {
return;
}
viafabricplus_boatPosRotationIncrements = 3;
}
this.x = x;
this.y = y;
this.z = z;
this.boatYaw = yaw;
this.boatPitch = pitch;
setVelocity(viafabricplus_velocityX, viafabricplus_velocityY, viafabricplus_velocityZ);
}
ci.cancel();
}
}
@Override
public void setVelocityClient(double x, double y, double z) {
super.setVelocityClient(x, y, z);
viafabricplus_velocityX = x;
viafabricplus_velocityY = y;
viafabricplus_velocityZ = z;
}
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
private void onTick(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
super.tick();
if (getDamageWobbleTicks() > 0) {
setDamageWobbleTicks(getDamageWobbleTicks() - 1);
}
if (getDamageWobbleStrength() > 0) {
setDamageWobbleStrength(getDamageWobbleStrength() - 1);
}
prevX = getX();
prevY = getY();
prevZ = getZ();
// calculate how submerged in water the boat is
final int yPartitions = 5;
double percentSubmerged = 0;
for (int partitionIndex = 0; partitionIndex < yPartitions; partitionIndex++) {
double minY = getBoundingBox().minY + getBoundingBox().getLengthY() * partitionIndex / yPartitions - 0.125;
double maxY = getBoundingBox().minY + getBoundingBox().getLengthY() * (partitionIndex + 1) / yPartitions - 0.125;
Box box = new Box(getBoundingBox().minX, minY, getBoundingBox().minZ, getBoundingBox().maxX, maxY, getBoundingBox().maxZ);
if (BlockPos.stream(box).anyMatch(pos -> getWorld().getFluidState(pos).isIn(FluidTags.WATER))) {
percentSubmerged += 1.0 / yPartitions;
}
}
// spawn boat movement splash particles
double oldHorizontalSpeed = Math.sqrt(getVelocity().x * getVelocity().x + getVelocity().z * getVelocity().z);
if (oldHorizontalSpeed > 0.2975) {
double rx = Math.cos(getYaw() * Math.PI / 180);
double rz = Math.sin(getYaw() * Math.PI / 180);
for (int i = 0; i < 1 + oldHorizontalSpeed * 60; i++) {
double dForward = random.nextFloat() * 2 - 1;
double dSideways = (random.nextInt(2) * 2 - 1) * 0.7;
if (random.nextBoolean()) {
// particles on the side of the boat
double x = getX() - rx * dForward * 0.8 + rz * dSideways;
double z = getZ() - rz * dForward * 0.8 - rx * dSideways;
getWorld().addParticle(ParticleTypes.SPLASH, x, getY() - 0.125, z, getVelocity().x, getVelocity().y, getVelocity().z);
} else {
// particles trailing behind the boat
double x = getX() + rx + rz * dForward * 0.7;
double z = getZ() + rz - rx * dForward * 0.7;
getWorld().addParticle(ParticleTypes.SPLASH, x, getY() - 0.125, z, getVelocity().x, getVelocity().y, getVelocity().z);
}
}
}
if (viafabricplus_boatEmpty) {
if (viafabricplus_boatPosRotationIncrements > 0) {
double newX = getX() + (this.x - getX()) / viafabricplus_boatPosRotationIncrements;
double newY = getY() + (this.y - getY()) / viafabricplus_boatPosRotationIncrements;
double newZ = getZ() + (this.z - getZ()) / viafabricplus_boatPosRotationIncrements;
double newYaw = this.getYaw() + (this.boatYaw - this.getYaw()) / viafabricplus_boatPosRotationIncrements;
double newPitch = this.getPitch() + (this.boatPitch - this.getPitch()) / viafabricplus_boatPosRotationIncrements;
viafabricplus_boatPosRotationIncrements--;
setPosition(newX, newY, newZ);
setRotation((float) newYaw, (float) newPitch);
} else {
setPosition(getX() + getVelocity().x, getY() + getVelocity().y, getZ() + getVelocity().z);
if (isOnGround()) {
setVelocity(getVelocity().multiply(0.5));
}
setVelocity(getVelocity().multiply(0.99, 0.95, 0.99));
}
} else {
if (percentSubmerged < 1) {
double normalizedDistanceFromMiddle = percentSubmerged * 2 - 1;
setVelocity(getVelocity().add(0, 0.04 * normalizedDistanceFromMiddle, 0));
} else {
if (getVelocity().y < 0) {
setVelocity(getVelocity().multiply(1, 0.5, 1));
}
setVelocity(getVelocity().add(0, 0.007, 0));
}
if (getControllingPassenger() != null) {
final LivingEntity passenger = getControllingPassenger();
float boatAngle = passenger.getYaw() - passenger.sidewaysSpeed * 90;
double xAcceleration = -Math.sin(boatAngle * Math.PI / 180) * viafabricplus_speedMultiplier * passenger.forwardSpeed * 0.05;
double zAcceleration = Math.cos(boatAngle * Math.PI / 180) * viafabricplus_speedMultiplier * passenger.forwardSpeed * 0.05;
setVelocity(getVelocity().add(xAcceleration, 0, zAcceleration));
}
double newHorizontalSpeed = Math.sqrt(getVelocity().x * getVelocity().x + getVelocity().z * getVelocity().z);
// cap horizontal speed at 0.35
if (newHorizontalSpeed > 0.35) {
double multiplier = 0.35 / newHorizontalSpeed;
setVelocity(getVelocity().multiply(multiplier, 1, multiplier));
newHorizontalSpeed = 0.35;
}
if (newHorizontalSpeed > oldHorizontalSpeed && viafabricplus_speedMultiplier < 0.35) {
viafabricplus_speedMultiplier += (0.35 - viafabricplus_speedMultiplier) / 35;
if (viafabricplus_speedMultiplier > 0.35) {
viafabricplus_speedMultiplier = 0.35;
}
} else {
viafabricplus_speedMultiplier -= (viafabricplus_speedMultiplier - 0.07) / 35;
if (viafabricplus_speedMultiplier < 0.07) {
viafabricplus_speedMultiplier = 0.07;
}
}
for (int i = 0; i < 4; i++) {
int dx = MathHelper.floor(getX() + ((i % 2) - 0.5) * 0.8);
//noinspection IntegerDivisionInFloatingPointContext
int dz = MathHelper.floor(getZ() + ((i / 2) - 0.5) * 0.8);
for (int ddy = 0; ddy < 2; ddy++) {
int dy = MathHelper.floor(getY()) + ddy;
BlockPos pos = new BlockPos(dx, dy, dz);
Block block = getWorld().getBlockState(pos).getBlock();
if (block == Blocks.SNOW) {
getWorld().setBlockState(pos, Blocks.AIR.getDefaultState());
horizontalCollision = false;
} else if (block == Blocks.LILY_PAD) {
getWorld().breakBlock(pos, true);
horizontalCollision = false;
}
}
}
if (isOnGround()) {
setVelocity(getVelocity().multiply(0.5));
}
move(MovementType.SELF, getVelocity());
if (!horizontalCollision || oldHorizontalSpeed <= 0.2975) {
setVelocity(getVelocity().multiply(0.99, 0.95, 0.99));
}
setPitch(0);
double deltaX = prevX - getX();
double deltaZ = prevZ - getZ();
if (deltaX * deltaX + deltaZ * deltaZ > 0.001) {
setYaw(MathHelper.clampAngle(getYaw(), (float) (MathHelper.atan2(deltaZ, deltaX) * 180 / Math.PI), 20));
}
}
ci.cancel();
}
}
@Inject(method = "updatePassengerPosition", at = @At("HEAD"), cancellable = true)
private void onUpdatePassengerPosition(Entity passenger, PositionUpdater positionUpdater, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
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);
}
ci.cancel();
}
}
@Inject(method = "onPassengerLookAround", at = @At("HEAD"), cancellable = true)
private void onOnPassengerLookAround(Entity passenger, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// don't prevent entities looking around in the boat
super.onPassengerLookAround(passenger);
ci.cancel();
}
}
@Inject(method = "fall", at = @At("HEAD"))
private void onFall(CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// prevent falling from being negated
location = BoatEntity.Location.ON_LAND;
}
}
@Inject(method = "canAddPassenger", at = @At("HEAD"), cancellable = true)
private void onCanAddPassenger(Entity passenger, CallbackInfoReturnable<Boolean> ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// only one entity can ride a boat at a time
ci.setReturnValue(super.canAddPassenger(passenger));
}
}
@Override
public void viafabricplus_setBoatEmpty(boolean boatEmpty) {
viafabricplus_boatEmpty = boatEmpty;
}
} }

View File

@ -17,7 +17,7 @@
*/ */
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity; package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import de.florianmichael.viafabricplus.definition.EntityHeightOffsets1_20_1; import de.florianmichael.viafabricplus.mappings.EntityHeightOffsetMappings;
import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityDimensions;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
@ -198,14 +198,14 @@ public abstract class MixinEntity {
@Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true) @Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true)
public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable<Float> cir) { public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable<Float> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
cir.setReturnValue((float) EntityHeightOffsets1_20_1.getHeightOffset((Entity) (Object) this)); cir.setReturnValue((float) EntityHeightOffsetMappings.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;")) @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) { public Vector3f revertStaticRidingOffsetCalculation(Entity instance, Entity passenger, EntityDimensions dimensions, float scaleFactor) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return new Vector3f(0.0F, (float) EntityHeightOffsets1_20_1.getMountedHeightOffset(instance), 0.0F); return new Vector3f(0.0F, (float) EntityHeightOffsetMappings.getMountedHeightOffset(instance), 0.0F);
} }
return getPassengerAttachmentPos(passenger, dimensions, scaleFactor); return getPassengerAttachmentPos(passenger, dimensions, scaleFactor);
} }

View File

@ -0,0 +1,36 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.injection.mixin.fixes.minecraft.entity;
import com.google.common.collect.ImmutableMap;
import de.florianmichael.viafabricplus.definition.boat.BoatModel_1_8;
import net.minecraft.client.model.TexturedModelData;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.EntityModels;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(EntityModels.class)
public class MixinEntityModels {
@ModifyVariable(method = "getModels", at = @At(value = "STORE", ordinal = 0), ordinal = 0)
private static ImmutableMap.Builder<EntityModelLayer, TexturedModelData> addBoatModel(ImmutableMap.Builder<EntityModelLayer, TexturedModelData> builder) {
return builder.put(BoatModel_1_8.MODEL_LAYER, BoatModel_1_8.getTexturedModelData());
}
}

View File

@ -0,0 +1,55 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.injection.mixin.fixes.minecraft.entity;
import de.florianmichael.viafabricplus.definition.boat.BoatRenderer_1_8;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.resource.ResourceManager;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(EntityRenderDispatcher.class)
public class MixinEntityRenderDispatcher {
@Unique
private BoatRenderer_1_8 viafabricplus_boatRenderer;
@SuppressWarnings("unchecked")
@Inject(method = "getRenderer", at = @At("HEAD"), cancellable = true)
private <T extends Entity> void onGetRenderer(T entity, CallbackInfoReturnable<EntityRenderer<? super T>> ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) && entity instanceof BoatEntity) {
ci.setReturnValue((EntityRenderer<? super T>) viafabricplus_boatRenderer);
}
}
@Inject(method = "reload", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD)
private void onReload(ResourceManager manager, CallbackInfo ci, EntityRendererFactory.Context context) {
viafabricplus_boatRenderer = new BoatRenderer_1_8(context);
}
}

View File

@ -19,7 +19,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import com.llamalad7.mixinextras.injector.WrapWithCondition; import com.llamalad7.mixinextras.injector.WrapWithCondition;
import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings; import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings;
import de.florianmichael.viafabricplus.definition.EntityHeightOffsets1_20_1; import de.florianmichael.viafabricplus.mappings.EntityHeightOffsetMappings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.TrapdoorBlock; import net.minecraft.block.TrapdoorBlock;
@ -211,14 +211,14 @@ public abstract class MixinLivingEntity extends Entity {
@Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true) @Inject(method = "getRidingOffset", at = @At("HEAD"), cancellable = true)
public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable<Float> cir) { public void replaceRidingOffset(Entity vehicle, CallbackInfoReturnable<Float> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
cir.setReturnValue((float) EntityHeightOffsets1_20_1.getHeightOffset((Entity) (Object) this)); cir.setReturnValue((float) EntityHeightOffsetMappings.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;")) @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) { public Vector3f revertStaticRidingOffsetCalculation(LivingEntity instance, Entity entity, EntityDimensions entityDimensions, float v) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return new Vector3f(0.0F, (float) EntityHeightOffsets1_20_1.getMountedHeightOffset(instance), 0.0F); return new Vector3f(0.0F, (float) EntityHeightOffsetMappings.getMountedHeightOffset(instance), 0.0F);
} }
return getPassengerAttachmentPos(entity, entityDimensions, v); return getPassengerAttachmentPos(entity, entityDimensions, v);
} }

View File

@ -20,6 +20,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.network;
import com.llamalad7.mixinextras.injector.WrapWithCondition; import com.llamalad7.mixinextras.injector.WrapWithCondition;
import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings; import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings;
import de.florianmichael.viafabricplus.injection.access.IBoatEntity_1_8;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.DownloadingTerrainScreen; import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
@ -37,10 +38,8 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.time.Duration;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import java.util.function.BooleanSupplier;
@SuppressWarnings("DataFlowIssue") @SuppressWarnings("DataFlowIssue")
@Mixin(ClientPlayNetworkHandler.class) @Mixin(ClientPlayNetworkHandler.class)
@ -105,6 +104,16 @@ public abstract class MixinClientPlayNetworkHandler {
return constant; return constant;
} }
@Inject(method = "onEntityPassengersSet", at = @At("RETURN"))
private void handle1_8BoatPassengers(EntityPassengersSetS2CPacket packet, CallbackInfo ci) {
if (!ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) return;
final var entity = this.world.getEntityById(packet.getId());
if (entity instanceof IBoatEntity_1_8 boatEntity) {
boatEntity.viafabricplus_setBoatEmpty(packet.getPassengerIds().length == 0);
}
}
@WrapWithCondition(method = "onPlayerList", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false)) @WrapWithCondition(method = "onPlayerList", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false))
public boolean removeWarning(Logger instance, String s, Object o) { public boolean removeWarning(Logger instance, String s, Object o) {
return ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(VersionEnum.r1_19_3); return ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(VersionEnum.r1_19_3);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package de.florianmichael.viafabricplus.definition; package de.florianmichael.viafabricplus.mappings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -31,7 +31,7 @@ import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
public class EntityHeightOffsets1_20_1 { public class EntityHeightOffsetMappings {
public static double getMountedHeightOffset(final Entity entity) { public static double getMountedHeightOffset(final Entity entity) {
double offset = entity.getHeight() * 0.75; double offset = entity.getHeight() * 0.75;
@ -57,7 +57,12 @@ public class EntityHeightOffsets1_20_1 {
} else if (entity instanceof ZoglinEntity zoglinEntity) { } else if (entity instanceof ZoglinEntity zoglinEntity) {
offset = (double) entity.getHeight() - (zoglinEntity.isBaby() ? 0.2 : 0.15); offset = (double) entity.getHeight() - (zoglinEntity.isBaby() ? 0.2 : 0.15);
} else if (entity instanceof BoatEntity boatEntity) { } else if (entity instanceof BoatEntity boatEntity) {
offset = boatEntity.getVariant() == BoatEntity.Type.BAMBOO ? 0.25 : -0.1; final var version = ProtocolHack.getTargetVersion();
if (version.isOlderThanOrEqualTo(VersionEnum.r1_8)) {
offset = -0.3;
} else {
offset = boatEntity.getVariant() == BoatEntity.Type.BAMBOO ? version.isOlderThanOrEqualTo(VersionEnum.r1_19_4) ? 0.3 : 0.25 : -0.1;
}
} else if (entity instanceof StriderEntity striderEntity) { } else if (entity instanceof StriderEntity striderEntity) {
float var1 = Math.min(0.25F, striderEntity.limbAnimator.getSpeed()); float var1 = Math.min(0.25F, striderEntity.limbAnimator.getSpeed());
float var2 = striderEntity.limbAnimator.getPos(); float var2 = striderEntity.limbAnimator.getPos();

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -80,7 +80,9 @@
"fixes.minecraft.entity.MixinCreeperEntity", "fixes.minecraft.entity.MixinCreeperEntity",
"fixes.minecraft.entity.MixinEntity", "fixes.minecraft.entity.MixinEntity",
"fixes.minecraft.entity.MixinEntityIndex", "fixes.minecraft.entity.MixinEntityIndex",
"fixes.minecraft.entity.MixinEntityModels",
"fixes.minecraft.entity.MixinEntityPredicates", "fixes.minecraft.entity.MixinEntityPredicates",
"fixes.minecraft.entity.MixinEntityRenderDispatcher",
"fixes.minecraft.entity.MixinItemEntity", "fixes.minecraft.entity.MixinItemEntity",
"fixes.minecraft.entity.MixinLivingEntity", "fixes.minecraft.entity.MixinLivingEntity",
"fixes.minecraft.entity.MixinLockableContainerBlockEntity", "fixes.minecraft.entity.MixinLockableContainerBlockEntity",