Skip to content

Commit

Permalink
New attribute field names, more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 24, 2024
1 parent cf56d9c commit 958ad3c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public class EnchantmentAttributesEmulation1_20_6 {
}
final int efficiencyLevel = getEquipmentLevel(Enchantments.EFFICIENCY, player);
if (efficiencyLevel > 0) {
player.getAttributeInstance(EntityAttributes.PLAYER_MINING_EFFICIENCY).setBaseValue(efficiencyLevel * efficiencyLevel + 1);
player.getAttributeInstance(EntityAttributes.MINING_EFFICIENCY).setBaseValue(efficiencyLevel * efficiencyLevel + 1);
} else {
player.getAttributeInstance(EntityAttributes.PLAYER_MINING_EFFICIENCY).setBaseValue(0);
player.getAttributeInstance(EntityAttributes.MINING_EFFICIENCY).setBaseValue(0);
}

player.getAttributeInstance(EntityAttributes.PLAYER_SNEAKING_SPEED).setBaseValue(0.3F + getEquipmentLevel(Enchantments.SWIFT_SNEAK, player) * 0.15F);
player.getAttributeInstance(EntityAttributes.PLAYER_SUBMERGED_MINING_SPEED).setBaseValue(getEquipmentLevel(Enchantments.AQUA_AFFINITY, player) <= 0 ? 0.2F : 1F);
player.getAttributeInstance(EntityAttributes.SNEAKING_SPEED).setBaseValue(0.3F + getEquipmentLevel(Enchantments.SWIFT_SNEAK, player) * 0.15F);
player.getAttributeInstance(EntityAttributes.SUBMERGED_MINING_SPEED).setBaseValue(getEquipmentLevel(Enchantments.AQUA_AFFINITY, player) <= 0 ? 0.2F : 1F);
}
});
}
Expand All @@ -82,14 +82,14 @@ public static void init() {
public static void setGenericMovementEfficiencyAttribute(final LivingEntity entity) {
final boolean isOnSoulSpeedBlock = entity.getWorld().getBlockState(entity.getVelocityAffectingPos()).isIn(BlockTags.SOUL_SPEED_BLOCKS);
if (isOnSoulSpeedBlock && getEquipmentLevel(Enchantments.SOUL_SPEED, entity) > 0) {
entity.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_EFFICIENCY).setBaseValue(1);
entity.getAttributeInstance(EntityAttributes.MOVEMENT_EFFICIENCY).setBaseValue(1);
} else {
entity.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_EFFICIENCY).setBaseValue(0);
entity.getAttributeInstance(EntityAttributes.MOVEMENT_EFFICIENCY).setBaseValue(0);
}
}

private static int getEquipmentLevel(final RegistryKey<Enchantment> enchantment, final LivingEntity entity) {
final Optional<RegistryEntry.Reference<Enchantment>> enchantmentRef = entity.getWorld().getRegistryManager().getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOptional(enchantment);
final Optional<RegistryEntry.Reference<Enchantment>> enchantmentRef = entity.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getOptional(enchantment);
return enchantmentRef.map(e -> EnchantmentHelper.getEquipmentLevel(e, entity)).orElse(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import net.minecraft.entity.mob.*;
import net.minecraft.entity.passive.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.ChestBoatEntity;
import net.minecraft.entity.vehicle.*;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;

Expand All @@ -52,25 +50,25 @@ public class EntityRidingOffsetsPre1_20_2 {
public static Vec3d getMountedHeightOffset(final Entity entity, final Entity passenger) {
double yOffset = entity.getHeight() * 0.75F;

if (entity instanceof BoatEntity boatEntity) {
if (!boatEntity.hasPassenger(passenger)) return Vec3d.ZERO;
if (entity instanceof AbstractBoatEntity abstractBoatEntity) {
if (!abstractBoatEntity.hasPassenger(passenger)) return Vec3d.ZERO;

if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) {
yOffset = -0.3F;
final double xOffset = MathHelper.cos(boatEntity.getYaw() * MathHelper.PI / 180F);
final double zOffset = MathHelper.sin(boatEntity.getYaw() * MathHelper.PI / 180F);
final double xOffset = MathHelper.cos(abstractBoatEntity.getYaw() * MathHelper.PI / 180F);
final double zOffset = MathHelper.sin(abstractBoatEntity.getYaw() * MathHelper.PI / 180F);

return new Vec3d(0.4F * xOffset, yOffset, 0.4F * zOffset);
} else {
if (boatEntity.isRemoved()) {
if (abstractBoatEntity.isRemoved()) {
yOffset = 0.01F;
} else {
yOffset = boatEntity.getVariant() == BoatEntity.Type.BAMBOO ? 0.25F : -0.1F;
yOffset = abstractBoatEntity.getType() == EntityType.BAMBOO_RAFT || abstractBoatEntity.getType() == EntityType.BAMBOO_CHEST_RAFT ? 0.25F : -0.1F;
}

double xOffset = boatEntity instanceof ChestBoatEntity ? 0.15F : 0F;
if (boatEntity.getPassengerList().size() > 1) {
final int idx = boatEntity.getPassengerList().indexOf(passenger);
double xOffset = abstractBoatEntity instanceof AbstractChestBoatEntity ? 0.15F : 0F;
if (abstractBoatEntity.getPassengerList().size() > 1) {
final int idx = abstractBoatEntity.getPassengerList().indexOf(passenger);
if (idx == 0) {
xOffset = 0.2F;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ private boolean removeVehicleCheck(ClientPlayerEntity instance) {
return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_19_3) && instance.hasVehicle();
}

@Redirect(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isFallFlying()Z"))
private boolean removeFallFlyingCheck(ClientPlayerEntity instance) {
return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_19_3) && instance.isFallFlying();
@Redirect(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isGliding()Z"))
private boolean removeGlidingCheck(ClientPlayerEntity instance) {
return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_19_3) && instance.isGliding();
}

@Redirect(method = "canSprint", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;hasVehicle()Z"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onValueChanged() {
final MinecraftClient client = MinecraftClient.getInstance();
if (client != null) {
for (FontStorage storage : client.fontManager.fontStorages.values()) {
storage.glyphRendererCache.clear();
storage.bakedGlyphCache.clear();
storage.glyphCache.clear();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/viafabricplus.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ accessible field net/minecraft/client/font/FontStorage$GlyphPair MISSING Lnet/mi
accessible field net/minecraft/network/ClientConnection packetSizeLogger Lnet/minecraft/network/handler/PacketSizeLogger;
accessible field net/minecraft/entity/boss/dragon/EnderDragonEntity body Lnet/minecraft/entity/boss/dragon/EnderDragonPart;
accessible field net/minecraft/entity/passive/AbstractHorseEntity lastAngryAnimationProgress F
accessible field net/minecraft/client/font/FontStorage bakedGlyphCache Lnet/minecraft/client/font/GlyphContainer;
accessible field net/minecraft/entity/vehicle/AbstractBoatEntity yawVelocity F
accessible field net/minecraft/client/font/FontStorage glyphCache Lnet/minecraft/client/font/GlyphContainer;
accessible field net/minecraft/entity/EntityType dimensions Lnet/minecraft/entity/EntityDimensions;
Expand Down

0 comments on commit 958ad3c

Please sign in to comment.