-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLBAInvHook.java
More file actions
63 lines (53 loc) · 2.12 KB
/
LBAInvHook.java
File metadata and controls
63 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package io.github.cottonmc.component.compat.lba;
import alexiil.mc.lib.attributes.SearchOptions;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import alexiil.mc.lib.attributes.item.ItemAttributes;
import alexiil.mc.lib.attributes.item.impl.EmptyFixedItemInv;
import io.github.cottonmc.component.item.InventoryComponent;
import io.github.cottonmc.component.item.InventoryComponentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import javax.annotation.Nullable;
public class LBAInvHook implements InventoryComponentHelper.DualInventoryHook {
private static final LBAInvHook INSTANCE = new LBAInvHook();
public static void initInv() {
InventoryComponentHelper.INSTANCE.addDualHook(INSTANCE);
}
@Override
public boolean hasInvComponent(BlockView world, BlockPos pos, @Nullable Direction dir) {
if (world instanceof World) {
if (dir == null) return ItemAttributes.FIXED_INV.get((World)world, pos) != EmptyFixedItemInv.INSTANCE;
return ItemAttributes.FIXED_INV.get((World)world, pos, SearchOptions.inDirection(dir)) != EmptyFixedItemInv.INSTANCE;
}
return false;
}
@Override
@Nullable
public InventoryComponent getInvComponent(BlockView world, BlockPos pos, @Nullable Direction dir) {
if (world instanceof World) {
FixedItemInv inv = dir == null ? ItemAttributes.FIXED_INV.get((World)world, pos) : ItemAttributes.FIXED_INV.get((World)world, pos, SearchOptions.inDirection(dir));
if (inv == EmptyFixedItemInv.INSTANCE) return null;
return new WrappedInvAttributeComponent(inv);
}
return null;
}
@Override
public boolean hasInvComponent(ItemStack stack) {
return ItemAttributes.FIXED_INV.get(stack) != EmptyFixedItemInv.INSTANCE;
}
@Override
@Nullable
public InventoryComponent getInvComponent(ItemStack stack) {
FixedItemInv inv = ItemAttributes.FIXED_INV.get(stack);
if (inv == EmptyFixedItemInv.INSTANCE) return null;
return new WrappedInvAttributeComponent(inv);
}
@Override
public String getId() {
return "lba-items";
}
private LBAInvHook() { }
}