Skip to content

Commit

Permalink
General cleanup of code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rektroth committed Apr 24, 2024
1 parent b62ef73 commit 98c8b1b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.5+build.1
loader_version=0.15.10

# Mod Properties
mod_version=0.2.0
mod_version=0.2.1
maven_group=io.github.rektroth
archives_base_name=whiteout

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Patch for MC-158900
* Patch for MC-4
*
* Authored for CraftBukkit/Spigot by Spottedleaf <[email protected].com> on August 13, 2019.
* Authored for CraftBukkit/Spigot by BillyGalbreath <blake.galbreath@gmail.com> on December 8, 2020.
* Ported to Fabric by Rektroth <[email protected]> on July 11, 2023.
*/

Expand All @@ -19,17 +19,21 @@

@Mixin(Entity.class)
public abstract class EntityMixin implements Nameable, EntityLike, CommandOutput {
@ModifyVariable(at = @At("HEAD"), method = "setPos(DDD)V", ordinal = 0)
// `(Entity)(Object)this` sort of "tricks" the compiler
// https://www.reddit.com/r/fabricmc/comments/nw3rs8/how_can_i_access_the_this_in_a_mixin_for_a_class/
// IDE will likely say the code after the check is unreachable, but it isn't

@ModifyVariable(argsOnly = true, at = @At("HEAD"), method = "setPos(DDD)V", ordinal = 0)
private double fixItemXPositionDesync(double x){
return (Entity)(Object)this instanceof ItemEntity ? MathHelper.lfloor(x * 4096.0D) * (1 / 4096.0D) : x;
}

@ModifyVariable(at = @At("HEAD"), method = "setPos(DDD)V", ordinal = 1)
@ModifyVariable(argsOnly = true, at = @At("HEAD"), method = "setPos(DDD)V", ordinal = 1)
private double fixItemYPositionDesync(double y){
return (Entity)(Object)this instanceof ItemEntity ? MathHelper.lfloor(y * 4096.0D) * (1 / 4096.0D) : y;
}

@ModifyVariable(at = @At("HEAD"), method = "setPos(DDD)V", ordinal = 2)
@ModifyVariable(argsOnly = true, at = @At("HEAD"), method = "setPos(DDD)V", ordinal = 2)
private double fixItemZPositionDesync(double z){
return (Entity)(Object)this instanceof ItemEntity ? MathHelper.lfloor(z * 4096.0D) * (1 / 4096.0D) : z;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
@Mixin(EnderDragonFight.class)
public interface EnderDragonFightAccessor {
@Accessor("bossBar")
public ServerBossBar getBossBar();
ServerBossBar getBossBar();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@
import net.minecraft.entity.boss.dragon.EnderDragonFight;
import net.minecraft.text.Text;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EnderDragonFight.class)
public class EnderDragonFightMixin {
@Unique
private static final Text DEFAULT_BOSS_EVENT_NAME = Text.translatable("entity.minecraft.ender_dragon");

@Inject(at = @At("TAIL"), method = "updateFight(Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;)V")
private void fixedCustomNameCheck(EnderDragonEntity dragon, CallbackInfo ci) {
ServerBossBar bossBar = ((EnderDragonFightAccessor)((EnderDragonFight)(Object)this)).getBossBar();
ServerBossBar bossBar = ((EnderDragonFightAccessor)this).getBossBar();

if (dragon.hasCustomName()) {
bossBar.setName(dragon.getDisplayName());
} else {
bossBar.setName(DEFAULT_BOSS_EVENT_NAME);
bossBar.setName(Text.translatable("entity.minecraft.ender_dragon"));
}
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;hasCustomName()Z"), method = "updateFight(Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;)V")
@Redirect(
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;hasCustomName()Z"),
method = "updateFight(Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;)V")
private boolean skipBadCustomNameCheck(EnderDragonEntity instance) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
@Mixin(PlayerManager.class)
public interface PlayerManagerAccessor {
@Accessor("bannedProfiles")
public BannedPlayerList getBannedProfiles();
BannedPlayerList getBannedProfiles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,34 @@
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(PlayerManager.class)
public abstract class PlayerManagerMixin {
@Unique
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");

@Inject(at = @At("HEAD"), method = "checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;", cancellable = true)
@Inject(
at = @At("HEAD"),
method = "checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;",
cancellable = true)
private void fixedBanCheck(SocketAddress address, GameProfile profile, CallbackInfoReturnable<Text> ci) {
if (((PlayerManagerAccessor)((PlayerManager)(Object)this)).getBannedProfiles().contains(profile)) {
BannedPlayerEntry bannedPlayerEntry = (BannedPlayerEntry)((PlayerManagerAccessor)((PlayerManager)(Object)this)).getBannedProfiles().get(profile);
if (((PlayerManagerAccessor)this).getBannedProfiles().contains(profile)) {
BannedPlayerEntry bannedPlayerEntry = ((PlayerManagerAccessor)this).getBannedProfiles().get(profile);

if (bannedPlayerEntry != null) {
MutableText mutableText = Text.translatable("multiplayer.disconnect.banned.reason", bannedPlayerEntry.getReason());
MutableText mutableText = Text.translatable(
"multiplayer.disconnect.banned.reason",
bannedPlayerEntry.getReason());

if (bannedPlayerEntry.getExpiryDate() != null) {
mutableText.append(Text.translatable("multiplayer.disconnect.banned.expiration", DATE_FORMATTER.format(bannedPlayerEntry.getExpiryDate())));
mutableText.append(Text.translatable(
"multiplayer.disconnect.banned.expiration",
DATE_FORMATTER.format(bannedPlayerEntry.getExpiryDate())));
}

ci.setReturnValue(mutableText);
Expand Down

0 comments on commit 98c8b1b

Please sign in to comment.