Skip to content

Commit

Permalink
Always Revert To Small and Incoming Damage Multiplier gamerules now t…
Browse files Browse the repository at this point in the history
…ake effect
  • Loading branch information
floral-qua-floral committed Dec 20, 2024
1 parent c555cab commit cb47b45
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.fqf.mario_qua_mario.mariodata.MarioMoveableData;
import com.fqf.mario_qua_mario.mariodata.MarioPlayerData;
import com.fqf.mario_qua_mario.mariodata.injections.MarioDataHolder;
import com.fqf.mario_qua_mario.util.MarioGamerules;
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -70,4 +73,12 @@ public void writeCustomDataToNbt(NbtCompound nbt) {

nbt.put(MarioQuaMario.MOD_DATA_KEY, persistentData);
}

@WrapMethod(method = "damage")
private boolean damageHook(DamageSource source, float amount, Operation<Boolean> original) {
float factor;
if(mqm$getMarioData().isEnabled()) factor = (float) getWorld().getGameRules().get(MarioGamerules.INCOMING_DAMAGE_MULTIPLIER).get();
else factor = 1F;
return original.call(source, amount * factor);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.fqf.mario_qua_mario.util;

import com.fqf.mario_qua_mario.MarioQuaMario;
import com.fqf.mario_qua_mario.mariodata.MarioServerPlayerData;
import com.fqf.mario_qua_mario.registries.RegistryManager;
import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

import java.util.Objects;

public class MarioEventListeners {
public static void register() {
Expand All @@ -20,15 +25,23 @@ public static void register() {
data.assignAction(data.getCharacter().INITIAL_ACTION.ID);
});

ServerLivingEntityEvents.ALLOW_DAMAGE.register((livingEntity, damageSource, amount) -> {
ServerLivingEntityEvents.ALLOW_DEATH.register((livingEntity, damageSource, amount) -> {
if(!(livingEntity instanceof ServerPlayerEntity mario)) return true;

MarioServerPlayerData data = mario.mqm$getMarioData();
if(!data.isEnabled()) return true;

if(data.getPowerUp().REVERSION_TARGET_ID == null) return true;

data.revertTo(data.getPowerUp().REVERSION_TARGET_ID);
Identifier reversionTarget = data.getPowerUp().REVERSION_TARGET_ID;
if(reversionTarget == null) return true;

if(livingEntity.getWorld().getGameRules().getBoolean(MarioGamerules.REVERT_TO_SMALL)) {
MarioQuaMario.LOGGER.info("Forcing maximum possible reversion!");
while(Objects.requireNonNull(RegistryManager.POWER_UPS.get(reversionTarget)).REVERSION_TARGET_ID != null) {
reversionTarget = Objects.requireNonNull(RegistryManager.POWER_UPS.get(reversionTarget)).REVERSION_TARGET_ID;
}
}
data.revertTo(reversionTarget);
mario.setHealth(mario.getMaxHealth());
return false;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ public class MarioGamerules {
public static boolean useCharacterStats;

public static final GameRules.Key<GameRules.BooleanRule> USE_CHARACTER_STATS =
GameRuleRegistry.register(MarioQuaMario.makeID("useCharacterStats").toString(), GameRules.Category.PLAYER,
GameRuleRegistry.register("marioUseCharacterStats", GameRules.Category.PLAYER,
GameRuleFactory.createBooleanRule(true, (server, booleanRule) -> {
useCharacterStats = booleanRule.get();
MarioPackets.syncUseCharacterStatsS2C(useCharacterStats);
})
);

public static final GameRules.Key<GameRules.BooleanRule> REJECT_INVALID_ACTION_TRANSITIONS =
GameRuleRegistry.register(MarioQuaMario.makeID("rejectInvalidActionTransitions").toString(), GameRules.Category.PLAYER,
GameRuleRegistry.register("marioRejectInvalidActionTransitions", GameRules.Category.PLAYER,
GameRuleFactory.createBooleanRule(true));

public static final GameRules.Key<DoubleRule> INCOMING_DAMAGE_MULTIPLIER =
GameRuleRegistry.register(MarioQuaMario.makeID("marioIncomingDamageMultiplier").toString(), GameRules.Category.PLAYER,
GameRuleRegistry.register("marioIncomingDamageMultiplier", GameRules.Category.PLAYER,
GameRuleFactory.createDoubleRule(2.5));
// How to get value: marioWorld.getGameRules().get(MarioQuaMario.INCOMING_DAMAGE_MULTIPLIER).get()

public static final GameRules.Key<DoubleRule> OUTGOING_DAMAGE_MULTIPLIER =
GameRuleRegistry.register(MarioQuaMario.makeID("marioOutgoingDamageMultiplier").toString(), GameRules.Category.PLAYER,
GameRuleRegistry.register("marioOutgoingDamageMultiplier", GameRules.Category.PLAYER,
GameRuleFactory.createDoubleRule(1.0));

public static final GameRules.Key<GameRules.BooleanRule> REVERT_TO_SMALL =
GameRuleRegistry.register(MarioQuaMario.makeID("alwaysRevertToSmall").toString(), GameRules.Category.PLAYER,
GameRuleRegistry.register("marioAlwaysRevertToSmallForm", GameRules.Category.PLAYER,
GameRuleFactory.createBooleanRule(false));

public static void register() {
Expand Down

0 comments on commit cb47b45

Please sign in to comment.