-
Notifications
You must be signed in to change notification settings - Fork 754
/
MobDisguiseModule.java
62 lines (54 loc) · 2.61 KB
/
MobDisguiseModule.java
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
package slimeknights.tconstruct.library.modifiers.modules.armor;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot.Type;
import slimeknights.mantle.data.loadable.Loadables;
import slimeknights.mantle.data.loadable.record.RecordLoadable;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.ModifierHooks;
import slimeknights.tconstruct.library.modifiers.hook.armor.EquipmentChangeModifierHook;
import slimeknights.tconstruct.library.modifiers.modules.ModifierModule;
import slimeknights.tconstruct.library.module.HookProvider;
import slimeknights.tconstruct.library.module.ModuleHook;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability.ComputableDataKey;
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import java.util.List;
/**
* Module for armor modifiers that makes this entity appear to be another entity from afar
*/
public record MobDisguiseModule(EntityType<?> entity) implements EquipmentChangeModifierHook, ModifierModule {
private static final List<ModuleHook<?>> DEFAULT_HOOKS = HookProvider.<MobDisguiseModule>defaultHooks(ModifierHooks.EQUIPMENT_CHANGE);
public static final RecordLoadable<MobDisguiseModule> LOADER = RecordLoadable.create(Loadables.ENTITY_TYPE.requiredField("entity", MobDisguiseModule::entity), MobDisguiseModule::new);
/**
* Data key for all disguises on an entity
*/
public static final ComputableDataKey<Multiset<EntityType<?>>> DISGUISES = TConstruct.createKey("mob_disguise", HashMultiset::create);
@Override
public void onEquip(IToolStackView tool, ModifierEntry modifier, EquipmentChangeContext context) {
if (context.getChangedSlot().getType() == Type.ARMOR) {
context.getTinkerData().ifPresent(data -> data.computeIfAbsent(DISGUISES).add(entity));
}
}
@Override
public void onUnequip(IToolStackView tool, ModifierEntry modifier, EquipmentChangeContext context) {
if (context.getChangedSlot().getType() == Type.ARMOR) {
context.getTinkerData().ifPresent(data -> {
Multiset<EntityType<?>> disguises = data.get(DISGUISES);
if (disguises != null) {
disguises.remove(entity);
}
});
}
}
@Override
public List<ModuleHook<?>> getDefaultHooks() {
return DEFAULT_HOOKS;
}
@Override
public RecordLoadable<MobDisguiseModule> getLoader() {
return LOADER;
}
}