Skip to content

Commit

Permalink
Thread safe item property registration
Browse files Browse the repository at this point in the history
  • Loading branch information
NeRdTheNed committed Jun 30, 2023
1 parent 2862cd6 commit 53844c8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/main/java/iDiamondhunter/morebows/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ public static void registerRenderer(EntityRenderersEvent.RegisterRenderers event

@SubscribeEvent
public static void onInitializeClient(FMLClientSetupEvent event) {
final ResourceLocation PULL = new ResourceLocation("pull");
final ResourceLocation PULLING = new ResourceLocation("pulling");
final ItemPropertyFunction PULL_PROVIDER = (stack, world, entity, unused) -> ((entity == null) || (entity.getUseItem() != stack) ? 0.0F : (stack.getUseDuration() - entity.getUseItemRemainingTicks()) / ((CustomBow) stack.getItem()).powerDiv);
final ItemPropertyFunction PULLING_PROVIDER = (stack, world, entity, unused) -> ((entity != null) && entity.isUsingItem() && (entity.getUseItem() == stack) ? 1.0F : 0.0F);

for (final Item bow : MoreBows.getAllItems()) {
ItemProperties.register(bow, PULL, PULL_PROVIDER);
ItemProperties.register(bow, PULLING, PULLING_PROVIDER);
}

final Item[] bows = MoreBows.getAllItems();
event.enqueueWork(() -> {
final ResourceLocation PULL = new ResourceLocation("pull");
final ResourceLocation PULLING = new ResourceLocation("pulling");
final ItemPropertyFunction PULL_PROVIDER = (stack, world, entity, unused) -> ((entity == null) || (entity.getUseItem() != stack) ? 0.0F : (stack.getUseDuration() - entity.getUseItemRemainingTicks()) / ((CustomBow) stack.getItem()).powerDiv);
final ItemPropertyFunction PULLING_PROVIDER = (stack, world, entity, unused) -> ((entity != null) && entity.isUsingItem() && (entity.getUseItem() == stack) ? 1.0F : 0.0F);

for (final Item bow : bows) {
ItemProperties.register(bow, PULL, PULL_PROVIDER);
ItemProperties.register(bow, PULLING, PULLING_PROVIDER);
}
});
final Client clientListener = new Client();
MinecraftForge.EVENT_BUS.addListener(clientListener::FOV);
MinecraftForge.EVENT_BUS.addListener(clientListener::renderBow);
Expand Down

0 comments on commit 53844c8

Please sign in to comment.