Skip to content

Commit

Permalink
I can load into a world on Fabric without crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Apr 20, 2024
1 parent ee57a64 commit 10c9b6e
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,40 @@ private void onPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L
}

@Inject(
method = "use",
method = "useWithoutItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z"
)
)
private void intentionalGameDesignTrigger(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> cir) {
private void intentionalGameDesignTrigger(
BlockState blockState, Level level, BlockPos blockPos, Player player, BlockHitResult blockHitResult,
CallbackInfoReturnable<InteractionResult> cir
) {
if (player instanceof ServerPlayer serverPlayer) {
BingoTriggers.INTENTIONAL_GAME_DESIGN.get().trigger(serverPlayer, pos);
BingoTriggers.INTENTIONAL_GAME_DESIGN.get().trigger(serverPlayer, blockPos);
}
}

@WrapOperation(
method = "use",
method = "useWithoutItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/player/Player;startSleepInBed(Lnet/minecraft/core/BlockPos;)Lcom/mojang/datafixers/util/Either;"
)
)
private Either<Player.BedSleepingProblem, Unit> sleptTrigger(
Player instance, BlockPos bedPos, Operation<Either<Player.BedSleepingProblem, Unit>> original,
@Local BlockState state, @Local InteractionHand hand
Player instance, BlockPos bedPos,
Operation<Either<Player.BedSleepingProblem, Unit>> original,
@Local(argsOnly = true) BlockState state
) {
final var result = original.call(instance, bedPos);
if (!(instance instanceof ServerPlayer serverPlayer)) {
return result;
}
return result.ifRight(unit -> BingoTriggers.SLEPT.get().trigger(
serverPlayer, bedPos, instance.getItemInHand(hand)
// useWithoutItem is only ever called with the MAIN_HAND
serverPlayer, bedPos, instance.getItemInHand(InteractionHand.MAIN_HAND)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MixinDoorBlock {
target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"
)
)
private BlockState onDoorOpened(BlockState state, @Local Level level, @Local(ordinal = 0) BlockPos doorPos) {
private BlockState onDoorOpened(BlockState state, @Local(argsOnly = true) Level level, @Local(ordinal = 0, argsOnly = true) BlockPos doorPos) {
if (state.getValue(OPEN) && GlobalVars.CURRENT_PLAYER.get() instanceof ServerPlayer player) {
final Projectile projectile = GlobalVars.CURRENT_PROJECTILE.get();
final BlockPos targetPos = GlobalVars.CURRENT_BLOCK_POS.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@

import io.github.gaming32.bingo.triggers.BingoTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.Consumer;

@Mixin(ItemStack.class)
public class MixinItemStack {
@Inject(
method = "hurtAndBreak",
method = "lambda$hurtAndBreak$15",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"
)
)
private void itemBrokenTrigger(int amount, LivingEntity entity, Consumer<? extends LivingEntity> onBroken, CallbackInfo ci) {
if (entity instanceof ServerPlayer serverPlayer) {
private void itemBrokenTrigger(LivingEntity livingEntity, EquipmentSlot equipmentSlot, CallbackInfo ci) {
if (livingEntity instanceof ServerPlayer serverPlayer) {
BingoTriggers.ITEM_BROKEN.get().trigger(serverPlayer, (ItemStack)(Object)this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixinLeadItem {
)
private static LeashFenceKnotEntity setKnotOwner(
Level level, BlockPos pos, Operation<LeashFenceKnotEntity> original,
@Local Player player
@Local(argsOnly = true) Player player
) {
final LeashFenceKnotEntity entity = original.call(level, pos);
((LeashFenceKnotEntityExt)entity).bingo$setOwner(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public MixinLivingEntity(EntityType<?> entityType, Level level) {
target = "Lnet/minecraft/world/entity/LivingEntity;doesEmitEquipEvent(Lnet/minecraft/world/entity/EquipmentSlot;)Z"
)
)
@SuppressWarnings("UnreachableCode")
private void onEquipItem(EquipmentSlot slot, ItemStack oldItem, ItemStack newItem, CallbackInfo ci) {
if ((Object)this instanceof ServerPlayer player) {
BingoTriggers.EQUIP_ITEM.get().trigger(player, oldItem, newItem, slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected MixinPig(EntityType<? extends Animal> entityType, Level level) {
target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"
)
)
private boolean zombifyPigTrigger(ServerLevel instance, Entity entity, Operation<Boolean> original, @Local LightningBolt lightning) {
private boolean zombifyPigTrigger(ServerLevel instance, Entity entity, Operation<Boolean> original, @Local(argsOnly = true) LightningBolt lightning) {
final boolean result = original.call(instance, entity);
if (result) {
if (lightning.getCause() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.github.gaming32.bingo.triggers.BingoTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
Expand All @@ -18,15 +17,18 @@
@Mixin(RespawnAnchorBlock.class)
public class MixinRespawnAnchorBlock {
@Inject(
method = "use",
method = "useWithoutItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/block/RespawnAnchorBlock;explode(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V"
)
)
private void intentionalGameDesignTrigger(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> cir) {
private void intentionalGameDesignTrigger(
BlockState blockState, Level level, BlockPos blockPos, Player player, BlockHitResult blockHitResult,
CallbackInfoReturnable<InteractionResult> cir
) {
if (player instanceof ServerPlayer serverPlayer) {
BingoTriggers.INTENTIONAL_GAME_DESIGN.get().trigger(serverPlayer, pos);
BingoTriggers.INTENTIONAL_GAME_DESIGN.get().trigger(serverPlayer, blockPos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private void itemPickedUpTrigger(ItemEntity itemEntity, CallbackInfo ci) {
}

@Inject(method = "awardKillScore", at = @At("HEAD"))
@SuppressWarnings("UnreachableCode")
private void killSelfTrigger(Entity killed, int scoreValue, DamageSource source, CallbackInfo ci) {
if (killed == (Object)this) {
BingoTriggers.KILL_SELF.get().trigger((ServerPlayer)killed, source);
Expand All @@ -40,13 +41,15 @@ private void killSelfTrigger(Entity killed, int scoreValue, DamageSource source,
private void deathTrigger(DamageSource damageSource, CallbackInfo ci) {
BingoTriggers.DEATH.get().trigger((ServerPlayer)(Object)this, damageSource);
}

@Inject(
method = "checkMovementStatistics",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/stats/Stats;CROUCH_ONE_CM:Lnet/minecraft/resources/ResourceLocation;"
)
)
@SuppressWarnings("UnreachableCode")
private void sneakingTrigger(double distanceX, double distanceY, double distanceZ, CallbackInfo ci) {
if ((Object)this instanceof ServerPlayer serverPlayer) {
if (bingo$startSneakingPos == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MixinTargetBlock {
)
private static void preOutputPower(
LevelAccessor level, BlockState state, int power, BlockPos pos, int waitTime, Operation<Void> original,
@Local Entity projectileEntity
@Local(argsOnly = true) Entity projectileEntity
) {
if (!(projectileEntity instanceof Projectile projectile) || !(projectile.getOwner() instanceof Player player)) {
original.call(level, state, power, pos, waitTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MixinTrapDoorBlock {
target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"
)
)
private BlockState onDoorOpened(BlockState state, @Local Level level, @Local(ordinal = 0) BlockPos doorPos) {
private BlockState onDoorOpened(BlockState state, @Local(argsOnly = true) Level level, @Local(ordinal = 0, argsOnly = true) BlockPos doorPos) {
if (state.getValue(OPEN) && GlobalVars.CURRENT_PLAYER.get() instanceof ServerPlayer player) {
final Projectile projectile = GlobalVars.CURRENT_PROJECTILE.get();
final BlockPos targetPos = GlobalVars.CURRENT_BLOCK_POS.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
package io.github.gaming32.bingo.mixin.common.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import io.github.gaming32.bingo.client.BingoClient;
import io.github.gaming32.bingo.client.BoardScreen;
import io.github.gaming32.bingo.client.config.BingoClientConfig;
import io.github.gaming32.bingo.client.config.BoardCorner;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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;

@Mixin(Gui.class)
public class MixinGui {
@Shadow @Final private Minecraft minecraft;

@WrapOperation(
method = "render",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;renderEffects(Lnet/minecraft/client/gui/GuiGraphics;)V")
)
private void moveEffects(Gui instance, GuiGraphics guiGraphics, Operation<Void> original) {
final BingoClientConfig config = BingoClient.CONFIG;
if (
BingoClient.clientGame == null || config.getBoardCorner() != BoardCorner.UPPER_RIGHT ||
minecraft.getDebugOverlay().showDebugScreen() || minecraft.screen instanceof BoardScreen
) {
original.call(instance, guiGraphics);
return;
@Inject(method = "renderEffects", at = @At("HEAD"))
private void moveEffectsPre(GuiGraphics guiGraphics, float f, CallbackInfo ci) {
if (bingo$effectsNeedMoving()) {
final float scale = BingoClient.CONFIG.getBoardScale();
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(
(-BingoClient.getBoardWidth() - BingoClient.BOARD_OFFSET) * scale,
BingoClient.BOARD_OFFSET * scale, 0f
);
}
}

@Inject(method = "renderEffects", at = @At("RETURN"))
private void moveEffectsPost(GuiGraphics guiGraphics, float f, CallbackInfo ci) {
if (bingo$effectsNeedMoving()) {
guiGraphics.pose().popPose();
}
}

final float scale = config.getBoardScale();
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(
(-BingoClient.getBoardWidth() - BingoClient.BOARD_OFFSET) * scale,
BingoClient.BOARD_OFFSET * scale, 0f
);
original.call(instance, guiGraphics);
guiGraphics.pose().popPose();
@Unique
private boolean bingo$effectsNeedMoving() {
return BingoClient.clientGame != null && BingoClient.CONFIG.getBoardCorner() == BoardCorner.UPPER_RIGHT &&
!minecraft.getDebugOverlay().showDebugScreen() && !(minecraft.screen instanceof BoardScreen);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Type<ResyncStatesPacket> type() {
@Override
public void handle(BingoNetworking.Context context) {
if (BingoClient.clientGame == null) {
Bingo.LOGGER.warn("BingoClient.clientGame == null while handling " + TYPE + "!");
Bingo.LOGGER.warn("BingoClient.clientGame == null while handling {}!", TYPE);
return;
}
System.arraycopy(states, 0, BingoClient.clientGame.states(), 0, BingoClient.clientGame.size() * BingoClient.clientGame.size());
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/bingo-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"MixinDoorBlock",
"MixinEnchantmentMenu",
"MixinEntity",
"MixinEntitySubPredicate_Types",
"MixinFungusBlock",
"MixinGrindstoneMenu_4",
"MixinHangingEntityItem",
Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dependencies {
// }
// modRuntimeOnly("net.fabricmc.fabric-api:fabric-api-deprecated:${rootProject.fabric_api_version}") // Required by EMI

modImplementation("com.terraformersmc:modmenu:9.0.0-pre.1")
modImplementation("com.terraformersmc:modmenu:10.0.0-alpha.3")
}

tasks.processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixinHashCache_ProviderCache {
target = "Ljava/io/BufferedWriter;write(Ljava/lang/String;)V"
)
)
private void skipDate(BufferedWriter instance, String str, Operation<Void> original, @Local String date) {
private void skipDate(BufferedWriter instance, String str, Operation<Void> original, @Local(argsOnly = true) String date) {
//noinspection StringEquality
if (str != date) {
original.call(instance, str);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import com.llamalad7.mixinextras.sugar.Local;
import io.github.gaming32.bingo.fabric.event.FabricEvents;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,26 +19,25 @@
@Mixin(Level.class)
public class MixinLevel {
@Inject(
method = "explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;ZLnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)Lnet/minecraft/world/level/Explosion;",
method = "explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;ZLnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)Lnet/minecraft/world/level/Explosion;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Explosion;explode()V"
)
)
private void onExplosion(
Entity entity,
DamageSource damageSource,
ExplosionDamageCalculator explosionDamageCalculator,
@Nullable Entity entity,
@Nullable DamageSource damageSource,
@Nullable ExplosionDamageCalculator explosionDamageCalculator,
double d,
double e,
double f,
float g,
boolean bl,
Level.ExplosionInteraction explosionInteraction,
boolean bl2,
ParticleOptions particleOptions,
boolean bl2, ParticleOptions particleOptions,
ParticleOptions particleOptions2,
SoundEvent soundEvent,
Holder<SoundEvent> holder,
CallbackInfoReturnable<Explosion> cir,
@Local Explosion explosion
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class MixinMinecraft {
@Shadow @Nullable public LocalPlayer player;

@Inject(
method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V",
method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/Minecraft;gameMode:Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;",
opcode = Opcodes.PUTFIELD
)
)
private void onPlayerQuit(Screen nextScreen, CallbackInfo ci) {
private void onPlayerQuit(Screen screen, boolean bl, CallbackInfo ci) {
FabricClientEvents.PLAYER_QUIT.invoker().accept(player);
}
}
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"depends": {
"fabricloader": ">=0.15.6",
"fabric-api": ">=0.97.0",
"minecraft": "~1.20.5"
"minecraft": "~1.20.5-"
},
"custom": {
"loom:injected_interfaces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ private static void wrapApplyBoneMeal(
BlockPos pos,
BlockState state,
Operation<Void> operation,
@Local ItemStack boneMeal,
@Local Player player
@Local(argsOnly = true) ItemStack boneMeal,
@Local(argsOnly = true) Player player
) {
try (
var ignored = GlobalVars.CURRENT_PLAYER.push(player);
Expand Down

0 comments on commit 10c9b6e

Please sign in to comment.