-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAttributeWrapper.java
More file actions
77 lines (62 loc) · 1.97 KB
/
Copy pathAttributeWrapper.java
File metadata and controls
77 lines (62 loc) · 1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package io.github.cottonmc.component.compat.lba;
import alexiil.mc.lib.attributes.ListenerRemovalToken;
import alexiil.mc.lib.attributes.ListenerToken;
import alexiil.mc.lib.attributes.Simulation;
import alexiil.mc.lib.attributes.item.*;
import alexiil.mc.lib.attributes.item.filter.ItemFilter;
import io.github.cottonmc.component.api.ActionType;
import io.github.cottonmc.component.item.InventoryComponent;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public class AttributeWrapper implements FixedItemInv, ItemTransferable {
private InventoryComponent component;
public AttributeWrapper(InventoryComponent component) {
this.component = component;
}
@Override
public ItemInsertable getInsertable() {
return this;
}
@Override
public ItemExtractable getExtractable() {
return this;
}
@Override
public int getSlotCount() {
return component.size();
}
@Override
public ItemStack getInvStack(int slot) {
return component.getStack(slot);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return component.isAcceptableStack(slot, stack);
}
@Override
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
if (simulation.isAction()) component.setStack(slot, to);
return true;
}
@Override
public int getChangeValue() {
return 0; //TODO: impl?
}
@Nullable
@Override
public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken) {
return null; //TODO: impl?
}
@Override
public ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) {
return component.removeStack(0, maxAmount, actionForSim(simulation)); //TODO: fix
}
@Override
public ItemStack attemptInsertion(ItemStack stack, Simulation simulation) {
return component.insertStack(stack, actionForSim(simulation));
}
private ActionType actionForSim(Simulation simulation) {
if (simulation.isAction()) return ActionType.PERFORM;
else return ActionType.TEST;
}
}