use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.
the class DropperBlockMixin method dispense.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void dispense(World worldIn, BlockPos pos) {
ProxyBlockSource proxyblocksource = new ProxyBlockSource(worldIn, pos);
DispenserTileEntity dispensertileentity = proxyblocksource.getBlockTileEntity();
int i = dispensertileentity.getDispenseSlot();
if (i < 0) {
worldIn.playEvent(1001, pos, 0);
} else {
ItemStack itemstack = dispensertileentity.getStackInSlot(i);
if (!itemstack.isEmpty() && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, dispensertileentity, i, itemstack)) {
Direction direction = worldIn.getBlockState(pos).get(DispenserBlock.FACING);
IInventory iinventory = HopperTileEntity.getInventoryAtPosition(worldIn, pos.offset(direction));
ItemStack itemstack1;
if (iinventory == null) {
itemstack1 = DISPENSE_BEHAVIOR.dispense(proxyblocksource, itemstack);
} else {
ItemStack split = itemstack.copy().split(1);
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(split);
Inventory destinationInventory;
// Have to special case large chests as they work oddly
if (iinventory instanceof DoubleSidedInventory) {
destinationInventory = new CraftInventoryDoubleChest((DoubleSidedInventory) iinventory);
} else {
destinationInventory = ((IInventoryBridge) iinventory).getOwner().getInventory();
}
InventoryMoveItemEvent event = new InventoryMoveItemEvent(((IInventoryBridge) dispensertileentity).getOwner().getInventory(), craftItemStack, destinationInventory, true);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
itemstack1 = HopperTileEntity.putStackInInventoryAllSlots(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite());
if (event.getItem().equals(craftItemStack) && itemstack1.isEmpty()) {
itemstack1 = itemstack.copy();
itemstack1.shrink(1);
} else {
itemstack1 = itemstack.copy();
}
}
dispensertileentity.setInventorySlotContents(i, itemstack1);
}
}
}
use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.
the class LootTableMixin method fillInventory.
// @formatter:on
public void fillInventory(IInventory inv, LootContext context, boolean plugin) {
List<ItemStack> list = this.generate(context);
Random random = context.getRandom();
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, plugin);
if (event.isCancelled()) {
return;
}
list = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList());
List<Integer> list1 = this.getEmptySlotsRandomized(inv, random);
this.shuffleItems(list, list1.size(), random);
for (ItemStack itemstack : list) {
if (list1.isEmpty()) {
LOGGER.warn("Tried to over-fill a container");
return;
}
if (itemstack.isEmpty()) {
inv.setInventorySlotContents(list1.remove(list1.size() - 1), ItemStack.EMPTY);
} else {
inv.setInventorySlotContents(list1.remove(list1.size() - 1), itemstack);
}
}
}
use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.
the class EnchantmentContainerMixin method onCraftMatrixChanged.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void onCraftMatrixChanged(IInventory inventoryIn) {
if (inventoryIn == this.tableInventory) {
ItemStack itemstack = inventoryIn.getStackInSlot(0);
if (!itemstack.isEmpty()) {
this.worldPosCallable.consume((p_217002_2_, p_217002_3_) -> {
float power = 0;
for (int k = -1; k <= 1; ++k) {
for (int l = -1; l <= 1; ++l) {
if ((k != 0 || l != 0) && p_217002_2_.isAirBlock(p_217002_3_.add(l, 0, k)) && p_217002_2_.isAirBlock(p_217002_3_.add(l, 1, k))) {
power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 0, k * 2));
power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 1, k * 2));
if (l != 0 && k != 0) {
power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 0, k));
power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 1, k));
power += getPower(p_217002_2_, p_217002_3_.add(l, 0, k * 2));
power += getPower(p_217002_2_, p_217002_3_.add(l, 1, k * 2));
}
}
}
}
this.rand.setSeed(this.xpSeed.get());
for (int i1 = 0; i1 < 3; ++i1) {
this.enchantLevels[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, (int) power, itemstack);
this.enchantClue[i1] = -1;
this.worldClue[i1] = -1;
if (this.enchantLevels[i1] < i1 + 1) {
this.enchantLevels[i1] = 0;
}
this.enchantLevels[i1] = ForgeEventFactory.onEnchantmentLevelSet(p_217002_2_, p_217002_3_, i1, (int) power, itemstack, enchantLevels[i1]);
}
for (int j1 = 0; j1 < 3; ++j1) {
if (this.enchantLevels[j1] > 0) {
List<EnchantmentData> list = this.getEnchantmentList(itemstack, j1, this.enchantLevels[j1]);
if (list != null && !list.isEmpty()) {
EnchantmentData enchantmentdata = list.get(this.rand.nextInt(list.size()));
this.enchantClue[j1] = Registry.ENCHANTMENT.getId(enchantmentdata.enchantment);
this.worldClue[j1] = enchantmentdata.enchantmentLevel;
}
}
}
CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
org.bukkit.enchantments.EnchantmentOffer[] offers = new EnchantmentOffer[3];
for (int j = 0; j < 3; ++j) {
org.bukkit.enchantments.Enchantment enchantment = (this.enchantClue[j] >= 0) ? org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(ForgeRegistries.ENCHANTMENTS.getKey(Registry.ENCHANTMENT.getByValue(this.enchantClue[j])))) : null;
offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.worldClue[j], this.enchantLevels[j]) : null;
}
PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), this.getBukkitView(), ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation().getBlock(), item, offers, (int) power);
event.setCancelled(!itemstack.isEnchantable());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
for (int j = 0; j < 3; ++j) {
this.enchantLevels[j] = 0;
this.enchantClue[j] = -1;
this.worldClue[j] = -1;
}
return;
}
for (int j = 0; j < 3; j++) {
EnchantmentOffer offer = event.getOffers()[j];
if (offer != null) {
this.enchantLevels[j] = offer.getCost();
this.enchantClue[j] = Registry.ENCHANTMENT.getId(ForgeRegistries.ENCHANTMENTS.getValue(CraftNamespacedKey.toMinecraft(offer.getEnchantment().getKey())));
this.worldClue[j] = offer.getEnchantmentLevel();
} else {
this.enchantLevels[j] = 0;
this.enchantClue[j] = -1;
this.worldClue[j] = -1;
}
}
this.detectAndSendChanges();
});
} else {
for (int i = 0; i < 3; ++i) {
this.enchantLevels[i] = 0;
this.enchantClue[i] = -1;
this.worldClue[i] = -1;
}
}
}
}
use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.
the class BlastingRecipeMixin method bridge$toBukkitRecipe.
@Override
public Recipe bridge$toBukkitRecipe() {
CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
CraftBlastingRecipe recipe = new CraftBlastingRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookTime);
recipe.setGroup(this.group);
return recipe;
}
use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.
the class ServerPlayNetHandlerMixin method processPlayerDigging.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void processPlayerDigging(CPlayerDiggingPacket packetplayinblockdig) {
PacketThreadUtil.checkThreadAndEnqueue(packetplayinblockdig, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
return;
}
BlockPos blockposition = packetplayinblockdig.getPosition();
this.player.markPlayerActive();
CPlayerDiggingPacket.Action packetplayinblockdig_enumplayerdigtype = packetplayinblockdig.getAction();
switch(packetplayinblockdig_enumplayerdigtype) {
case SWAP_HELD_ITEMS:
{
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getHeldItem(Hand.OFF_HAND);
CraftItemStack mainHand = CraftItemStack.asCraftMirror(itemstack);
CraftItemStack offHand = CraftItemStack.asCraftMirror(this.player.getHeldItem(Hand.MAIN_HAND));
PlayerSwapHandItemsEvent swapItemsEvent = new PlayerSwapHandItemsEvent(this.getPlayer(), mainHand.clone(), offHand.clone());
this.server.getPluginManager().callEvent(swapItemsEvent);
if (swapItemsEvent.isCancelled()) {
return;
}
if (swapItemsEvent.getOffHandItem().equals(offHand)) {
this.player.setHeldItem(Hand.OFF_HAND, this.player.getHeldItem(Hand.MAIN_HAND));
} else {
this.player.setHeldItem(Hand.OFF_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getOffHandItem()));
}
if (swapItemsEvent.getMainHandItem().equals(mainHand)) {
this.player.setHeldItem(Hand.MAIN_HAND, itemstack);
} else {
this.player.setHeldItem(Hand.MAIN_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getMainHandItem()));
}
}
return;
}
case DROP_ITEM:
{
if (!this.player.isSpectator()) {
if (this.lastDropTick != ArclightConstants.currentTick) {
this.dropCount = 0;
this.lastDropTick = ArclightConstants.currentTick;
} else {
++this.dropCount;
if (this.dropCount >= 20) {
LOGGER.warn(this.player.getScoreboardName() + " dropped their items too quickly!");
this.disconnect("You dropped your items too quickly (Hacking?)");
return;
}
}
this.bridge$dropItems(this.player, false);
}
return;
}
case DROP_ALL_ITEMS:
{
if (!this.player.isSpectator()) {
this.bridge$dropItems(this.player, true);
}
return;
}
case RELEASE_USE_ITEM:
{
this.player.stopActiveHand();
return;
}
case START_DESTROY_BLOCK:
case ABORT_DESTROY_BLOCK:
case STOP_DESTROY_BLOCK:
{
this.player.interactionManager.func_225416_a(blockposition, packetplayinblockdig_enumplayerdigtype, packetplayinblockdig.getFacing(), this.minecraftServer.getBuildLimit());
return;
}
default:
{
throw new IllegalArgumentException("Invalid player action");
}
}
}
Aggregations