Skip to content

Commit

Permalink
Merge branch 'IzzelAliz:Whisper' into Whisper
Browse files Browse the repository at this point in the history
  • Loading branch information
HotoRas authored May 4, 2024
2 parents d9e7e2b + 08bffd8 commit d655c25
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ A Bukkit server implementation utilizing Mixin.

![Downloads](https://img.shields.io/github/downloads/IzzelAliz/Arclight/total?style=flat-square) ![GitHub](https://img.shields.io/github/license/IzzelAliz/Arclight?style=flat-square)

| Release | Forge | NeoForge | Fabric | Status | Downloads |
|:---------------------|:--------|:---------|:--------|:------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Whisper (1.20.4) | 49.0.38 | 20.4.215 | 0.96.11 | ACTIVE | [![1.20.4 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Whisper&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3AWhisper) |
| Trials (1.20-1.20.1) | 47.2.20 | - | - | LTS | [![1.20.1 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Trials&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ATrials) |
| Horn (1.19-1.19.2) | 43.3.7 | - | - | LTS | [![Horn Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-19?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |
| Release | Forge | NeoForge | Fabric | Status | Downloads |
|:---------------------|:--------|:---------|:-------|:------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Whisper (1.20.4) | 49.0.49 | 20.4.234 | 0.97.0 | ACTIVE | [![1.20.4 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Whisper&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3AWhisper) |
| Trials (1.20-1.20.1) | 47.2.20 | - | - | LTS | [![1.20.1 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Trials&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ATrials) |
| Horn (1.19-1.19.2) | 43.3.7 | - | - | LTS | [![Horn Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-19?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |

**Legacy versions**:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public Entity getCausingEntity() {

@Override
public DamageSource bridge$customCausingEntity(Entity entity) {
// This method is not intended for change the causing entity if is already set
// also is only necessary if the entity passed is not the direct entity or different from the current causingEntity
if (this.customCausingEntity != null || this.directEntity == entity || this.causingEntity == entity) {
return (DamageSource) (Object) this;
}
var src = cloneInstance();
return ((DamageSourceBridge) src).bridge$setCustomCausingEntity(entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.izzel.arclight.common.bridge.core.entity.MobEntityBridge;
import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import io.izzel.arclight.common.mod.server.ArclightServer;
import io.izzel.arclight.mixin.Eject;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -325,18 +324,28 @@ public ItemStack equipItemIfPossible(ItemStack stack) {
Bukkit.getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN));
}

@Eject(method = "convertTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"))
private boolean arclight$copySpawn(net.minecraft.world.level.Level world, Entity entityIn, CallbackInfoReturnable<Mob> cir) {
private transient boolean arclight$cancelSpawn;

@Redirect(method = "convertTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"))
private boolean arclight$copySpawn(net.minecraft.world.level.Level world, Entity entityIn) {
EntityTransformEvent.TransformReason transformReason = arclight$transform == null ? EntityTransformEvent.TransformReason.UNKNOWN : arclight$transform;
arclight$transform = null;
if (CraftEventFactory.callEntityTransformEvent((Mob) (Object) this, (LivingEntity) entityIn, transformReason).isCancelled()) {
cir.setReturnValue(null);
arclight$cancelSpawn = true;
return false;
} else {
return world.addFreshEntity(entityIn);
}
}

@Inject(method = "convertTo", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"))
private <T extends Mob> void arclight$cancelSpawn(EntityType<T> entityType, boolean bl, CallbackInfoReturnable<T> cir) {
if (arclight$cancelSpawn) {
cir.setReturnValue(null);
}
arclight$cancelSpawn = false;
}

@Inject(method = "convertTo", at = @At("RETURN"))
private <T extends Mob> void arclight$cleanReason(EntityType<T> p_233656_1_, boolean p_233656_2_, CallbackInfoReturnable<T> cir) {
((WorldBridge) this.level()).bridge$pushAddEntityReason(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package io.izzel.arclight.common.mixin.core.world.entity.monster;

import io.izzel.arclight.common.bridge.core.entity.monster.CreeperEntityBridge;
import io.izzel.arclight.common.bridge.core.util.DamageSourceBridge;
import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
Expand All @@ -20,9 +25,11 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Collection;
Expand All @@ -38,6 +45,13 @@ public abstract class CreeperMixin extends PathfinderMobMixin implements Creeper
@Shadow public abstract boolean isPowered();
// @formatter:on

@Unique private Player entityIgniter; // CraftBukkit

@Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/Creeper;ignite()V"))
private void arclight$catchIgniter(Player player, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResult> cir) {
this.entityIgniter = player;
}

@Inject(method = "thunderHit", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/monster/Creeper;entityData:Lnet/minecraft/network/syncher/SynchedEntityData;"))
private void arclight$lightningBolt(ServerLevel world, LightningBolt lightningBolt, CallbackInfo ci) {
if (CraftEventFactory.callCreeperPowerEvent((Creeper) (Object) this, lightningBolt, CreeperPowerEvent.PowerCause.LIGHTNING).isCancelled()) {
Expand All @@ -57,7 +71,9 @@ public final void explodeCreeper() {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.dead = true;
this.level().explode((Creeper) (Object) this, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB);
this.level().explode((Creeper) (Object) this,
((DamageSourceBridge) Explosion.getDefaultDamageSource(level(), (Creeper) (Object) this)).bridge$customCausingEntity(entityIgniter), null,
this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB);
this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.EXPLODE);
this.discard();
this.spawnLingeringCloud();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.izzel.arclight.common.bridge.core.world.level.levelgen.ChunkGeneratorBridge;
import io.izzel.arclight.common.bridge.core.world.server.ServerChunkProviderBridge;
import io.izzel.arclight.common.bridge.core.world.server.ServerWorldBridge;
import io.izzel.arclight.common.mod.ArclightConstants;
import io.izzel.arclight.common.mod.mixins.annotation.CreateConstructor;
import io.izzel.arclight.common.mod.mixins.annotation.ShadowConstructor;
import io.izzel.arclight.common.mod.mixins.annotation.TransformAccess;
Expand All @@ -22,6 +23,7 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelWriter;
Expand Down Expand Up @@ -59,6 +61,7 @@
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand Down Expand Up @@ -365,4 +368,30 @@ public BlockEntity getBlockEntity(BlockPos pos, boolean validate) {
public void bridge$preventPoiUpdated(boolean b) {
this.preventPoiUpdated = b;
}

private transient Explosion.BlockInteraction arclight$blockInteractionOverride;

@ModifyVariable(method = "explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;ZLnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)Lnet/minecraft/world/level/Explosion;",
ordinal = 0, at = @At("HEAD"), argsOnly = true)
private Level.ExplosionInteraction arclight$standardExplodePre(Level.ExplosionInteraction interaction) {
if (interaction == ArclightConstants.STANDARD) {
arclight$blockInteractionOverride = Explosion.BlockInteraction.DESTROY;
return Level.ExplosionInteraction.BLOCK;
}
return interaction;
}

@ModifyVariable(method = "explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;ZLnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)Lnet/minecraft/world/level/Explosion;",
at = @At(value = "LOAD", ordinal = 0))
private Explosion.BlockInteraction arclight$standardExplodePost(Explosion.BlockInteraction interaction) {
try {
if (arclight$blockInteractionOverride != null) {
return arclight$blockInteractionOverride;
} else {
return interaction;
}
} finally {
arclight$blockInteractionOverride = null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.izzel.arclight.common.mixin.core.world.level;

import io.izzel.arclight.api.EnumHelper;
import io.izzel.arclight.common.mod.mixins.annotation.TransformAccess;
import net.minecraft.world.level.Level;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;

import java.util.List;

@Mixin(Level.ExplosionInteraction.class)
public class Level_ExplosionInteractionMixin {

@TransformAccess(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL)
private static final Level.ExplosionInteraction STANDARD = EnumHelper.makeEnum(Level.ExplosionInteraction.class, "STANDARD", Level.ExplosionInteraction.values().length, List.of(), List.of());
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@

import io.izzel.arclight.common.bridge.core.entity.player.PlayerEntityBridge;
import io.izzel.arclight.common.bridge.core.util.DamageSourceBridge;
import io.izzel.arclight.common.mod.mixins.annotation.TransformAccess;
import net.minecraft.core.BlockPos;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageSources;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.ConduitBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.objectweb.asm.Opcodes;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(ConduitBlockEntity.class)
public abstract class ConduitBlockEntityMixin extends BlockEntityMixin {

// @formatter:off
@Shadow private static void updateDestroyTarget(Level level, BlockPos blockPos, BlockState blockState, List<BlockPos> list, ConduitBlockEntity conduitBlockEntity) {}
// @formatter:on

@Redirect(method = "applyEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z"))
private static boolean arclight$addEntity(Player player, MobEffectInstance eff) {
((PlayerEntityBridge) player).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONDUIT);
Expand All @@ -31,4 +40,27 @@ public abstract class ConduitBlockEntityMixin extends BlockEntityMixin {
private static DamageSource arclight$attackReason(DamageSources instance, Level level, BlockPos pos) {
return ((DamageSourceBridge) instance.magic()).bridge$directBlock(CraftBlock.at(level, pos));
}

@TransformAccess(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC)
private static int getRange(List<BlockPos> list) {
int i = list.size();
return i / 7 * 16;
}

private static boolean arclight$damageTarget = true;

@Inject(method = "updateDestroyTarget", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V"))
private static void arclight$returnIfNot(Level level, BlockPos blockPos, BlockState blockState, List<BlockPos> list, ConduitBlockEntity conduitBlockEntity, CallbackInfo ci) {
if (!arclight$damageTarget) {
ci.cancel();
level.sendBlockUpdated(blockPos, blockState, blockState, 2);
}
}

@TransformAccess(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC)
private static void updateDestroyTarget(Level level, BlockPos blockPos, BlockState blockState, List<BlockPos> list, ConduitBlockEntity conduitBlockEntity, boolean damageTarget) {
arclight$damageTarget = damageTarget;
updateDestroyTarget(level, blockPos, blockState, list, conduitBlockEntity);
arclight$damageTarget = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.izzel.arclight.api.EnumHelper;
import io.izzel.arclight.api.Unsafe;
import net.minecraft.util.datafix.DataFixTypes;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.bukkit.TreeType;
Expand All @@ -15,6 +16,7 @@ public class ArclightConstants {

public static final TreeType MOD = EnumHelper.addEnum(TreeType.class, "MOD", ImmutableList.of(), ImmutableList.of());

public static final Level.ExplosionInteraction STANDARD = Unsafe.getStatic(Level.ExplosionInteraction.class, "STANDARD");
public static final LootContextParam<Integer> LOOTING_MOD = Unsafe.getStatic(LootContextParams.class, "LOOTING_MOD");

private static final DSL.TypeReference PDC_TYPE = () -> "bukkit_pdc";
Expand Down
4 changes: 4 additions & 0 deletions arclight-common/src/main/resources/arclight.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ accessible method net/minecraft/world/damagesource/DamageSource <init> (Lnet/min
accessible method net/minecraft/server/level/ServerLevel getEntities ()Lnet/minecraft/world/level/entity/LevelEntityGetter;
accessible field net/minecraft/world/entity/animal/MushroomCow stewEffects Ljava/util/List;
accessible field net/minecraft/world/entity/LivingEntity useItemRemaining I
accessible method net/minecraft/world/level/block/entity/ConduitBlockEntity getDestroyRangeAABB (Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/AABB;
accessible field net/minecraft/world/level/block/entity/ConduitBlockEntity effectBlocks Ljava/util/List;
accessible field net/minecraft/world/level/block/entity/ConduitBlockEntity destroyTarget Lnet/minecraft/world/entity/LivingEntity;
accessible field net/minecraft/world/level/block/entity/ConduitBlockEntity destroyTargetUUID Ljava/util/UUID;
# Older versions
accessible field net/minecraft/world/level/chunk/storage/ChunkSerializer BLOCK_STATE_CODEC Lcom/mojang/serialization/Codec;
# TODO field net/minecraft/server/PlayerAdvancements f_135964_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
"world.item.enchantment.FrostWalkerEnchantmentMixin",
"world.level.ExplosionMixin",
"world.level.GameRules_ValueMixin",
"world.level.Level_ExplosionInteractionMixin",
"world.level.LevelMixin",
"world.level.block.BambooSaplingBlockMixin",
"world.level.block.BambooStalkBlockMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ private static void doBrew(Level level, BlockPos pos, NonNullList<ItemStack> sta
return;
}

itemStack.shrink(1);
if (itemStack.getItem().hasCraftingRemainingItem()) {
ItemStack itemStack2 = new ItemStack(itemStack.getItem().getCraftingRemainingItem());
itemStack.shrink(1);
if (itemStack.isEmpty()) {
itemStack = itemStack2;
} else {
Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), itemStack2);
}
} else {
itemStack.shrink(1);
}

stacks.set(3, itemStack);
Expand Down
Loading

0 comments on commit d655c25

Please sign in to comment.