-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 秋雨落 <i@rain.cx>
- Loading branch information
Showing
28 changed files
with
397 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...main/java/io/izzel/arclight/common/mixin/core/server/level/ServerPlayerMixin_Vanilla.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.izzel.arclight.common.mixin.core.server.level; | ||
|
||
import com.mojang.datafixers.util.Either; | ||
import io.izzel.arclight.api.ArclightPlatform; | ||
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; | ||
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.*; | ||
import net.minecraft.util.Unit; | ||
import net.minecraft.world.entity.player.Player; | ||
import org.bukkit.event.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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(ServerPlayer.class) | ||
@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) | ||
public abstract class ServerPlayerMixin_Vanilla implements ServerPlayerEntityBridge { | ||
|
||
@Inject(method = "startSleepInBed", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;setRespawnPosition(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/BlockPos;FZZ)V")) | ||
private void arclight$bedCause(BlockPos p_9115_, CallbackInfoReturnable<Either<Player.BedSleepingProblem, Unit>> cir) { | ||
this.bridge$pushChangeSpawnCause(PlayerSpawnChangeEvent.Cause.BED); | ||
} | ||
|
||
@Redirect(method = "startSleepInBed", require = 0, at = @At(value = "INVOKE", remap = false, target = "Lcom/mojang/datafixers/util/Either;left(Ljava/lang/Object;)Lcom/mojang/datafixers/util/Either;")) | ||
private <L, R> Either<L, R> arclight$failSleep(L value, BlockPos pos) { | ||
Either<L, R> either = Either.left(value); | ||
return bridge$fireBedEvent(either, pos); | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
...re/world/effect/PoisonMobEffectMixin.java → .../effect/PoisonMobEffectMixin_Vanilla.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...n/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin_Vanilla.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.izzel.arclight.common.mixin.core.world.entity; | ||
|
||
import io.izzel.arclight.api.ArclightPlatform; | ||
import io.izzel.arclight.common.bridge.core.command.ICommandSourceBridge; | ||
import io.izzel.arclight.common.bridge.core.entity.EntityBridge; | ||
import io.izzel.arclight.common.bridge.core.entity.InternalEntityBridge; | ||
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; | ||
import io.izzel.arclight.mixin.Decorate; | ||
import io.izzel.arclight.mixin.DecorationOps; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.world.entity.*; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(Entity.class) | ||
@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) | ||
public abstract class EntityMixin_Vanilla implements InternalEntityBridge, EntityBridge, ICommandSourceBridge { | ||
|
||
@Decorate(method = "updateFluidHeightAndDoFluidPushing", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FluidState;getFlow(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/Vec3;")) | ||
private Vec3 arclight$setLava(FluidState fluid, BlockGetter level, BlockPos pos) throws Throwable { | ||
if (fluid.getType().is(FluidTags.LAVA)) { | ||
bridge$setLastLavaContact(pos.immutable()); | ||
} | ||
return (Vec3) DecorationOps.callsite().invoke(fluid, level, pos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin_Vanilla.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.izzel.arclight.common.mixin.core.world.entity.animal; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import io.izzel.arclight.api.ArclightPlatform; | ||
import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; | ||
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.animal.SnowGolem; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.bukkit.craftbukkit.v.event.CraftEventFactory; | ||
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(SnowGolem.class) | ||
@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) | ||
public abstract class SnowGolemMixin_Vanilla extends PathfinderMobMixin { | ||
|
||
// Forge/NeoForge: ShearsItem#interactLivingEntity | ||
@Inject(method = "mobInteract", require = 0, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/SnowGolem;shear(Lnet/minecraft/sounds/SoundSource;)V")) | ||
private void arclight$onShear(Player player, InteractionHand hand, CallbackInfoReturnable<InteractionResult> cir, @Local ItemStack stack) { | ||
if (!CraftEventFactory.handlePlayerShearEntityEvent(player, (Entity) (Object) this, stack, hand)) { | ||
cir.setReturnValue(InteractionResult.PASS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../src/main/java/io/izzel/arclight/common/mixin/core/world/item/ItemStackMixin_Vanilla.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.izzel.arclight.common.mixin.core.world.item; | ||
|
||
import io.izzel.arclight.api.ArclightPlatform; | ||
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; | ||
import io.izzel.arclight.common.bridge.core.world.item.ItemStackBridge; | ||
import io.izzel.arclight.common.mod.mixins.annotation.OnlyInPlatform; | ||
import io.izzel.arclight.mixin.Decorate; | ||
import io.izzel.arclight.mixin.DecorationOps; | ||
import io.izzel.arclight.mixin.Local; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.bukkit.craftbukkit.v.event.CraftEventFactory; | ||
import org.bukkit.craftbukkit.v.inventory.CraftItemStack; | ||
import org.bukkit.event.player.PlayerItemDamageEvent; | ||
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 java.util.function.Consumer; | ||
|
||
@Mixin(ItemStack.class) | ||
@OnlyInPlatform(value = {ArclightPlatform.VANILLA, ArclightPlatform.FABRIC}) | ||
public abstract class ItemStackMixin_Vanilla implements ItemStackBridge { | ||
|
||
// @formatter:off | ||
@Shadow private int count; | ||
// @formatter:on | ||
|
||
@Decorate(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/level/ServerPlayer;Ljava/util/function/Consumer;)V", | ||
require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;processDurabilityChange(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;I)I")) | ||
private int arclight$itemDamage(ServerLevel serverLevel, ItemStack itemStack, int i, @Local(ordinal = 0) ServerPlayer damager) throws Throwable { | ||
int result = (int) DecorationOps.callsite().invoke(serverLevel, itemStack, i); | ||
if (damager != null) { | ||
PlayerItemDamageEvent event = new PlayerItemDamageEvent(((ServerPlayerEntityBridge) damager).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror((ItemStack) (Object) this), result); | ||
event.getPlayer().getServer().getPluginManager().callEvent(event); | ||
|
||
if (result != event.getDamage() || event.isCancelled()) { | ||
event.getPlayer().updateInventory(); | ||
} | ||
if (event.isCancelled()) { | ||
return (int) DecorationOps.cancel().invoke(); | ||
} | ||
result = event.getDamage(); | ||
} | ||
return result; | ||
} | ||
|
||
@Inject(method = "hurtAndBreak(ILnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/level/ServerPlayer;Ljava/util/function/Consumer;)V", require = 0, at = @At(value = "INVOKE", target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V")) | ||
private void arclight$itemBreak(int amount, ServerLevel level, @Nullable ServerPlayer serverPlayer, Consumer<Item> onBroken, CallbackInfo ci) { | ||
if (this.count == 1 && serverPlayer != null) { | ||
CraftEventFactory.callPlayerItemBreakEvent(serverPlayer, (ItemStack) (Object) this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.