-
Notifications
You must be signed in to change notification settings - Fork 755
/
FlexItemTypes.java
101 lines (87 loc) · 5.18 KB
/
FlexItemTypes.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package slimeknights.tconstruct.plugin.jsonthings;
import dev.gigaherz.jsonthings.things.IFlexItem;
import dev.gigaherz.jsonthings.things.serializers.FlexItemType;
import dev.gigaherz.jsonthings.things.serializers.IItemSerializer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.Item;
import slimeknights.mantle.data.loadable.Loadable;
import slimeknights.mantle.data.loadable.Loadables;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.client.armor.texture.ArmorTextureSupplier;
import slimeknights.tconstruct.library.materials.stats.MaterialStatsId;
import slimeknights.tconstruct.library.tools.definition.ToolDefinition;
import slimeknights.tconstruct.library.tools.item.armor.DummyArmorMaterial;
import slimeknights.tconstruct.plugin.jsonthings.item.FlexModifiableBowItem;
import slimeknights.tconstruct.plugin.jsonthings.item.FlexModifiableCrossbowItem;
import slimeknights.tconstruct.plugin.jsonthings.item.FlexModifiableItem;
import slimeknights.tconstruct.plugin.jsonthings.item.FlexRepairKitItem;
import slimeknights.tconstruct.plugin.jsonthings.item.FlexToolPartItem;
import slimeknights.tconstruct.plugin.jsonthings.item.armor.FlexModifiableArmorItem;
import slimeknights.tconstruct.plugin.jsonthings.item.armor.FlexMultilayerArmorModel;
import slimeknights.tconstruct.tools.item.ArmorSlotType;
import java.util.ArrayList;
import java.util.List;
/** Collection of custom item types added by Tinkers */
@SuppressWarnings("unused")
public class FlexItemTypes {
/** Standard tools that need standard properties */
static final List<Item> TOOL_ITEMS = new ArrayList<>();
/** All crossbow items that need their predicate registered */
static final List<Item> CROSSBOW_ITEMS = new ArrayList<>();
/** All armor items that need the broken predicate */
static final List<Item> ARMOR_ITEMS = new ArrayList<>();
/** Adds a thing to a list so we can fetch the instances later */
private static <T> T add(List<? super T> list, T item) {
list.add(item);
return item;
}
/** Initializes the item types */
public static void init() {
/* Register a tool part to create new tools */
register("tool_part", data -> {
MaterialStatsId statType = new MaterialStatsId(JsonHelper.getResourceLocation(data, "stat_type"));
return (props, builder) -> new FlexToolPartItem(props, statType);
});
/* Register an item that can be used to repair tools */
register("repair_kit", data -> {
float repairAmount = GsonHelper.getAsFloat(data, "repair_amount");
return (props, builder) -> new FlexRepairKitItem(props, repairAmount);
});
/* Register a modifiable tool instance for melee/harvest tools */
register("tool", data -> {
boolean breakBlocksInCreative = GsonHelper.getAsBoolean(data, "break_blocks_in_creative", true);
return (props, builder) -> add(TOOL_ITEMS, new FlexModifiableItem(props, ToolDefinition.create(builder.getRegistryName()), breakBlocksInCreative));
});
/* Register a modifiable tool instance for bow like items (release on finish) */
register("bow", data -> (props, builder) -> add(TOOL_ITEMS, new FlexModifiableBowItem(props, ToolDefinition.create(builder.getRegistryName()))));
/* Register a modifiable tool instance for crossbow like items (load on finish) */
register("crossbow", data -> {
boolean allowFireworks = GsonHelper.getAsBoolean(data, "allow_fireworks");
return (props, builder) -> add(CROSSBOW_ITEMS, new FlexModifiableCrossbowItem(props, ToolDefinition.create(builder.getRegistryName()), allowFireworks));
});
/* Armor */
/* Simple armor type with a flat texture */
register("basic_armor", data -> {
ResourceLocation name = JsonHelper.getResourceLocation(data, "texture_name");
SoundEvent sound = Loadables.SOUND_EVENT.getOrDefault(data, "equip_sound", SoundEvents.ARMOR_EQUIP_GENERIC);
ArmorSlotType slot = JsonHelper.getAsEnum(data, "slot", ArmorSlotType.class);
return (props, builder) -> add(ARMOR_ITEMS, new FlexModifiableArmorItem(new DummyArmorMaterial(name, sound), slot.getEquipmentSlot(), props, ToolDefinition.create(builder.getRegistryName())));
});
/* Layered armor type, used for golden, dyeable, etc */
Loadable<List<ArmorTextureSupplier>> ARMOR_TEXTURES = ArmorTextureSupplier.LOADER.list(1);
register("multilayer_armor", data -> {
ResourceLocation name = JsonHelper.getResourceLocation(data, "model_name");
SoundEvent sound = Loadables.SOUND_EVENT.getOrDefault(data, "equip_sound", SoundEvents.ARMOR_EQUIP_GENERIC);
ArmorSlotType slot = JsonHelper.getAsEnum(data, "slot", ArmorSlotType.class);
return (props, builder) -> add(ARMOR_ITEMS, new FlexMultilayerArmorModel(new DummyArmorMaterial(name, sound), slot.getEquipmentSlot(), props, ToolDefinition.create(builder.getRegistryName())));
});
}
/** Local helper to register our stuff */
private static <T extends Item & IFlexItem> void register(String name, IItemSerializer<T> factory) {
FlexItemType.register(TConstruct.resourceString(name), factory);
}
}