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;
}
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);
}
}
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;
}
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;
}
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;
}
}
Aggregations