Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
run_fabric_smoke
tmp_arclight_api_src

# User-specific stuff
.idea/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import net.minecraft.core.PositionImpl;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
import org.bukkit.projectiles.ProjectileSource;

import java.util.Collection;
import java.util.List;

public interface EntityBridge extends ICommandSourceBridge {
Expand Down Expand Up @@ -52,4 +54,10 @@ public interface EntityBridge extends ICommandSourceBridge {
int bridge$getRideCooldown();

boolean bridge$canCollideWith(Entity entity);

Collection<ItemEntity> bridge$captureDrops();

Collection<ItemEntity> bridge$captureDrops(Collection<ItemEntity> value);

void bridge$revive();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.izzel.arclight.common.mixin.bukkit;

import io.izzel.arclight.common.mod.server.entity.ArclightFakePlayer;
import io.izzel.arclight.common.mod.server.entity.EntityClassLookup;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraftforge.common.util.FakePlayer;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftComplexPart;
import org.bukkit.craftbukkit.v.entity.CraftEnderDragonPart;
Expand All @@ -28,17 +26,16 @@ public abstract class CraftEntityMixin implements org.bukkit.entity.Entity {

@Inject(method = "getEntity", cancellable = true, at = @At("HEAD"))
private static void arclight$fakePlayer(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
if (entity instanceof FakePlayer) {
cir.setReturnValue(new ArclightFakePlayer(server, (FakePlayer) entity));
if (cir.isCancelled()) {
return;
}
if (entity instanceof EnderDragonPart part) {
if (part.parentMob instanceof EnderDragon) {
cir.setReturnValue(new CraftEnderDragonPart(server, (EnderDragonPart) entity));
cir.setReturnValue(new CraftEnderDragonPart(server, part));
return;
}

cir.setReturnValue(new CraftComplexPart(server, (EnderDragonPart) entity));
cir.setReturnValue(new CraftComplexPart(server, part));
return;
}
var convert = EntityClassLookup.getConvert(entity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.izzel.arclight.common.mixin.bukkit;

import io.izzel.arclight.common.mod.mixins.annotation.LoadIfMod;
import io.izzel.arclight.common.mod.server.entity.ArclightFakePlayer;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.common.util.FakePlayer;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
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;

@LoadIfMod(modid = "forge", condition = LoadIfMod.ModCondition.PRESENT)
@Mixin(value = CraftEntity.class, remap = false)
public abstract class CraftEntityMixin_Forge {

@Inject(method = "getEntity", cancellable = true, at = @At("HEAD"))
private static void arclight$forge$fakePlayer(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
if (entity instanceof FakePlayer) {
cir.setReturnValue(new ArclightFakePlayer(server, (FakePlayer) entity));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public class CraftEventFactoryMixin {
@Shadow
public static Block blockDamage;

@Inject(method = "handleEntityDamageEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", at = @At("HEAD"))
@Inject(method = {
"handleEntityDamageEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;",
"handleEntityDamageEvent(Lnet/minecraft/class_1297;Lnet/minecraft/class_1282;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;"
}, at = @At("HEAD"))
private static void arclight$captureSource(Entity entity, DamageSource source, Map<EntityDamageEvent.DamageModifier, Double> modifiers, Map<EntityDamageEvent.DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled, CallbackInfoReturnable<EntityDamageEvent> cir) {
Entity damageEventEntity = ArclightCaptures.getDamageEventEntity();
BlockPos damageEventBlock = ArclightCaptures.getDamageEventBlock();
Expand All @@ -70,7 +73,10 @@ public class CraftEventFactoryMixin {
}
}

@Inject(method = "handleEntityDamageEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", cancellable = true, at = @At(value = "NEW", target = "java/lang/IllegalStateException"))
@Inject(method = {
"handleEntityDamageEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;",
"handleEntityDamageEvent(Lnet/minecraft/class_1297;Lnet/minecraft/class_1282;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;"
}, cancellable = true, at = @At(value = "NEW", target = "java/lang/IllegalStateException"))
private static void arclight$unhandledDamage(Entity entity, DamageSource source, Map<EntityDamageEvent.DamageModifier, Double> modifiers, Map<EntityDamageEvent.DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled, CallbackInfoReturnable<EntityDamageEvent> cir) {
// todo blockDamage is lost
EntityDamageEvent event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.izzel.arclight.common.mixin.bukkit;

import io.izzel.arclight.common.bridge.core.inventory.container.ContainerBridge;
import io.izzel.arclight.common.mod.server.ArclightForgePermissible;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import io.izzel.arclight.i18n.ArclightConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
Expand All @@ -17,13 +15,10 @@
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryPlayer;
import org.bukkit.inventory.InventoryView;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.ServerOperator;
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.CallbackInfoReturnable;

import java.lang.reflect.Field;
Expand All @@ -47,15 +42,6 @@ public void setHandle(Entity entity) {
this.inventory = new CraftInventoryPlayer(((Player) entity).getInventory());
}

@Redirect(method = "<init>", at = @At(value = "NEW", target = "org/bukkit/permissions/PermissibleBase"))
private PermissibleBase arclight$forwardPerm(ServerOperator opable) {
if (ArclightConfig.spec().getCompat().isForwardPermissionReverse()) {
return new ArclightForgePermissible(opable);
} else {
return new PermissibleBase(opable);
}
}

@Inject(method = "getOpenInventory", at = @At("HEAD"))
private void arclight$capturePlayer(CallbackInfoReturnable<InventoryView> cir) {
ArclightCaptures.captureContainerOwner(this.getHandle());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.izzel.arclight.common.mixin.bukkit;

import io.izzel.arclight.common.mod.mixins.annotation.LoadIfMod;
import io.izzel.arclight.common.mod.server.ArclightForgePermissible;
import io.izzel.arclight.i18n.ArclightConfig;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.ServerOperator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@LoadIfMod(modid = "forge", condition = LoadIfMod.ModCondition.PRESENT)
@Mixin(value = CraftHumanEntity.class, remap = false)
public abstract class CraftHumanEntityMixin_Forge {

@Redirect(method = "<init>", at = @At(value = "NEW", target = "(Lorg/bukkit/permissions/ServerOperator;)Lorg/bukkit/permissions/PermissibleBase;"))
private PermissibleBase arclight$forge$forwardPerm(ServerOperator opable) {
if (ArclightConfig.spec().getCompat().isForwardPermissionReverse()) {
return new ArclightForgePermissible(opable);
} else {
return new PermissibleBase(opable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge {

@Shadow static Material getType(ItemStack item) { throw new RuntimeException(); }

@Inject(method = "getItemMeta(Lnet/minecraft/world/item/ItemStack;)Lorg/bukkit/inventory/meta/ItemMeta;", cancellable = true, at = @At(value = "INVOKE", target = "Lorg/bukkit/Material;ordinal()I"))
@Inject(method = "getItemMeta(Lnet/minecraft/class_1799;)Lorg/bukkit/inventory/meta/ItemMeta;", cancellable = true, at = @At(value = "INVOKE", target = "Lorg/bukkit/Material;ordinal()I"))
private static void arclight$noTag(ItemStack item, CallbackInfoReturnable<ItemMeta> cir) {
if (item.getTag() == null) {
var meta = CraftItemFactory.instance().getItemMeta(getType(item));
Expand All @@ -36,7 +36,7 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge {
}
}

@Inject(method = "getItemMeta(Lnet/minecraft/world/item/ItemStack;)Lorg/bukkit/inventory/meta/ItemMeta;", at = @At("RETURN"))
@Inject(method = "getItemMeta(Lnet/minecraft/class_1799;)Lorg/bukkit/inventory/meta/ItemMeta;", at = @At("RETURN"))
private static void arclight$offerCaps(ItemStack item, CallbackInfoReturnable<ItemMeta> cir) {
if (item == null) return;
ItemMeta meta = cir.getReturnValue();
Expand All @@ -47,7 +47,7 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge {
((ItemMetaBridge) meta).bridge$setForgeCaps(((ItemStackBridge) (Object) item).bridge$getForgeCaps());
}

@Inject(method = "setItemMeta(Lnet/minecraft/world/item/ItemStack;Lorg/bukkit/inventory/meta/ItemMeta;)Z", at = @At(value = "INVOKE", ordinal = 1, remap = true, target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;"))
@Inject(method = "setItemMeta(Lnet/minecraft/class_1799;Lorg/bukkit/inventory/meta/ItemMeta;)Z", at = @At(value = "INVOKE", ordinal = 1, remap = true, target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;"))
private static void arclight$setCaps(ItemStack item, ItemMeta itemMeta, CallbackInfoReturnable<Boolean> cir) {
CompoundTag forgeCaps = ((ItemMetaBridge) itemMeta).bridge$getForgeCaps();
if (forgeCaps != null) {
Expand All @@ -56,7 +56,7 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge {
}
// @formatter:on

@Inject(method = "hasItemMeta(Lnet/minecraft/world/item/ItemStack;)Z", cancellable = true, at = @At("HEAD"))
@Inject(method = "hasItemMeta(Lnet/minecraft/class_1799;)Z", cancellable = true, at = @At("HEAD"))
private static void arclight$hasMeta(ItemStack item, CallbackInfoReturnable<Boolean> cir) {
if (item != null) {
CompoundTag forgeCaps = ((ItemStackBridge) (Object) item).bridge$getForgeCaps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class CraftMetaItemMixin implements ItemMetaBridge {
private CompoundTag internalTag;
private CompoundTag forgeCaps;

@ModifyVariable(method = "<init>(Lnet/minecraft/nbt/CompoundTag;)V", at = @At(value = "INVOKE", target = "Lorg/bukkit/UnsafeValues;getDataVersion()I"))
@ModifyVariable(method = "<init>(Lnet/minecraft/nbt/CompoundTag;)V", at = @At(value = "INVOKE", target = "Lorg/bukkit/UnsafeValues;getDataVersion()I"), require = 0)
private CompoundTag arclight$provideTag(CompoundTag tag) {
return tag == null ? new CompoundTag() : tag;
}
Expand Down
Loading