Search in sources :

Example 11 with PlayerEntityBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge in project Arclight by IzzelAliz.

the class RepairContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventory inventory = new CraftInventoryAnvil(((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation(), this.inputSlots, this.outputSlot, (RepairContainer) (Object) this);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) Container(net.minecraft.inventory.container.Container) RepairContainer(net.minecraft.inventory.container.RepairContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) CraftInventoryAnvil(org.bukkit.craftbukkit.v.inventory.CraftInventoryAnvil)

Example 12 with PlayerEntityBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge in project Arclight by IzzelAliz.

the class HangingEntityItemMixin method arclight$hangingPlace.

@Inject(method = "onItemUse", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/HangingEntity;playPlaceSound()V"))
public void arclight$hangingPlace(ItemUseContext context, CallbackInfoReturnable<ActionResultType> cir, BlockPos blockPos, Direction direction, BlockPos blockPos1, PlayerEntity playerEntity, ItemStack itemStack, World world, HangingEntity hangingEntity) {
    Player who = (context.getPlayer() == null) ? null : (Player) ((PlayerEntityBridge) context.getPlayer()).bridge$getBukkitEntity();
    Block blockClicked = CraftBlock.at(world, blockPos);
    BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
    HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) hangingEntity).bridge$getBukkitEntity(), who, blockClicked, blockFace);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        cir.setReturnValue(ActionResultType.FAIL);
    }
}
Also used : Player(org.bukkit.entity.Player) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) BlockFace(org.bukkit.block.BlockFace) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 13 with PlayerEntityBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge in project Arclight by IzzelAliz.

the class StonecutterContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.inputInventory, this.inventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : Container(net.minecraft.inventory.container.Container) StonecutterContainer(net.minecraft.inventory.container.StonecutterContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) CraftInventoryStonecutter(org.bukkit.craftbukkit.v.inventory.CraftInventoryStonecutter)

Example 14 with PlayerEntityBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge in project Arclight by IzzelAliz.

the class LeadItemMixin_1_14 method attachToFence.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public static boolean attachToFence(PlayerEntity player, World worldIn, BlockPos fence) {
    LeashKnotEntity leashknotentity = null;
    boolean flag = false;
    double d0 = 7.0D;
    int i = fence.getX();
    int j = fence.getY();
    int k = fence.getZ();
    for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
        if (mobentity.getLeashHolder() == player) {
            if (leashknotentity == null) {
                leashknotentity = LeashKnotEntity.create(worldIn, fence);
                HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    leashknotentity.remove();
                    return false;
                }
            }
            if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
                continue;
            }
            mobentity.setLeashHolder(leashknotentity, true);
            flag = true;
        }
    }
    return flag;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Player(org.bukkit.entity.Player) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 15 with PlayerEntityBridge

use of io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge in project Arclight by IzzelAliz.

the class EnchantmentContainerMixin method enchantItem.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public boolean enchantItem(PlayerEntity playerIn, int id) {
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;
    if ((itemstack1.isEmpty() || itemstack1.getCount() < i) && !playerIn.abilities.isCreativeMode) {
        return false;
    } else if (this.enchantLevels[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.enchantLevels[id]) && !playerIn.abilities.isCreativeMode) {
        return false;
    } else {
        this.worldPosCallable.consume((p_217003_6_, p_217003_7_) -> {
            ItemStack itemstack2 = itemstack;
            List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]);
            if (true || !list.isEmpty()) {
                // playerIn.onEnchant(itemstack, i);
                boolean flag = itemstack.getItem() == Items.BOOK;
                Map<Enchantment, Integer> enchants = new java.util.HashMap<>();
                for (EnchantmentData obj : list) {
                    enchants.put(org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(ForgeRegistries.ENCHANTMENTS.getKey(obj.enchantment))), obj.enchantmentLevel);
                }
                CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2);
                EnchantItemEvent event = new EnchantItemEvent(((Player) ((PlayerEntityBridge) playerIn).bridge$getBukkitEntity()), this.getBukkitView(), ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation().getBlock(), item, this.enchantLevels[id], enchants, id);
                Bukkit.getPluginManager().callEvent(event);
                int level = event.getExpLevelCost();
                if (event.isCancelled() || (level > playerIn.experienceLevel && !playerIn.abilities.isCreativeMode) || event.getEnchantsToAdd().isEmpty()) {
                    return;
                }
                if (flag) {
                    itemstack2 = new ItemStack(Items.ENCHANTED_BOOK);
                    this.tableInventory.setInventorySlotContents(0, itemstack2);
                }
                for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
                    try {
                        if (flag) {
                            NamespacedKey enchantId = entry.getKey().getKey();
                            net.minecraft.enchantment.Enchantment nms = ForgeRegistries.ENCHANTMENTS.getValue(CraftNamespacedKey.toMinecraft(enchantId));
                            if (nms == null) {
                                continue;
                            }
                            EnchantmentData weightedrandomenchant = new EnchantmentData(nms, entry.getValue());
                            EnchantedBookItem.addEnchantment(itemstack2, weightedrandomenchant);
                        } else {
                            item.addUnsafeEnchantment(entry.getKey(), entry.getValue());
                        }
                    } catch (IllegalArgumentException e) {
                    /* Just swallow invalid enchantments */
                    }
                }
                playerIn.onEnchant(itemstack, i);
                if (!playerIn.abilities.isCreativeMode) {
                    itemstack1.shrink(i);
                    if (itemstack1.isEmpty()) {
                        this.tableInventory.setInventorySlotContents(1, ItemStack.EMPTY);
                    }
                }
                playerIn.addStat(Stats.ENCHANT_ITEM);
                if (playerIn instanceof ServerPlayerEntity) {
                    CriteriaTriggers.ENCHANTED_ITEM.trigger((ServerPlayerEntity) playerIn, itemstack2, i);
                }
                this.tableInventory.markDirty();
                this.xpSeed.set(playerIn.getXPSeed());
                this.onCraftMatrixChanged(this.tableInventory);
                p_217003_6_.playSound((PlayerEntity) null, p_217003_7_, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, p_217003_6_.rand.nextFloat() * 0.1F + 0.9F);
            }
        });
        return true;
    }
}
Also used : PrepareItemEnchantEvent(org.bukkit.event.enchantment.PrepareItemEnchantEvent) EnchantedBookItem(net.minecraft.item.EnchantedBookItem) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) Enchantment(org.bukkit.enchantments.Enchantment) Inject(org.spongepowered.asm.mixin.injection.Inject) Container(net.minecraft.inventory.container.Container) EnchantmentContainer(net.minecraft.inventory.container.EnchantmentContainer) Random(java.util.Random) Player(org.bukkit.entity.Player) Overwrite(org.spongepowered.asm.mixin.Overwrite) IntReferenceHolder(net.minecraft.util.IntReferenceHolder) IWorldPosCallableBridge(io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) ItemStack(net.minecraft.item.ItemStack) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) Mixin(org.spongepowered.asm.mixin.Mixin) EnchantmentData(net.minecraft.enchantment.EnchantmentData) Map(java.util.Map) Stats(net.minecraft.stats.Stats) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) SoundCategory(net.minecraft.util.SoundCategory) IWorldPosCallable(net.minecraft.util.IWorldPosCallable) Bukkit(org.bukkit.Bukkit) At(org.spongepowered.asm.mixin.injection.At) PlayerInventory(net.minecraft.entity.player.PlayerInventory) EnchantItemEvent(org.bukkit.event.enchantment.EnchantItemEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) NamespacedKey(org.bukkit.NamespacedKey) World(net.minecraft.world.World) CraftNamespacedKey(org.bukkit.craftbukkit.v.util.CraftNamespacedKey) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) Final(org.spongepowered.asm.mixin.Final) CraftInventoryEnchanting(org.bukkit.craftbukkit.v.inventory.CraftInventoryEnchanting) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) SoundEvents(net.minecraft.util.SoundEvents) Registry(net.minecraft.util.registry.Registry) EnchantmentContainerBridge(io.izzel.arclight.common.bridge.inventory.container.EnchantmentContainerBridge) List(java.util.List) IInventory(net.minecraft.inventory.IInventory) EnchantmentOffer(org.bukkit.enchantments.EnchantmentOffer) Shadow(org.spongepowered.asm.mixin.Shadow) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) EnchantmentData(net.minecraft.enchantment.EnchantmentData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) EnchantItemEvent(org.bukkit.event.enchantment.EnchantItemEvent) NamespacedKey(org.bukkit.NamespacedKey) CraftNamespacedKey(org.bukkit.craftbukkit.v.util.CraftNamespacedKey) List(java.util.List) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) Map(java.util.Map) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)20 Container (net.minecraft.inventory.container.Container)15 CraftInventoryView (org.bukkit.craftbukkit.v.inventory.CraftInventoryView)15 CraftInventory (org.bukkit.craftbukkit.v.inventory.CraftInventory)5 Player (org.bukkit.entity.Player)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)4 MobEntity (net.minecraft.entity.MobEntity)3 PlayerInventory (net.minecraft.entity.player.PlayerInventory)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 LeashKnotEntity (net.minecraft.entity.item.LeashKnotEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 IInventory (net.minecraft.inventory.IInventory)2 EnchantmentContainer (net.minecraft.inventory.container.EnchantmentContainer)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 HangingPlaceEvent (org.bukkit.event.hanging.HangingPlaceEvent)2 InternalEntityBridge (io.izzel.arclight.common.bridge.entity.InternalEntityBridge)1 PlayerInventoryBridge (io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge)1