Skip to content

Commit

Permalink
Update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed May 1, 2024
1 parent e88b7bf commit b54ec03
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 2 deletions.
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
@@ -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,8 @@
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.ModifyArg;
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 +369,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;
}

@ModifyArg(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 = "NEW", target = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/sounds/SoundEvent;)Lnet/minecraft/world/level/Explosion;"))
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.addEnum(Level.ExplosionInteraction.class, "STANDARD", 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

0 comments on commit b54ec03

Please sign in to comment.