Update mixins

This commit is contained in:
DBotThePony 2024-08-26 20:14:46 +07:00
parent cb276da292
commit e3990d7fb5
Signed by: DBot
GPG Key ID: DCC23B5715498507
18 changed files with 157 additions and 134 deletions

View File

@ -16,7 +16,8 @@ import ru.dbotthepony.mc.otm.core.MultiblockKt;
public abstract class BlockEntityMixin {
@Inject(
at = @At("TAIL"),
method = "setRemoved()V"
method = "setRemoved()V",
remap = false
)
public void setRemovedListener(CallbackInfo ci) {
MultiblockKt.onBlockEntityInvalidated((BlockEntity) (Object) this);

View File

@ -9,7 +9,7 @@ import ru.dbotthepony.mc.otm.compat.vanilla.MatteryChestMenu;
@Mixin(DispenserBlockEntity.class)
public abstract class DispenserBlockEntityMixin {
@Overwrite
@Overwrite(remap = false)
public AbstractContainerMenu createMenu(int p_59312_, Inventory p_59313_) {
return MatteryChestMenu.c3x3(p_59312_, p_59313_, (DispenserBlockEntity) (Object) this);
}

View File

@ -1,24 +0,0 @@
package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
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.CallbackInfoReturnable;
import ru.dbotthepony.mc.otm.item.weapon.EnergySwordItem;
@Mixin(EnchantmentHelper.class)
public class EnchantmentHelperMixin {
@Inject(
method = "getSweepingDamageRatio(Lnet/minecraft/world/entity/LivingEntity;)F",
at = @At("HEAD"),
cancellable = true)
private static void getSweepingDamageRatio(LivingEntity p_44822_, CallbackInfoReturnable<Float> info) {
var result = EnergySwordItem.getSweepingDamageRatioHook(p_44822_);
if (result != null) {
info.setReturnValue(result);
}
}
}

View File

@ -8,26 +8,29 @@ 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.CallbackInfo;
import ru.dbotthepony.mc.otm.capability.IMatteryPlayer;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
@Mixin(FoodData.class)
public class FoodDataMixin {
@Shadow
@Shadow(remap = false)
private int lastFoodLevel;
@Shadow
@Shadow(remap = false)
private int tickTimer;
@Shadow
@Shadow(remap = false)
private int foodLevel;
@Shadow
@Shadow(remap = false)
private float exhaustionLevel;
@Inject(
method = "tick(Lnet/minecraft/world/entity/player/Player;)V",
at = @At("HEAD"),
remap = false,
cancellable = true
)
private void tick(Player player, CallbackInfo info) {
player.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(it -> {
var it = ((IMatteryPlayer) player).getOtmPlayer();
if (it.isAndroid()) {
info.cancel();
@ -44,6 +47,5 @@ public class FoodDataMixin {
// а так же не регенерируем
// ну и не получаем урон от "голодания"
}
});
}
}

View File

@ -12,13 +12,13 @@ import static ru.dbotthepony.mc.otm.client.render.RenderHelperKt.pushScissorRect
// mostly because it is not a stack at all.
@Mixin(GuiGraphics.class)
public abstract class GuiGraphicsMixin {
@Overwrite
@Overwrite(remap = false)
public void enableScissor(int x0, int y0, int x1, int y1) {
double scale = Minecraft.getInstance().getWindow().getGuiScale();
pushScissorRect((int) (scale * x0), (int) (scale * y0), (int) (scale * (x1 - x0)), (int) (scale * (y1 - y0)));
}
@Overwrite
@Overwrite(remap = false)
public void disableScissor() {
popScissorRect();
}

View File

@ -9,7 +9,7 @@ import ru.dbotthepony.mc.otm.compat.vanilla.MatteryChestMenu;
@Mixin(HopperBlockEntity.class)
public abstract class HopperBlockEntityMixin {
@Overwrite
@Overwrite(remap = false)
public AbstractContainerMenu createMenu(int p_59312_, Inventory p_59313_) {
return MatteryChestMenu.hopper(p_59312_, p_59313_, (HopperBlockEntity) (Object) this);
}

View File

@ -10,12 +10,12 @@ import ru.dbotthepony.mc.otm.triggers.MatteryInventoryChangeTrigger;
@Mixin(InventoryChangeTrigger.class)
public abstract class InventoryChangeTriggerMixin {
@Overwrite
@Overwrite(remap = false)
public void trigger(ServerPlayer p_43150_, Inventory p_43151_, ItemStack p_43152_) {
MatteryInventoryChangeTrigger.INSTANCE.trigger(p_43150_, p_43151_, p_43152_);
}
@Overwrite
@Overwrite(remap = false)
private void trigger(ServerPlayer p_43154_, Inventory p_43155_, ItemStack p_43156_, int p_43157_, int p_43158_, int p_43159_) {
MatteryInventoryChangeTrigger.INSTANCE.trigger(p_43154_, p_43155_, p_43156_, p_43157_, p_43158_, p_43159_);
}

View File

@ -8,29 +8,26 @@ 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.CallbackInfoReturnable;
import ru.dbotthepony.mc.otm.capability.IMatteryPlayer;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.registry.MSoundEvents;
@Mixin(AbstractHurtingProjectile.class)
public class MixinAbstractHurtingProjectile {
@Inject(
method = "hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;markHurt()V",
ordinal = 0
method = "onDeflection(Lnet/minecraft/world/entity/Entity;Z)V",
remap = false,
at = @At("TAIL")
)
)
public void onProjectileHit(DamageSource pSource, float pAmount, CallbackInfoReturnable<Boolean> cir) {
Entity entity = pSource.getEntity();
if (entity == null) return;
public void onDeflection(Entity entity, boolean byAttack, CallbackInfoReturnable<Boolean> cir) {
if (entity instanceof IMatteryPlayer player) {
var cap = player.getOtmPlayer();
entity.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(cap -> {
AbstractHurtingProjectile proj = (AbstractHurtingProjectile)(Object)this;
if (cap.isAndroid() && proj.getOwner() != entity) {
entity.level().playSound(entity, proj.blockPosition(), MSoundEvents.INSTANCE.getANDROID_PROJ_PARRY(), SoundSource.PLAYERS, 1.0f, 0.95f + entity.level().random.nextFloat() * 0.1f);
}
});
}
}
}

View File

@ -14,6 +14,7 @@ public class MixinAnvilBlock {
@Inject(
method = "damage(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/block/state/BlockState;",
at = @At("HEAD"),
remap = false,
cancellable = true)
private static void damage(BlockState pState, CallbackInfoReturnable<BlockState> info) {
var list = MBlocks.INSTANCE.getTRITANIUM_ANVIL();

View File

@ -13,8 +13,10 @@ import ru.dbotthepony.mc.otm.client.render.RenderHelperKt;
public class MixinGameRenderer {
@Inject(
method = "render(FJZ)V",
remap = false,
at = @At(
value = "INVOKE",
remap = false,
target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;bindWrite(Z)V"
)
)
@ -24,6 +26,7 @@ public class MixinGameRenderer {
@Inject(
method = "reloadShaders(Lnet/minecraft/server/packs/resources/ResourceProvider;)V",
remap = false,
at = @At("HEAD")
)
private void reloadShaders(ResourceProvider p_250719_, CallbackInfo ci) {

View File

@ -3,13 +3,13 @@ package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.Container;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.ForgeRegistries;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.capability.IMatteryPlayer;
import ru.dbotthepony.mc.otm.capability.MatteryPlayer;
import java.util.function.Predicate;
@ -25,12 +25,13 @@ import java.util.function.Predicate;
@Mixin(Inventory.class)
public class MixinInventory {
@Final
@Shadow
@Shadow(remap = false)
public Player player;
@Inject(
method = "add(ILnet/minecraft/world/item/ItemStack;)Z",
at = @At("HEAD"),
remap = false,
cancellable = true
)
private void add(int pSlot, ItemStack pStack, CallbackInfoReturnable<Boolean> hook) {
@ -39,25 +40,24 @@ public class MixinInventory {
}
if (pSlot == -1) {
this.player.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(it -> {
try {
hook.setReturnValue(it.inventoryAddImpl(pStack));
hook.setReturnValue(((IMatteryPlayer) this.player).getOtmPlayer().inventoryAddImpl(pStack));
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Adding item to inventory (Overdrive That Matters detour)");
CrashReportCategory crashreportcategory = crashreport.addCategory("Item being added");
crashreportcategory.setDetail("Registry Name", () -> String.valueOf(ForgeRegistries.ITEMS.getKey(pStack.getItem())));
crashreportcategory.setDetail("Registry Name", () -> String.valueOf(BuiltInRegistries.ITEM.getKey(pStack.getItem())));
crashreportcategory.setDetail("Item Class", () -> pStack.getItem().getClass().getName());
crashreportcategory.setDetail("Item ID", Item.getId(pStack.getItem()));
crashreportcategory.setDetail("Item data", pStack.getDamageValue());
crashreportcategory.setDetail("Item name", () -> pStack.getHoverName().getString());
throw new ReportedException(crashreport);
}
});
}
}
@Inject(
method = "dropAll()V",
remap = false,
at = @At("TAIL")
)
private void dropAll(CallbackInfo ci) {
@ -66,6 +66,7 @@ public class MixinInventory {
@Inject(
method = "clearContent()V",
remap = false,
at = @At("TAIL")
)
private void clearContent(CallbackInfo ci) {
@ -74,17 +75,17 @@ public class MixinInventory {
@Inject(
method = "clearOrCountMatchingItems(Ljava/util/function/Predicate;ILnet/minecraft/world/Container;)I",
remap = false,
at = @At("RETURN"),
cancellable = true
)
private void clearOrCountMatchingItems(Predicate<ItemStack> predicate, int count, Container container, CallbackInfoReturnable<Integer> cir) {
player.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(it -> {
var it = ((IMatteryPlayer) this.player).getOtmPlayer();
if (!it.getHasExopack()) return;
int i = cir.getReturnValue();
i += ContainerHelper.clearOrCountMatchingItems(it.getExopackContainer(), predicate, count - i, count == 0);
cir.setReturnValue(i);
});
}
}

View File

@ -1,14 +1,16 @@
package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.ForgeEventFactory;
import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.Nullable;
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.CallbackInfo;
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
import ru.dbotthepony.mc.otm.capability.IMatteryPlayer;
import ru.dbotthepony.mc.otm.config.ServerConfig;
import ru.dbotthepony.mc.otm.core.util.ExperienceUtilsKt;
import ru.dbotthepony.mc.otm.registry.MItems;
@ -16,18 +18,20 @@ import ru.dbotthepony.mc.otm.registry.MItems;
@SuppressWarnings("ConstantConditions")
@Mixin(LivingEntity.class)
public class MixinLivingEntity {
@Shadow
@Shadow(remap = false)
@Nullable
protected Player lastHurtByPlayer;
@Inject(
method = "dropExperience()V",
method = "dropExperience(Lnet/minecraft/world/entity/Entity;)V",
remap = false,
at = @At("HEAD"),
cancellable = true)
public void dropExperience(CallbackInfo hook) {
public void dropExperience(@Nullable Entity killer, CallbackInfo hook) {
if (((Object) this) instanceof Player player && ServerConfig.INSTANCE.getDROP_EXPERIENCE_CAPSULES()) {
player.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresent(it -> {
hook.cancel();
var android = ((IMatteryPlayer) player).getOtmPlayer();
long totalExperience = ExperienceUtilsKt.getTotalXpRequiredForLevel(player.experienceLevel);
totalExperience += (long) (player.experienceProgress * player.getXpNeededForNextLevel());
@ -46,23 +50,22 @@ public class MixinLivingEntity {
}
if (totalExperience >= Integer.MAX_VALUE) {
int hooked = ForgeEventFactory.getExperienceDrop(player, lastHurtByPlayer, Integer.MAX_VALUE);
int hooked = EventHooks.getExperienceDrop(player, lastHurtByPlayer, Integer.MAX_VALUE);
if (hooked != Integer.MAX_VALUE) {
totalExperience = hooked;
}
} else {
totalExperience = ForgeEventFactory.getExperienceDrop(player, lastHurtByPlayer, (int) totalExperience);
totalExperience = EventHooks.getExperienceDrop(player, lastHurtByPlayer, (int) totalExperience);
}
if (totalExperience > 0L) {
if (it.isAndroid()) {
if (android.isAndroid()) {
player.drop(MItems.INSTANCE.getESSENCE_DRIVE().make(totalExperience), true, false);
} else {
player.drop(MItems.INSTANCE.getESSENCE_CAPSULE().make(totalExperience), true, false);
}
}
});
}
}
}

View File

@ -12,8 +12,10 @@ import ru.dbotthepony.mc.otm.capability.MatteryPlayer;
public class MixinMinecraft {
@Redirect(
method = "pickBlock()V",
remap = false,
at = @At(
value = "INVOKE",
remap = false,
target = "Lnet/minecraft/world/entity/player/Inventory;findSlotMatchingItem(Lnet/minecraft/world/item/ItemStack;)I"
)
)

View File

@ -27,6 +27,7 @@ public class MixinPlayer implements IMatteryPlayer {
@Inject(
method = "getProjectile(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;",
remap = false,
at = @At(
value = "INVOKE",
target = "net.minecraftforge.common.ForgeHooks.getProjectile(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;",
@ -45,6 +46,7 @@ public class MixinPlayer implements IMatteryPlayer {
@Inject(
method = "destroyVanishingCursedItems()V",
remap = false,
at = @At("TAIL")
)
private void destroyVanishingCursedItems(CallbackInfo ci) {
@ -55,6 +57,7 @@ public class MixinPlayer implements IMatteryPlayer {
@Inject(
method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;FLcom/mojang/authlib/GameProfile;)V",
remap = false,
at = @At("TAIL")
)
private void constructOtmPlayer(Level p_250508_, BlockPos p_250289_, float p_251702_, GameProfile p_252153_, CallbackInfo ci) {
@ -69,6 +72,7 @@ public class MixinPlayer implements IMatteryPlayer {
@Inject(
method = "addAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V",
remap = false,
at = @At("TAIL")
)
private void addAdditionalSaveData(CompoundTag data, CallbackInfo ci) {
@ -77,6 +81,7 @@ public class MixinPlayer implements IMatteryPlayer {
@Inject(
method = "readAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V",
remap = false,
at = @At("TAIL")
)
private void readAdditionalSaveData(CompoundTag data, CallbackInfo ci) {

View File

@ -19,6 +19,7 @@ public abstract class SimpleCriterionTriggerMixin implements CriterionTrigger<Cr
@Inject(
method = "removePlayerListener(Lnet/minecraft/server/PlayerAdvancements;Lnet/minecraft/advancements/CriterionTrigger$Listener;)V",
at = @At("HEAD"),
remap = false,
cancellable = true
)
public void removePlayerListener(PlayerAdvancements p_66254_, CriterionTrigger.Listener p_66255_, CallbackInfo info) {
@ -31,6 +32,7 @@ public abstract class SimpleCriterionTriggerMixin implements CriterionTrigger<Cr
@Inject(
method = "addPlayerListener(Lnet/minecraft/server/PlayerAdvancements;Lnet/minecraft/advancements/CriterionTrigger$Listener;)V",
at = @At("HEAD"),
remap = false,
cancellable = true
)
public void addPlayerListener(PlayerAdvancements p_66254_, CriterionTrigger.Listener p_66255_, CallbackInfo info) {
@ -43,6 +45,7 @@ public abstract class SimpleCriterionTriggerMixin implements CriterionTrigger<Cr
@Inject(
method = "removePlayerListeners(Lnet/minecraft/server/PlayerAdvancements;)V",
at = @At("HEAD"),
remap = false,
cancellable = true
)
public void removePlayerListeners(PlayerAdvancements p_66254_, CallbackInfo info) {

View File

@ -1,8 +1,12 @@
package ru.dbotthepony.mc.otm.mixin;
import net.minecraft.client.User;
import net.minecraft.client.resources.SplashManager;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.neoforged.fml.ModList;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -10,14 +14,19 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.Locale;
@Mixin(SplashManager.class)
public abstract class SplashManagerMixin {
@Shadow
public List<String> splashes;
@Shadow(remap = false)
private List<String> splashes;
@Shadow(remap = false)
@Nullable
private User user;
@Inject(
at = @At("TAIL"),
remap = false,
method = "apply(Ljava/util/List;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V"
)
public void otmSplashes(List<String> splashes, ResourceManager p_118879_, ProfilerFiller p_118880_, CallbackInfo ci) {
@ -29,12 +38,41 @@ public abstract class SplashManagerMixin {
this.splashes.add("As it was 13 nanoseconds ago!");
this.splashes.add("Smart AI is smart enough to fail Turing test!");
this.splashes.add("Neural computing!");
this.splashes.add("Swimming through quantum field!");
this.splashes.add("Swimming through quantum fields!");
this.splashes.add("For biological and digital alike!");
this.splashes.add("Digital is the next form of Biological!");
this.splashes.add("Also try Starbound!");
this.splashes.add("Also try No Man's Sky!");
this.splashes.add("Also try Factorio!");
if (ModList.get().isLoaded("jei")) {
this.splashes.add("E in JEI stands for Extraterrestrial!");
}
this.splashes.add("Smarter than Smart Cities!");
if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("tin_")))
this.splashes.add("Induction stove compatible!");
if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("lead_")))
this.splashes.add("Lead free!");
if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("electrum_")))
this.splashes.add("Somehow does not come with electrum!");
if (BuiltInRegistries.ITEM.keySet().stream().noneMatch((it) -> it.getPath().contains("silver_")))
this.splashes.add("Non-complementary to gold!");
if (this.user != null) {
var username = this.user.getName();
this.splashes.add("Say no more, " + username + "!");
this.splashes.add(username + ", and here comes the quarks!");
if (ModList.get().isLoaded("ad_astra")) {
this.splashes.add("Such a weird choice for Space Faring mod, " + username + "...");
}
}
}
}

View File

@ -48,6 +48,7 @@ class EnergySwordItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.RARE)
builder.add(Attributes.ATTACK_DAMAGE, AttributeModifier(BASE_ATTACK_DAMAGE_ID, 11.0, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND)
builder.add(Attributes.ATTACK_SPEED, AttributeModifier(BASE_ATTACK_SPEED_ID, -2.4, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND)
builder.add(Attributes.SWEEPING_DAMAGE_RATIO, AttributeModifier(ResourceLocation(OverdriveThatMatters.MOD_ID, "energy_sword_sweeping_edge"), 1.0, AttributeModifier.Operation.ADD_VALUE), EquipmentSlotGroup.MAINHAND)
chargedAttributes = builder.build()
builder = ItemAttributeModifiers.builder()
@ -214,14 +215,5 @@ class EnergySwordItem : MatteryItem(Properties().stacksTo(1).rarity(Rarity.RARE)
builder.pop()
}
@JvmStatic
fun getSweepingDamageRatioHook(ply: LivingEntity): Float? {
if (ply.mainHandItem.item is EnergySwordItem && ply.mainHandItem.matteryEnergy?.extractEnergyExact(ENERGY_PER_SWING, true) == true) {
return 1f
}
return null
}
}
}

View File

@ -7,7 +7,6 @@
"refmap": "overdrive_that_matters.refmap.json",
"mixins": [
"BlockEntityMixin",
"EnchantmentHelperMixin",
"FoodDataMixin",
"MixinLivingEntity",
"MixinAnvilBlock",