mirror of
https://github.com/architectury/architectury-api.git
synced 2026-04-02 13:37:43 -05:00
More hooks
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.PlayerEvent;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.FurnaceResultSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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;
|
||||
|
||||
@Mixin(FurnaceResultSlot.class)
|
||||
public class MixinFurnaceResultSlot {
|
||||
@Shadow @Final private Player player;
|
||||
|
||||
@Inject(method = "checkTakeAchievements", at = @At("RETURN"))
|
||||
private void checkTakeAchievements(ItemStack itemStack, CallbackInfo ci) {
|
||||
PlayerEvent.SMELT_ITEM.invoker().smelt(player, itemStack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.PlayerEvent;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
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;
|
||||
|
||||
@Mixin(ItemEntity.class)
|
||||
public abstract class MixinItemEntity {
|
||||
@Shadow
|
||||
public abstract ItemStack getItem();
|
||||
|
||||
@Inject(method = "playerTouch",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getCount()I"), cancellable = true)
|
||||
private void prePickup(Player player, CallbackInfo ci) {
|
||||
InteractionResult canPickUp = PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(player, (ItemEntity) (Object) this, getItem());
|
||||
if (canPickUp == InteractionResult.FAIL) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "playerTouch",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;take(Lnet/minecraft/world/entity/Entity;I)V"))
|
||||
private void pickup(Player player, CallbackInfo ci) {
|
||||
PlayerEvent.PICKUP_ITEM_POST.invoker().pickup(player, (ItemEntity) (Object) this, getItem());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.EntityEvent;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class MixinLivingEntity {
|
||||
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
|
||||
private void hurt(DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
|
||||
if ((Object) this instanceof Player) return;
|
||||
if (EntityEvent.LIVING_ATTACK.invoker().attack((LivingEntity) (Object) this, damageSource, f) == InteractionResult.FAIL) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,18 @@
|
||||
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.EntityEvent;
|
||||
import me.shedaniel.architectury.event.events.LifecycleEvent;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.ProgressListener;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ServerLevel.class)
|
||||
public class MixinServerLevel {
|
||||
@@ -30,4 +35,28 @@ public class MixinServerLevel {
|
||||
private void save(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) {
|
||||
LifecycleEvent.SERVER_WORLD_SAVE.invoker().act((ServerLevel) (Object) this);
|
||||
}
|
||||
|
||||
@Inject(method = "addEntity", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;getChunk(IILnet/minecraft/world/level/chunk/ChunkStatus;Z)Lnet/minecraft/world/level/chunk/ChunkAccess;"),
|
||||
cancellable = true)
|
||||
private void addEntity(Entity entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (EntityEvent.ADD.invoker().add(entity, (ServerLevel) (Object) this) == InteractionResult.FAIL) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "addPlayer", at = @At("HEAD"), cancellable = true)
|
||||
private void addPlayer(ServerPlayer serverPlayer, CallbackInfo ci) {
|
||||
if (EntityEvent.ADD.invoker().add(serverPlayer, (ServerLevel) (Object) this) == InteractionResult.FAIL) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "loadFromChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;add(Lnet/minecraft/world/entity/Entity;)V"),
|
||||
cancellable = true)
|
||||
private void loadFromChunk(Entity entity, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (EntityEvent.ADD.invoker().add(entity, (ServerLevel) (Object) this) == InteractionResult.FAIL) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.EntityEvent;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.player.RemotePlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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;
|
||||
|
||||
@Mixin(value = {LocalPlayer.class, Player.class, RemotePlayer.class})
|
||||
public class PlayerAttackInvoker {
|
||||
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
|
||||
private void hurt(DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (EntityEvent.LIVING_ATTACK.invoker().attack((LivingEntity) (Object) this, damageSource, f) == InteractionResult.FAIL && (Object) this instanceof Player) {
|
||||
cir.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package me.shedaniel.architectury.mixin.fabric.client;
|
||||
|
||||
import me.shedaniel.architectury.event.events.EntityEvent;
|
||||
import me.shedaniel.architectury.event.events.LifecycleEvent;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -37,4 +40,11 @@ public class MixinClientLevel {
|
||||
private void construct(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, int i, Supplier<ProfilerFiller> supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
|
||||
LifecycleEvent.CLIENT_WORLD_LOAD.invoker().act((ClientLevel) (Object) this);
|
||||
}
|
||||
|
||||
@Inject(method = "addEntity", at = @At("HEAD"), cancellable = true)
|
||||
private void addEntity(int i, Entity entity, CallbackInfo ci) {
|
||||
if (EntityEvent.ADD.invoker().add(entity, (ClientLevel) (Object) this) == InteractionResult.FAIL) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package me.shedaniel.architectury.registry.fabric;
|
||||
|
||||
import me.shedaniel.architectury.registry.BlockProperties;
|
||||
import me.shedaniel.architectury.registry.ToolType;
|
||||
import net.fabricmc.fabric.impl.object.builder.BlockSettingsInternals;
|
||||
import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BlockPropertiesImpl implements BlockProperties.Impl {
|
||||
@Override
|
||||
public BlockProperties of(Material material, MaterialColor color) {
|
||||
return new Impl(material, (state) -> color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockProperties of(Material material, Function<BlockState, MaterialColor> color) {
|
||||
return new Impl(material, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockProperties copy(BlockBehaviour old) {
|
||||
return copy(old.properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockProperties copy(BlockBehaviour.Properties old) {
|
||||
BlockProperties properties = of(old.material, old.materialColor);
|
||||
properties.material = old.material;
|
||||
properties.destroyTime = old.destroyTime;
|
||||
properties.explosionResistance = old.explosionResistance;
|
||||
properties.hasCollision = old.hasCollision;
|
||||
properties.isRandomlyTicking = old.isRandomlyTicking;
|
||||
properties.lightEmission = old.lightEmission;
|
||||
properties.materialColor = old.materialColor;
|
||||
properties.soundType = old.soundType;
|
||||
properties.friction = old.friction;
|
||||
properties.speedFactor = old.speedFactor;
|
||||
properties.dynamicShape = old.dynamicShape;
|
||||
properties.canOcclude = old.canOcclude;
|
||||
properties.isAir = old.isAir;
|
||||
properties.requiresCorrectToolForDrops = old.requiresCorrectToolForDrops;
|
||||
BlockSettingsInternals otherInternals = (BlockSettingsInternals) old;
|
||||
FabricBlockInternals.ExtraData extraData = otherInternals.getExtraData();
|
||||
if (extraData != null) {
|
||||
((BlockSettingsInternals) this).setExtraData(extraData);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static final class Impl extends BlockProperties {
|
||||
public Impl(Material material, Function<BlockState, MaterialColor> function) {
|
||||
super(material, function);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockProperties tool(ToolType type, int level) {
|
||||
FabricBlockInternals.computeExtraData(this).addMiningLevel(type.fabricTag.get(), level);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.shedaniel.architectury.registry.fabric;
|
||||
|
||||
import me.shedaniel.architectury.registry.ToolType;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
public class ToolTypeImpl implements ToolType.Impl {
|
||||
@Override
|
||||
public Tag<Item> pickaxeTag() {
|
||||
return FabricToolTags.PICKAXES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<Item> axeTag() {
|
||||
return FabricToolTags.AXES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<Item> hoeTag() {
|
||||
return FabricToolTags.HOES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<Item> shovelTag() {
|
||||
return FabricToolTags.SHOVELS;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,49 @@
|
||||
accessWidener v1 named
|
||||
accessible method net/minecraft/client/gui/screens/Screen addButton (Lnet/minecraft/client/gui/components/AbstractWidget;)Lnet/minecraft/client/gui/components/AbstractWidget;
|
||||
accessible method net/minecraft/client/gui/screens/Screen addWidget (Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;
|
||||
accessible field net/minecraft/client/gui/screens/Screen buttons Ljava/util/List;
|
||||
accessible field net/minecraft/client/gui/screens/Screen buttons Ljava/util/List;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour properties Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties material Lnet/minecraft/world/level/material/Material;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties material Lnet/minecraft/world/level/material/Material;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties materialColor Ljava/util/function/Function;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties materialColor Ljava/util/function/Function;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasCollision Z
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasCollision Z
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties soundType Lnet/minecraft/world/level/block/SoundType;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties soundType Lnet/minecraft/world/level/block/SoundType;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties lightEmission Ljava/util/function/ToIntFunction;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties lightEmission Ljava/util/function/ToIntFunction;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties explosionResistance F
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties explosionResistance F
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties destroyTime F
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties destroyTime F
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties requiresCorrectToolForDrops Z
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties requiresCorrectToolForDrops Z
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isRandomlyTicking Z
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties isRandomlyTicking Z
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties friction F
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties friction F
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties speedFactor F
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties speedFactor F
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties jumpFactor F
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties jumpFactor F
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties drops Lnet/minecraft/resources/ResourceLocation;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties drops Lnet/minecraft/resources/ResourceLocation;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties canOcclude Z
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties canOcclude Z
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isAir Z
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties isAir Z
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isValidSpawn Lnet/minecraft/world/level/block/state/BlockBehaviour$StateArgumentPredicate;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties isValidSpawn Lnet/minecraft/world/level/block/state/BlockBehaviour$StateArgumentPredicate;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isRedstoneConductor Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties isRedstoneConductor Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isSuffocating Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties isSuffocating Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isViewBlocking Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties isViewBlocking Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasPostProcess Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasPostProcess Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties emissiveRendering Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties emissiveRendering Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
|
||||
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties dynamicShape Z
|
||||
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties dynamicShape Z
|
||||
@@ -12,8 +12,9 @@
|
||||
"client.MixinScreen"
|
||||
],
|
||||
"mixins": [
|
||||
"ExplosionPreInvoker", "LivingDeathInvoker", "MixinCommands", "MixinExplosion", "MixinPlayer", "MixinPlayerAdvancements", "MixinPlayerList",
|
||||
"MixinServerGamePacketListenerImpl", "MixinServerLevel", "MixinServerPlayer"
|
||||
"ExplosionPreInvoker", "LivingDeathInvoker", "MixinCommands", "MixinExplosion", "MixinFurnaceResultSlot", "MixinItemEntity", "MixinLivingEntity",
|
||||
"MixinPlayer", "MixinPlayerAdvancements", "MixinPlayerList", "MixinServerGamePacketListenerImpl", "MixinServerLevel", "MixinServerPlayer",
|
||||
"PlayerAttackInvoker"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user