Skip to content

Commit

Permalink
24w39a
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Sep 27, 2024
1 parent 8aefdf6 commit 9eda89a
Show file tree
Hide file tree
Showing 31 changed files with 227 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
package carpettisaddition.helpers.carpet.loggerRestriction;

import carpet.logging.Logger;
import carpettisaddition.CarpetTISAdditionMod;
import carpettisaddition.translations.Translator;
import carpettisaddition.utils.CarpetModUtil;
import carpettisaddition.utils.Messenger;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.BaseText;
import net.minecraft.text.ClickEvent;

Expand All @@ -51,15 +53,22 @@ public static void addLoggerRuleSwitch(Logger logger, String ruleName, Supplier<
translator.tr("permission_denied", logger.getLogName()),
translator.tr("rule_hint", ruleName)
);
if (CarpetModUtil.canUseCarpetCommand(player.getCommandSource()))
if (!(player instanceof ServerPlayerEntity))
{
CarpetTISAdditionMod.LOGGER.warn("subscriptionChecker receives a player {} that is not a ServerPlayerEntity", player);
return RestrictionCheckResult.ok();
}

ServerPlayerEntity serverPlayer = (ServerPlayerEntity)player; // for mc1.21.2+, where getCommandSource requires being on the server-side
if (CarpetModUtil.canUseCarpetCommand(serverPlayer.getCommandSource()))
{
Messenger.click(
message,
new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/carpet " + ruleName)
);
}
return RestrictionCheckResult.bool(
CarpetModUtil.canUseCommand(player.getCommandSource(), ruleValueProvider.get()),
CarpetModUtil.canUseCommand(serverPlayer.getCommandSource(), ruleValueProvider.get()),
message
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public interface RestrictiveLogger
{
void addSubscriptionRestriction(SubscriptionChecker subscriptionValidator);
void addSubscriptionRestriction(SubscriptionChecker subscriptionChecker);

RestrictionCheckResult canPlayerSubscribe(PlayerEntity player, @Nullable String option);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import carpettisaddition.commands.lifetime.utils.LifeTimeTrackerUtil;
import carpettisaddition.logging.TISAdditionLoggerRegistry;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;

public class LifeTimeStandardCarpetHUDLogger extends
//#if MC >= 11500
Expand All @@ -52,8 +53,8 @@ public LifeTimeStandardCarpetHUDLogger()
public void addPlayer(String playerName, String option)
{
super.addPlayer(playerName, option);
PlayerEntity player = this.playerFromName(playerName);
if (player != null)
ServerPlayerEntity player = this.playerFromName(playerName);
if (player instanceof ServerPlayerEntity)
{
if (!LifeTimeTrackerUtil.getEntityTypeFromName(option).isPresent())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public abstract class LoggerMixin implements RestrictiveLogger
{
private final List<SubscriptionChecker> subscriptionCheckers = Lists.newArrayList();

public void addSubscriptionRestriction(SubscriptionChecker subscriptionValidator)
public void addSubscriptionRestriction(SubscriptionChecker subscriptionChecker)
{
this.subscriptionCheckers.add(subscriptionValidator);
this.subscriptionCheckers.add(subscriptionChecker);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package carpettisaddition.mixins.command.lifetime.deathdamage;

import carpettisaddition.commands.lifetime.interfaces.DamageableEntity;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.damage.DamageSource;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -44,7 +45,7 @@ public abstract class ExperienceOrbEntityMixin implements DamageableEntity
//#endif
)
)
private void lifetimeTracker_recordDeathDamageSource_xpOrb(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void lifetimeTracker_recordDeathDamageSource_xpOrb(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) DamageSource source)
{
this.deathDamageSource = source;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
package carpettisaddition.mixins.command.lifetime.deathdamage;

import carpettisaddition.commands.lifetime.interfaces.DamageableEntity;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.damage.DamageSource;
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.CallbackInfoReturnable;

@Mixin(ItemEntity.class)
public abstract class ItemEntityMixin implements DamageableEntity
{
@Unique
private DamageSource deathDamageSource;

@Inject(
Expand All @@ -44,7 +47,7 @@ public abstract class ItemEntityMixin implements DamageableEntity
//#endif
)
)
private void lifetimeTracker_recordDeathDamageSource_item(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void lifetimeTracker_recordDeathDamageSource_item(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) DamageSource source)
{
this.deathDamageSource = source;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import carpettisaddition.commands.lifetime.interfaces.LifetimeTrackerTarget;
import carpettisaddition.commands.lifetime.removal.MobPickupRemovalReason;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
Expand All @@ -47,7 +48,7 @@ public DolphinEntityMixin(EntityType<?> type, World world)
target = "Lnet/minecraft/entity/passive/DolphinEntity;sendPickup(Lnet/minecraft/entity/Entity;I)V"
)
)
private void lifetimeTracker_recordRemoval_mobPickup_dolphinPickupItem(ItemEntity item, CallbackInfo ci)
private void lifetimeTracker_recordRemoval_mobPickup_dolphinPickupItem(CallbackInfo ci, @Local(argsOnly = true) ItemEntity item)
{
((LifetimeTrackerTarget)item).recordRemoval(new MobPickupRemovalReason(this.getType()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import carpettisaddition.commands.lifetime.interfaces.LifetimeTrackerTarget;
import carpettisaddition.commands.lifetime.removal.MobPickupRemovalReason;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
Expand All @@ -47,7 +48,7 @@ public FoxEntityMixin(EntityType<?> type, World world)
target = "Lnet/minecraft/entity/passive/FoxEntity;sendPickup(Lnet/minecraft/entity/Entity;I)V"
)
)
private void lifetimeTracker_recordRemoval_mobPickup_foxPickupItem(ItemEntity item, CallbackInfo ci)
private void lifetimeTracker_recordRemoval_mobPickup_foxPickupItem(CallbackInfo ci, @Local(argsOnly = true) ItemEntity item)
{
((LifetimeTrackerTarget)item).recordRemoval(new MobPickupRemovalReason(this.getType()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import carpettisaddition.commands.lifetime.interfaces.LifetimeTrackerTarget;
import carpettisaddition.commands.lifetime.removal.MobPickupRemovalReason;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand All @@ -44,10 +45,9 @@ public abstract class ItemEntityMixin
//#else
target = "Lnet/minecraft/entity/ItemEntity;remove()V"
//#endif
),
locals = LocalCapture.CAPTURE_FAILHARD
)
)
private void lifetimeTracker_recordRemoval_mobPickup_playerPickupItem(PlayerEntity player, CallbackInfo ci, ItemStack itemStack, Item item, int i)
private void lifetimeTracker_recordRemoval_mobPickup_playerPickupItem(PlayerEntity player, CallbackInfo ci, @Local ItemStack itemStack, @Local int i)
{
int stackCount = itemStack.getCount();
itemStack.setCount(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import carpettisaddition.commands.lifetime.interfaces.LifetimeTrackerTarget;
import carpettisaddition.commands.lifetime.removal.MobPickupRemovalReason;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -51,7 +52,7 @@ protected MobEntityMixin(EntityType<? extends LivingEntity> type, World world)
//#endif
)
)
private void lifetimeTracker_recordRemoval_mobPickup_mobEntityPickupItem(ItemEntity item, CallbackInfo ci)
private void lifetimeTracker_recordRemoval_mobPickup_mobEntityPickupItem(CallbackInfo ci, @Local(argsOnly = true) ItemEntity item)
{
((LifetimeTrackerTarget)item).recordRemoval(new MobPickupRemovalReason(this.getType()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public abstract class FoxEntityMateGoalMixin
method = "breed",
at = @At(
value = "INVOKE",
//#if MC >= 11600
//$$ target = "Lnet/minecraft/server/world/ServerWorld;spawnEntityAndPassengers(Lnet/minecraft/entity/Entity;)V"
//#else
target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z",
ordinal = 0
//#endif
)
)
private Entity lifetimeTracker_recordSpawning_breeding_foxMateGoal(Entity entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,33 @@

import carpettisaddition.commands.lifetime.interfaces.LifetimeTrackerTarget;
import carpettisaddition.commands.lifetime.spawning.MobDropSpawningReason;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Entity.class)
public abstract class EntityMixin
{
@Shadow public World world;

@Shadow public abstract EntityType<?> getType();

@Inject(method = "dropStack(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;", at = @At("RETURN"))
private void lifetimeTracker_recordSpawning_mobDrop_common(CallbackInfoReturnable<ItemEntity> cir)
@ModifyReturnValue(
//#if MC >= 12102
//$$ method = "dropStack(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;",
//#else
method = "dropStack(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/ItemEntity;",
//#endif
at = @At("RETURN")
)
private ItemEntity lifetimeTracker_recordSpawning_mobDrop_common(ItemEntity itemEntity)
{
ItemEntity itemEntity = cir.getReturnValue();
if (itemEntity != null)
{
((LifetimeTrackerTarget)itemEntity).recordSpawning(new MobDropSpawningReason(this.getType()));
}
return itemEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC >= 12102
//$$ import net.minecraft.server.world.ServerWorld;
//#endif

@Mixin(CommandBlock.class)
public abstract class CommandBlockMixin
{
Expand All @@ -42,7 +46,16 @@ public abstract class CommandBlockMixin
shift = At.Shift.AFTER
)
)
private void onCommandBlockExecutedCommandBlockLogger(BlockState state, World world, BlockPos pos, CommandBlockExecutor executor, boolean hasCommand, CallbackInfo ci)
private void onCommandBlockExecutedCommandBlockLogger(
BlockState state,
//#if MC >= 12102
//$$ ServerWorld world,
//#else
World world,
//#endif
BlockPos pos, CommandBlockExecutor executor, boolean hasCommand,
CallbackInfo ci
)
{
CommandBlockLogger.getInstance().onCommandBlockActivated(world, pos, state, executor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import carpettisaddition.logging.loggers.damage.interfaces.DamageLoggerTarget;
import carpettisaddition.logging.loggers.damage.modifyreasons.ModifyReason;
import carpettisaddition.logging.loggers.damage.modifyreasons.StatusEffectModifyReason;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffects;
Expand All @@ -37,6 +38,10 @@

import java.util.Optional;

//#if MC >= 12102
//$$ import net.minecraft.server.world.ServerWorld;
//#endif

// some same mixins
public abstract class LivingEntityAndPlayerEntityMixins
{
Expand All @@ -50,7 +55,7 @@ public static class ApplyDamageMixin
target = "Ljava/lang/Math;max(FF)F"
)
)
private void onAbsorptionReducedDamage(DamageSource source, float amount, CallbackInfo ci)
private void onAbsorptionReducedDamage(CallbackInfo ci, @Local(argsOnly = true) float amount)
{
((DamageLoggerTarget) this).getDamageTracker().ifPresent(tracker -> tracker.modifyDamage(
amount, new StatusEffectModifyReason(StatusEffects.ABSORPTION)
Expand All @@ -59,13 +64,23 @@ amount, new StatusEffectModifyReason(StatusEffects.ABSORPTION)

// at the end of damage calculation
@Inject(method = "applyDamage", at = @At("RETURN"))
private void onDamageApplyDone(DamageSource source, float amount, CallbackInfo ci)
private void onDamageApplyDone(
CallbackInfo ci, @Local(argsOnly = true) DamageSource source, @Local(argsOnly = true) float amount
//#if MC >= 12102
//$$ , @Local(argsOnly = true) ServerWorld serverWorld
//#endif
)
{
if (DamageLogger.isLoggerActivated())
{
LivingEntity entity = (LivingEntity) (Object) this;
Optional<DamageLogger.Tracker> logger = ((DamageLoggerTarget) this).getDamageTracker();
if (entity.isInvulnerableTo(source))
if (entity.isInvulnerableTo(
//#if MC >= 12102
//$$ serverWorld,
//#endif
source
))
{
amount = 0.0F;
logger.ifPresent(tracker -> tracker.modifyDamage(0.0F, ModifyReason.IMMUNE));
Expand All @@ -80,7 +95,7 @@ private void onDamageApplyDone(DamageSource source, float amount, CallbackInfo c
public static class DamageMixin
{
@Inject(method = "damage", at = @At(value = "RETURN"))
private void onDamageEnded(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void onDamageEnded(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) float amount)
{
if (DamageLogger.isLoggerActivated())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import carpettisaddition.logging.loggers.damage.modifyreasons.EnchantmentModifyReason;
import carpettisaddition.logging.loggers.damage.modifyreasons.ModifyReason;
import carpettisaddition.logging.loggers.damage.modifyreasons.StatusEffectModifyReason;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void setDamageTracker(@Nullable DamageLogger.Tracker tracker)
target = "Lnet/minecraft/entity/LivingEntity;isSleeping()Z"
)
)
private void onDamageStarted(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void onDamageStarted(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) DamageSource source, @Local(argsOnly = true) float amount)
{
DamageLogger.create((LivingEntity)(Object)this, source, amount);
}
Expand All @@ -107,7 +108,7 @@ private void onDamageStarted(DamageSource source, float amount, CallbackInfoRetu
args = "floatValue=0.75F"
)
)
private void onHelmetReducedAnvilDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void onHelmetReducedAnvilDamage(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) float amount)
{
this.getDamageTracker().ifPresent(tracker -> tracker.modifyDamage(amount * 0.75F, ModifyReason.HELMET));
}
Expand All @@ -131,7 +132,7 @@ private void onHelmetReducedAnvilDamage(DamageSource source, float amount, Callb
ordinal = 0
)
)
private void onShieldReducedDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void onShieldReducedDamage(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) float amount)
{
this.getDamageTracker().ifPresent(tracker -> tracker.modifyDamage(amount, ModifyReason.SHIELD));
}
Expand All @@ -148,7 +149,7 @@ private void onShieldReducedDamage(DamageSource source, float amount, CallbackIn
ordinal = 0
)
)
private void onRecentHintReducedDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir)
private void onRecentHintReducedDamage(CallbackInfoReturnable<Boolean> cir, @Local(argsOnly = true) float amount)
{
final float last =
//#if MC >= 11500
Expand Down
Loading

0 comments on commit 9eda89a

Please sign in to comment.