diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e32c0d8..b7d0c6a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,12 +30,12 @@ jobs: with: curseforge-id: 657831 curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + modrinth-id: iRE67WIn + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} files-primary: build/libs/!(*-@(javadoc|sources)).jar version-type: release loaders: neoforge game-versions: 1.21 java: 21 name: "" - modrinth-id: iRE67WIn - modrinth-token: ${{ secrets.MODRINTH_TOKEN }} changelog-file: changelog-1.21.* diff --git a/changelog-1.21.txt b/changelog-1.21.txt index fd44353..e092b4f 100644 --- a/changelog-1.21.txt +++ b/changelog-1.21.txt @@ -1,2 +1,2 @@ -- Neoforge changes 2 electric boogalo -- Enabled buckler launch by default \ No newline at end of file +- Internal changes to how item properties are registered +- Allowed users to define items for other modded ziglin variants in datamaps \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index dacd949..34a44bf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ minecraft_version=1.21 # as they do not follow standard versioning conventions. minecraft_version_range=[1.21, 1.22) # The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=21.0.76-beta +neo_version=21.0.86-beta # The Neo version range can use any version of Neo as bounds or match the loader version range neo_version_range=[20.5.14,) # The loader version range can only use the major version of Neo/FML as bounds @@ -31,7 +31,7 @@ mod_name=Piglin Proliferation # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT for code, CC BY-NC-SA 4.0 for assets # The mod version. See https://semver.org/ -mod_version=2.0.4 +mod_version=2.0.5 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/tallestred/piglinproliferation/PPEvents.java b/src/main/java/tallestred/piglinproliferation/PPEvents.java index 3fdd59d..31beb11 100644 --- a/src/main/java/tallestred/piglinproliferation/PPEvents.java +++ b/src/main/java/tallestred/piglinproliferation/PPEvents.java @@ -25,6 +25,7 @@ import net.minecraft.world.entity.monster.piglin.PiglinBrute; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Arrow; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.Potions; @@ -307,11 +308,6 @@ public static void finalizeSpawn(FinalizeSpawnEvent event) { if (event.getEntity().getType() == EntityType.ZOMBIFIED_PIGLIN) { // Some mods have entities that extend zombified piglins in order to make their own ziglins have custom textures ZombifiedPiglin zombifiedPiglin = (ZombifiedPiglin) event.getEntity(); if (spawnType != MobSpawnType.CONVERSION) { - if (!ziglinVariants.isEmpty()) { - EntityType variantType = getRandomCustomVariant(random); - ResourceLocation resourcelocation = BuiltInRegistries.ENTITY_TYPE.getKey(variantType); - zombifiedPiglin.setData(PPDataAttachments.TRANSFORMATION_TRACKER.get(), resourcelocation.getPath()); - } if (random.nextFloat() < PPConfig.COMMON.zombifiedPiglinDefaultChance.get().floatValue()) zombifiedPiglin.setData(PPDataAttachments.TRANSFORMATION_TRACKER.get(), "piglin"); float bruteChance = PPConfig.COMMON.zombifiedBruteChance.get().floatValue(); @@ -334,6 +330,13 @@ public static void finalizeSpawn(FinalizeSpawnEvent event) { zombifiedPiglin.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.CROSSBOW)); } } + if (!ziglinVariants.isEmpty()) { + EntityType variantType = WeightedRandom.getRandomItem(random, ziglinVariants).orElseThrow().type(); + Item item = WeightedRandom.getRandomItem(random, ziglinVariants).orElseThrow().itemId(); + ResourceLocation resourcelocation = BuiltInRegistries.ENTITY_TYPE.getKey(variantType); + zombifiedPiglin.setData(PPDataAttachments.TRANSFORMATION_TRACKER.get(), resourcelocation.getPath()); + zombifiedPiglin.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(item)); + } } if (spawnType == MobSpawnType.JOCKEY) { event.setCanceled(true); @@ -344,16 +347,11 @@ public static void finalizeSpawn(FinalizeSpawnEvent event) { } } - public static EntityType getRandomCustomVariant(RandomSource rand) { - ZiglinVariantWeight mob = WeightedRandom.getRandomItem(rand, ziglinVariants).orElseThrow(); - return mob.type(); - } - @SubscribeEvent public static void onDataMapsUpdated(DataMapsUpdatedEvent event) { event.ifRegistry(Registries.ENTITY_TYPE, registry -> ziglinVariants = registry.getDataMap(PiglinProliferation.ZOMBIFIED_PIGLIN_VARIANT_DATA_MAP).entrySet().stream().map((entry) -> { EntityType type = Objects.requireNonNull(registry.get(entry.getKey()), "Nonexistent entity " + entry.getKey() + " in modded ziglin variant datamap!"); - return new ZiglinVariantWeight(type, entry.getValue().weight()); + return new ZiglinVariantWeight(type, entry.getValue().weight(), entry.getValue().itemID()); }).toList()); } diff --git a/src/main/java/tallestred/piglinproliferation/PiglinProliferation.java b/src/main/java/tallestred/piglinproliferation/PiglinProliferation.java index cab92ea..ae11004 100644 --- a/src/main/java/tallestred/piglinproliferation/PiglinProliferation.java +++ b/src/main/java/tallestred/piglinproliferation/PiglinProliferation.java @@ -84,8 +84,6 @@ public PiglinProliferation(IEventBus modEventBus, Dist dist, ModContainer contai modEventBus.addListener(this::addCreativeTabs); modEventBus.addListener(this::registerPackets); modEventBus.addListener(this::addDataMaps); - if (dist == Dist.CLIENT) - modEventBus.addListener(this::doClientStuff); NeoForge.EVENT_BUS.addListener(this::serverStart); PPSounds.SOUNDS.register(modEventBus); PPAttributes.ATTRIBUTES.register(modEventBus); @@ -147,6 +145,8 @@ private void addCreativeTabs(final BuildCreativeModeTabContentsEvent event) { ); } else if (CreativeModeTabs.COMBAT.equals(event.getTabKey())) { addToCreativeTabAfter(event, Items.SHIELD, PPItems.BUCKLER.get()); + } else if (CreativeModeTabs.TOOLS_AND_UTILITIES.equals(event.getTabKey())) { + addToCreativeTabAfter(event, Items.RECOVERY_COMPASS, PPItems.TRAVELERS_COMPASS.get()); } } @@ -179,26 +179,6 @@ private void enqueueIMC(final InterModEnqueueEvent event) { private void processIMC(final InterModProcessEvent event) { } - - @OnlyIn(Dist.CLIENT) - private void doClientStuff(final FMLClientSetupEvent event) { - event.enqueueWork(() -> { - ItemProperties.register(PPItems.BUCKLER.get(), ResourceLocation.parse("blocking"), - (stack, clientWorld, livingEntity, useTime) -> { - boolean active = livingEntity != null && livingEntity.isUsingItem() - && livingEntity.getUseItem() == stack - || livingEntity != null && BucklerItem.isReady(stack); - return livingEntity != null && active ? 1.0F : 0.0F; - }); - ItemProperties.register(PPItems.TRAVELERS_COMPASS.get(), ResourceLocation.parse("angle"), new CompassItemPropertyFunction((level, itemStack, player) -> { - TravelersCompassTracker tracker = itemStack.get(PPComponents.TRAVELERS_COMPASS_TRACKER); - if (tracker != null) - return tracker.target(); - return null; //TODO not sure - })); - }); - } - private void serverStart(final ServerAboutToStartEvent event) { Registry templatePoolRegistry = event.getServer().registryAccess().registry(Registries.TEMPLATE_POOL).orElseThrow(); Registry processorListRegistry = event.getServer().registryAccess().registry(Registries.PROCESSOR_LIST).orElseThrow(); diff --git a/src/main/java/tallestred/piglinproliferation/PiglinProliferationClient.java b/src/main/java/tallestred/piglinproliferation/PiglinProliferationClient.java new file mode 100644 index 0000000..2277114 --- /dev/null +++ b/src/main/java/tallestred/piglinproliferation/PiglinProliferationClient.java @@ -0,0 +1,39 @@ +package tallestred.piglinproliferation; + +import net.minecraft.client.renderer.item.CompassItemPropertyFunction; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import tallestred.piglinproliferation.common.items.BucklerItem; +import tallestred.piglinproliferation.common.items.PPItems; +import tallestred.piglinproliferation.common.items.component.PPComponents; +import tallestred.piglinproliferation.common.items.component.TravelersCompassTracker; + +@Mod(value = PiglinProliferation.MODID, dist = Dist.CLIENT) +public class PiglinProliferationClient { + public PiglinProliferationClient(IEventBus modEventBus, Dist dist, ModContainer container) { + modEventBus.addListener(this::doClientStuff); + } + + private void doClientStuff(final FMLClientSetupEvent event) { + event.enqueueWork(() -> { + ItemProperties.register(PPItems.BUCKLER.get(), ResourceLocation.parse("blocking"), + (stack, clientWorld, livingEntity, useTime) -> { + boolean active = livingEntity != null && livingEntity.isUsingItem() + && livingEntity.getUseItem() == stack + || livingEntity != null && BucklerItem.isReady(stack); + return livingEntity != null && active ? 1.0F : 0.0F; + }); + ItemProperties.register(PPItems.TRAVELERS_COMPASS.get(), ResourceLocation.parse("angle"), new CompassItemPropertyFunction((level, itemStack, player) -> { + TravelersCompassTracker tracker = itemStack.get(PPComponents.TRAVELERS_COMPASS_TRACKER); + if (tracker != null) + return tracker.target(); + return null; //TODO not sure + })); + }); + } +} diff --git a/src/main/java/tallestred/piglinproliferation/common/entities/ZiglinVariantWeight.java b/src/main/java/tallestred/piglinproliferation/common/entities/ZiglinVariantWeight.java index 5cdad0d..86257ef 100644 --- a/src/main/java/tallestred/piglinproliferation/common/entities/ZiglinVariantWeight.java +++ b/src/main/java/tallestred/piglinproliferation/common/entities/ZiglinVariantWeight.java @@ -3,8 +3,9 @@ import net.minecraft.util.random.Weight; import net.minecraft.util.random.WeightedEntry; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.Item; -public record ZiglinVariantWeight(EntityType type, Weight weight) implements WeightedEntry { +public record ZiglinVariantWeight(EntityType type, Weight weight, Item itemId) implements WeightedEntry { @Override public Weight getWeight() { return weight; diff --git a/src/main/java/tallestred/piglinproliferation/common/entities/ZombifiedPiglinVariant.java b/src/main/java/tallestred/piglinproliferation/common/entities/ZombifiedPiglinVariant.java index 9e31126..0773b62 100644 --- a/src/main/java/tallestred/piglinproliferation/common/entities/ZombifiedPiglinVariant.java +++ b/src/main/java/tallestred/piglinproliferation/common/entities/ZombifiedPiglinVariant.java @@ -2,13 +2,22 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.util.random.Weight; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; -public record ZombifiedPiglinVariant(Weight weight) { +import java.util.function.Function; + +public record ZombifiedPiglinVariant(Weight weight, Item itemID) { public static final Codec WEIGHT_CODEC = Weight.CODEC - .xmap(ZombifiedPiglinVariant::new, ZombifiedPiglinVariant::weight); + .xmap((Function) ZombifiedPiglinVariant::new, ZombifiedPiglinVariant::weight); public static final Codec CODEC = Codec.withAlternative( RecordCodecBuilder.create(in -> in.group( - Weight.CODEC.fieldOf("weight").forGetter(ZombifiedPiglinVariant::weight)).apply(in, ZombifiedPiglinVariant::new)), + Weight.CODEC.fieldOf("weight").forGetter(ZombifiedPiglinVariant::weight), BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(ZombifiedPiglinVariant::itemID)).apply(in, ZombifiedPiglinVariant::new)), WEIGHT_CODEC); + + public ZombifiedPiglinVariant(Weight weight) { + this(weight, Items.AIR); + } }