Skip to content

Commit

Permalink
Add item properties to bows
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Jan 12, 2023
1 parent cb39fd4 commit 6b464fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@
import slimeknights.tconstruct.plugin.jsonthings.item.FlexModifiableItem;
import slimeknights.tconstruct.plugin.jsonthings.item.FlexToolPartItem;

import java.util.ArrayList;
import java.util.List;

/** Collection of custom item types added by Tinkers */
public class FlexItemTypes {
/** All bow items that need their predicate registered */
static final List<Item> BOW_ITEMS = new ArrayList<>();
/** All crossbow items that need their predicate registered */
static final List<Item> CROSSBOW_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;
}

/** Register a modifiable tool instance for melee/harvest tools */
public static final ItemType<FlexToolPartItem> TOOL_PART = register("tool_part", data -> {
MaterialStatsId statType = new MaterialStatsId(JsonHelper.getResourceLocation(data, "stat_type"));
Expand All @@ -34,14 +48,15 @@ public class FlexItemTypes {
/** Register a modifiable tool instance for bow like items (release on finish) */
public static final ItemType<FlexModifiableBowItem> BOW = register("bow", data -> {
IToolStatProvider statProvider = data.has("stat_provider") ? ToolStatProviders.REGISTRY.deserialize(data, "stat_provider") : ToolStatProviders.RANGED;
return (props, builder) -> new FlexModifiableBowItem(props, ToolDefinition.builder(builder.getRegistryName()).setStatsProvider(statProvider).build());
return (props, builder) -> add(BOW_ITEMS, new FlexModifiableBowItem(props, ToolDefinition.builder(builder.getRegistryName()).setStatsProvider(statProvider).build()));
});

/** Register a modifiable tool instance for crossbow like items (load on finish) */
public static final ItemType<FlexModifiableCrossbowItem> CROSSBOW = register("crossbow", data -> {
IToolStatProvider statProvider = data.has("stat_provider") ? ToolStatProviders.REGISTRY.deserialize(data, "stat_provider") : ToolStatProviders.RANGED;
boolean allowFireworks = GsonHelper.getAsBoolean(data, "allow_fireworks");
return (props, builder) -> new FlexModifiableCrossbowItem(props, ToolDefinition.builder(builder.getRegistryName()).setStatsProvider(statProvider).build(), allowFireworks);
return (props, builder) -> add(allowFireworks ? CROSSBOW_ITEMS : BOW_ITEMS,
new FlexModifiableCrossbowItem(props, ToolDefinition.builder(builder.getRegistryName()).setStatsProvider(statProvider).build(), allowFireworks));
});

/** Initializes the item types */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package slimeknights.tconstruct.plugin.jsonthings;

import dev.gigaherz.jsonthings.things.client.ItemColorHandler;
import net.minecraft.world.item.Item;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.client.model.TinkerItemProperties;
import slimeknights.tconstruct.library.client.model.tools.ToolModel;

/** Handles anything that requires clientside class loading */
public class PluginClient {
public static void init() {
ItemColorHandler.register(TConstruct.resourceString("tool"), block -> ToolModel.COLOR_HANDLER);
FMLJavaModLoadingContext.get().getModEventBus().addListener(PluginClient::clientSetup);
}

private static void clientSetup(FMLClientSetupEvent event) {
for (Item item : FlexItemTypes.BOW_ITEMS) {
TinkerItemProperties.registerBowProperties(item);
}
for (Item item : FlexItemTypes.CROSSBOW_ITEMS) {
TinkerItemProperties.registerCrossbowProperties(item);
}
}
}

0 comments on commit 6b464fa

Please sign in to comment.