use of net.minecraft.inventory.DoubleSidedInventory 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 net.minecraft.inventory.DoubleSidedInventory in project Arclight by IzzelAliz.
the class ChestContainerMixin method getBukkitView.
@Override
public CraftInventoryView getBukkitView() {
if (bukkitEntity != null) {
return bukkitEntity;
}
CraftInventory inventory;
if (this.lowerChestInventory instanceof PlayerInventory) {
inventory = new CraftInventoryPlayer((PlayerInventory) this.lowerChestInventory);
} else if (this.lowerChestInventory instanceof DoubleSidedInventory) {
inventory = new CraftInventoryDoubleChest((DoubleSidedInventory) this.lowerChestInventory);
} else {
inventory = new CraftInventory(this.lowerChestInventory);
}
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
return bukkitEntity;
}
use of net.minecraft.inventory.DoubleSidedInventory in project Arclight by IzzelAliz.
the class HopperTileEntityMixin method arclight$moveItem.
@Redirect(method = "transferItemsOut", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;"))
public ItemStack arclight$moveItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) {
CraftItemStack original = CraftItemStack.asCraftMirror(stack);
Inventory destinationInventory;
// Have to special case large chests as they work oddly
if (destination instanceof DoubleSidedInventory) {
destinationInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) destination));
} else {
destinationInventory = ((IInventoryBridge) destination).getOwner().getInventory();
}
InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), original.clone(), destinationInventory, true);
Bukkit.getPluginManager().callEvent(event);
if (arclight$moveItem = event.isCancelled()) {
// Delay hopper checks
this.setTransferCooldown(8);
return null;
}
return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction);
}
use of net.minecraft.inventory.DoubleSidedInventory in project Arclight by IzzelAliz.
the class HopperTileEntityMixin method arclight$pullItem.
@Redirect(method = "pullItemFromSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;"))
private static ItemStack arclight$pullItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) {
CraftItemStack original = CraftItemStack.asCraftMirror(stack);
Inventory sourceInventory;
// Have to special case large chests as they work oddly
if (source instanceof DoubleSidedInventory) {
sourceInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) source));
} else {
sourceInventory = ((IInventoryBridge) source).getOwner().getInventory();
}
InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, original.clone(), ((IInventoryBridge) destination).getOwner().getInventory(), false);
Bukkit.getPluginManager().callEvent(event);
if (arclight$moveItem = event.isCancelled()) {
if (destination instanceof HopperTileEntity) {
// Delay hopper checks
((HopperTileEntity) destination).setTransferCooldown(8);
} else if (destination instanceof HopperMinecartEntity) {
// Delay hopper minecart checks
((HopperMinecartEntity) destination).setTransferTicker(4);
}
return null;
}
return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction);
}
Aggregations