Fix mods dropping air item (#688)

This commit is contained in:
IzzelAliz 2022-09-02 15:55:11 +08:00
parent a30aa77099
commit 9442c1f987
No known key found for this signature in database
GPG Key ID: EE50E123A11D8338
2 changed files with 19 additions and 8 deletions

View File

@ -1,7 +1,9 @@
package io.izzel.arclight.common.bridge.core.inventory;
import io.izzel.arclight.common.mod.ArclightMod;
import io.izzel.arclight.common.mod.util.WrappedContents;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventory;
@ -10,9 +12,6 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import java.util.List;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
public interface IInventoryBridge {
@ -48,7 +47,7 @@ public interface IInventoryBridge {
if (owner != null) {
return owner.getInventory();
} else {
ArclightMod.LOGGER.warn("No owner for inventory {}/{}", this, this.getClass());
// ArclightMod.LOGGER.warn("No owner for inventory {}/{}", this, this.getClass());
return new CraftInventory((Container) this);
}
}

View File

@ -3,12 +3,12 @@ package io.izzel.arclight.common.mixin.bukkit;
import com.google.common.base.Function;
import io.izzel.arclight.common.bridge.core.entity.EntityBridge;
import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import io.izzel.arclight.common.mod.ArclightMod;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import io.izzel.arclight.common.mod.util.DistValidate;
import net.minecraft.core.BlockPos;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
@ -20,6 +20,7 @@ import org.bukkit.craftbukkit.v.block.CraftBlockStates;
import org.bukkit.craftbukkit.v.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.util.CraftMagicNumbers;
import org.bukkit.entity.Item;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockGrowEvent;
@ -31,6 +32,7 @@ import org.bukkit.event.block.NotePlayEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@ -70,10 +72,10 @@ public class CraftEventFactoryMixin {
// todo blockDamage is lost
EntityDamageEvent event;
if (source.getEntity() != null) {
ArclightMod.LOGGER.debug("Unhandled damage of {} by {} from {}", entity, source.getEntity(), source.msgId);
// ArclightMod.LOGGER.debug("Unhandled damage of {} by {} from {}", entity, source.getEntity(), source.msgId);
event = new EntityDamageByEntityEvent(((EntityBridge) source.getEntity()).bridge$getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions);
} else {
ArclightMod.LOGGER.debug("Unhandled damage of {} from {}", entity, source.msgId);
// ArclightMod.LOGGER.debug("Unhandled damage of {} from {}", entity, source.msgId);
event = new EntityDamageEvent(((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions);
}
event.setCancelled(cancelled);
@ -233,4 +235,14 @@ public class CraftEventFactoryMixin {
}
return event;
}
@Inject(method = "callItemSpawnEvent", cancellable = true, at = @At("HEAD"))
private static void arclight$noAirDrops(ItemEntity itemEntity, CallbackInfoReturnable<ItemSpawnEvent> cir) {
if (itemEntity.getItem().isEmpty()) {
Item entity = (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity();
ItemSpawnEvent event = new ItemSpawnEvent(entity);
event.setCancelled(true);
cir.setReturnValue(event);
}
}
}