diff --git a/.classpath b/.classpath index f170b8c90..24758fffe 100644 --- a/.classpath +++ b/.classpath @@ -2,9 +2,9 @@ - + diff --git a/build.gradle b/build.gradle index c8ab1b060..1617c6b77 100644 --- a/build.gradle +++ b/build.gradle @@ -108,7 +108,7 @@ repositories { } } -def gottschcore_path="../gottsch-minecraft-GottschCore/build/libs/GottschCore-mc${mc_version}-f${gottschcore_forge_version}-v${gottschcore_version}.jar" +def gottschcore_path="../GottschCore/build/libs/GottschCore-mc${mc_version}-f${gottschcore_forge_version}-v${gottschcore_version}.jar" println gottschcore_path dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed @@ -137,31 +137,3 @@ jar { } } -// an array containing destination paths -def destinations = ["${dest_folder}", "${mods_folder}"] - -task deleteOldJar(type: Delete) { - destinations.each { destination -> - print 'deleting... ' - println destination -// delete fileTree(destination) { - // include "**/${mod_name}-mc${mc_version}-f${forge_version}-*.jar" -// } - delete "${destination}/${mod_name}-mc${mc_version}-f${forge_version}-*.jar" - } -} - -task copyJar() { - // iterate over the array with destination paths - destinations.each { destination -> - // for every destination define new CopySpec - println destination - copy { - from jar - into destination - } - } -} - -deleteOldJar.dependsOn minecraft -copyJar.dependsOn deleteOldJar \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 5b669fb7e..1cf25ea05 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ package_group=someguyssoftware.treasure2 # use alpha, beta, or v (for version) mod_version_type=v -mod_version=1.6.0 +mod_version=1.6.1 #versions @@ -15,7 +15,7 @@ mc_version=1.16.5 forge_version=36.2.0 mappings_channel=official mappings_version=1.16.5 -gottschcore_version=1.3.0 +gottschcore_version=1.4.0 gottschcore_forge_version=36.1.0 # paths diff --git a/src/main/java/com/someguyssoftware/treasure2/Treasure.java b/src/main/java/com/someguyssoftware/treasure2/Treasure.java index 998264acf..2d0236510 100644 --- a/src/main/java/com/someguyssoftware/treasure2/Treasure.java +++ b/src/main/java/com/someguyssoftware/treasure2/Treasure.java @@ -10,7 +10,9 @@ import com.someguyssoftware.treasure2.charm.TreasureCharms; import com.someguyssoftware.treasure2.config.TreasureConfig; import com.someguyssoftware.treasure2.entity.TreasureEntities; -import com.someguyssoftware.treasure2.eventhandler.PlayerEventHandler; +import com.someguyssoftware.treasure2.eventhandler.CharmEventHandler; +import com.someguyssoftware.treasure2.eventhandler.HotbarEquipmentCharmHandler; +import com.someguyssoftware.treasure2.eventhandler.IEquipmentCharmHandler; import com.someguyssoftware.treasure2.eventhandler.WorldEventHandler; import com.someguyssoftware.treasure2.init.TreasureSetup; import com.someguyssoftware.treasure2.network.TreasureNetworking; @@ -18,6 +20,8 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.InterModComms; +import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; @@ -25,8 +29,11 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLPaths; +import top.theillusivec4.curios.api.SlotTypeMessage; +import top.theillusivec4.curios.api.SlotTypePreset; /** * @@ -55,7 +62,7 @@ public class Treasure implements IMod { // constants public static final String MODID = "treasure2"; protected static final String NAME = "Treasure2"; - protected static final String VERSION = "1.6.0"; + protected static final String VERSION = "1.6.1"; protected static final String UPDATE_JSON_URL = "https://raw.githubusercontent.com/gottsch/gottsch-minecraft-Treasure/1.16.5-master/update.json"; @@ -83,12 +90,41 @@ public Treasure() { eventBus.addListener(TreasureCharms::setup); eventBus.addListener(TreasureSetup::clientSetup); eventBus.addListener(this::clientSetup); + eventBus.addListener(this::interModComms); - // needs to be registered here instead of @Mod.EventBusSubscriber because we need to pass in a constructor argument + // needs to be registered here instead of @Mod.EventBusSubscriber because an instance of the handler + // is required and constructor arguments may need to be passed in MinecraftForge.EVENT_BUS.register(new WorldEventHandler(getInstance())); - MinecraftForge.EVENT_BUS.register(new PlayerEventHandler()); // need to register here? + + IEquipmentCharmHandler equipmentCharmHandler = null; + if (ModList.get().isLoaded("curios")) { + LOGGER.debug("curios IS loaded"); + try { + equipmentCharmHandler = + (IEquipmentCharmHandler) Class.forName("com.someguyssoftware.treasure2.eventhandler.CuriosEquipmentCharmHandler").newInstance(); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + LOGGER.warn("Unable to load Curios compatiblity class."); + } + } + if (equipmentCharmHandler == null) { + LOGGER.debug("equipmentHandler is null"); + equipmentCharmHandler = new HotbarEquipmentCharmHandler(); + } + MinecraftForge.EVENT_BUS.register(new CharmEventHandler(equipmentCharmHandler)); } + /** + * + * @param event + */ + private void interModComms(InterModEnqueueEvent event) { + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.CHARM.getMessageBuilder().build()); + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.NECKLACE.getMessageBuilder().build()); + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.RING.getMessageBuilder().build()); + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.BRACELET.getMessageBuilder().build()); + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.BELT.getMessageBuilder().build()); + } + public static void clientOnly() { } diff --git a/src/main/java/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java b/src/main/java/com/someguyssoftware/treasure2/eventhandler/CharmEventHandler.java similarity index 77% rename from src/main/java/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java rename to src/main/java/com/someguyssoftware/treasure2/eventhandler/CharmEventHandler.java index c321179de..c8326c3f4 100644 --- a/src/main/java/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java +++ b/src/main/java/com/someguyssoftware/treasure2/eventhandler/CharmEventHandler.java @@ -67,11 +67,21 @@ * @author Mark Gottschling on Apr 26, 2018 * */ -@Mod.EventBusSubscriber(modid = Treasure.MODID, bus = EventBusSubscriber.Bus.FORGE) -public class PlayerEventHandler { - private static final String CURIOS_ID = "curios"; - private static final List CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm"); +//@Mod.EventBusSubscriber(modid = Treasure.MODID, bus = EventBusSubscriber.Bus.FORGE) +public class CharmEventHandler { +// private static final String CURIOS_ID = "curios"; +// private static final List CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm"); + private IEquipmentCharmHandler equipmentCharmHandler; + + /** + * + * @param handler + */ + public CharmEventHandler(IEquipmentCharmHandler handler) { + equipmentCharmHandler = handler; + } + /* * Subscribing to multiple types of Living events for Charm Interactions so that instanceof doesn't have to be called everytime. */ @@ -81,7 +91,7 @@ public class PlayerEventHandler { * @param event */ @SubscribeEvent - public static void checkCharmsInteraction(LivingUpdateEvent event) { + public void checkCharmsInteraction(LivingUpdateEvent event) { if (WorldInfo.isClientSide(event.getEntity().level)) { return; } @@ -159,7 +169,7 @@ public void checkCharmsInteractionWithAttack(LivingHurtEvent event) { * @param event * @param player */ - private static void processCharms(Event event, ServerPlayerEntity player) { + private void processCharms(Event event, ServerPlayerEntity player) { /* * a list of charm contexts to execute */ @@ -183,11 +193,11 @@ private static void processCharms(Event event, ServerPlayerEntity player) { * @param player * @return */ - private static List gatherCharms(Event event, ServerPlayerEntity player) { + private List gatherCharms(Event event, ServerPlayerEntity player) { final List contexts = new ArrayList<>(5); // get the slot provider - curios (general slots) or minecraft (hotbar) - String slotProviderId = ModList.get().isLoaded(CURIOS_ID) ? CURIOS_ID : "minecaft"; +// String slotProviderId = ModList.get().isLoaded(CURIOS_ID) ? CURIOS_ID : "minecaft"; // check each hand for (Hand hand : Hand.values()) { @@ -222,49 +232,10 @@ private static List gatherCharms(Event event, ServerPlayerEntity p } } - // check slots - if (slotProviderId.equals(CURIOS_ID)) { - // check curio slots - LazyOptional handler = CuriosApi.getCuriosHelper().getCuriosHandler(player); - handler.ifPresent(itemHandler -> { - // curios type names -> head, necklace, back, bracelet, hands, ring, belt, charm, feet - CURIOS_SLOTS.forEach(slot -> { - Optional stacksOptional = itemHandler.getStacksHandler(slot); - stacksOptional.ifPresent(stacksHandler -> { - ItemStack curiosStack = stacksHandler.getStacks().getStackInSlot(0); - curiosStack.getCapability(TreasureCapabilities.CHARMABLE).ifPresent(cap -> { - for (InventoryType type : InventoryType.values()) { - AtomicInteger index = new AtomicInteger(); - // requires indexed for-loop - for (int i = 0; i < cap.getCharmEntities()[type.getValue()].size(); i++) { - ICharmEntity entity = cap.getCharmEntities()[type.getValue()].get(i); - // if (!TreasureCharms.isCharmEventRegistered(event.getClass(), entity.getCharm().getType())) { - if (!entity.getCharm().getRegisteredEvent().equals(event.getClass())) { - // Treasure.LOGGER.debug("charm type -> {} is not register for this event -> {}", entity.getCharm().getType(), event.getClass().getSimpleName()); - continue; - } - index.set(i); - CharmContext curiosContext = new CharmContext.Builder().with($ -> { - $.slotProviderId = slotProviderId; - $.slot = slot; - $.itemStack = curiosStack; - $.capability = cap; - $.type = type; - $.index = index.get(); - $.entity = entity; - }).build(); - contexts.add(curiosContext); - } - } - }); - }); - }); - }); - } - else { - // TODO check hotbar slots - // TODO only allow IAdornments from hotbar - } + // check equipment slots + List equipmentContexts = getEquipmentCharmHandler().handleEquipmentCharms(event, player); + contexts.addAll(equipmentContexts); + return contexts; } @@ -274,7 +245,7 @@ private static List gatherCharms(Event event, ServerPlayerEntity p * @param player * @param contexts */ - private static void executeCharms(Event event, ServerPlayerEntity player, List contexts) { + private void executeCharms(Event event, ServerPlayerEntity player, List contexts) { /* * a list of charm types that are non-stackable that should not be executed more than once. */ @@ -312,7 +283,16 @@ private static void executeCharms(Event event, ServerPlayerEntity player, List. + */ +package com.someguyssoftware.treasure2.eventhandler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; + +import com.someguyssoftware.treasure2.capability.CharmableCapability.InventoryType; +import com.someguyssoftware.treasure2.capability.TreasureCapabilities; +import com.someguyssoftware.treasure2.charm.CharmContext; +import com.someguyssoftware.treasure2.charm.ICharmEntity; + +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.eventbus.api.Event; +import top.theillusivec4.curios.api.CuriosApi; +import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler; +import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler; + +/** + * + * @author Mark Gottschling on Aug 30, 2021 + * + */ +public class CuriosEquipmentCharmHandler implements IEquipmentCharmHandler { + private static final String CURIOS_ID = "curios"; + private static final List CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm"); + + @Override + public List handleEquipmentCharms(Event event, ServerPlayerEntity player) { + List contexts = new ArrayList<>(); + + // check curio slots + LazyOptional handler = CuriosApi.getCuriosHelper().getCuriosHandler(player); + handler.ifPresent(itemHandler -> { + // curios type names -> head, necklace, back, bracelet, hands, ring, belt, charm, feet + CURIOS_SLOTS.forEach(slot -> { + Optional stacksOptional = itemHandler.getStacksHandler(slot); + stacksOptional.ifPresent(stacksHandler -> { + ItemStack curiosStack = stacksHandler.getStacks().getStackInSlot(0); + curiosStack.getCapability(TreasureCapabilities.CHARMABLE).ifPresent(cap -> { + for (InventoryType type : InventoryType.values()) { + AtomicInteger index = new AtomicInteger(); + // requires indexed for-loop + for (int i = 0; i < cap.getCharmEntities()[type.getValue()].size(); i++) { + ICharmEntity entity = cap.getCharmEntities()[type.getValue()].get(i); + // if (!TreasureCharms.isCharmEventRegistered(event.getClass(), entity.getCharm().getType())) { + if (!entity.getCharm().getRegisteredEvent().equals(event.getClass())) { + // Treasure.LOGGER.debug("charm type -> {} is not register for this event -> {}", entity.getCharm().getType(), event.getClass().getSimpleName()); + continue; + } + index.set(i); + CharmContext curiosContext = new CharmContext.Builder().with($ -> { + $.slotProviderId = CURIOS_ID; + $.slot = slot; + $.itemStack = curiosStack; + $.capability = cap; + $.type = type; + $.index = index.get(); + $.entity = entity; + }).build(); + contexts.add(curiosContext); + } + } + }); + }); + }); + }); + return contexts; + } +} diff --git a/src/main/java/com/someguyssoftware/treasure2/eventhandler/HotbarEquipmentCharmHandler.java b/src/main/java/com/someguyssoftware/treasure2/eventhandler/HotbarEquipmentCharmHandler.java new file mode 100644 index 000000000..3913afa48 --- /dev/null +++ b/src/main/java/com/someguyssoftware/treasure2/eventhandler/HotbarEquipmentCharmHandler.java @@ -0,0 +1,43 @@ +/* + * This file is part of Treasure2. + * Copyright (c) 2021, Mark Gottschling (gottsch) + * + * All rights reserved. + * + * Treasure2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Treasure2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Treasure2. If not, see . + */ +package com.someguyssoftware.treasure2.eventhandler; + +import java.util.ArrayList; +import java.util.List; + +import com.someguyssoftware.treasure2.Treasure; +import com.someguyssoftware.treasure2.charm.CharmContext; + +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraftforge.eventbus.api.Event; + +/** + * + * @author Mark Gottschling on Aug 30, 2021 + * + */ +public class HotbarEquipmentCharmHandler implements IEquipmentCharmHandler { + + @Override + public List handleEquipmentCharms(Event event, ServerPlayerEntity player) { + return new ArrayList<>(1); + } + +} diff --git a/src/main/java/com/someguyssoftware/treasure2/eventhandler/IEquipmentCharmHandler.java b/src/main/java/com/someguyssoftware/treasure2/eventhandler/IEquipmentCharmHandler.java new file mode 100644 index 000000000..25a877d49 --- /dev/null +++ b/src/main/java/com/someguyssoftware/treasure2/eventhandler/IEquipmentCharmHandler.java @@ -0,0 +1,37 @@ +/* + * This file is part of Treasure2. + * Copyright (c) 2021, Mark Gottschling (gottsch) + * + * All rights reserved. + * + * Treasure2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Treasure2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Treasure2. If not, see . + */ +package com.someguyssoftware.treasure2.eventhandler; + +import java.util.List; + +import com.someguyssoftware.treasure2.charm.CharmContext; + +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraftforge.eventbus.api.Event; + +/** + * + * @author Mark Gottschling on Aug 30, 2021 + * + */ +public interface IEquipmentCharmHandler { + + public List handleEquipmentCharms(Event event, ServerPlayerEntity player); +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 70d8b0483..7a67dc271 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -17,7 +17,7 @@ issueTrackerURL="https://github.com/gottsch/gottsch-minecraft-Treasure/issues" # modId="treasure2" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it -version="1.6.0" #mandatory +version="1.6.1" #mandatory # A display name for the mod @@ -73,3 +73,4 @@ Base API for all my mods. ordering="BEFORE" # Side this dependency is applied on - BOTH, CLIENT or SERVER side="BOTH" + diff --git a/update.json b/update.json index 66e81425a..2263355a8 100644 --- a/update.json +++ b/update.json @@ -1,14 +1,15 @@ { "homepage": "https://minecraft.curseforge.com/projects/treasure2", "promos": { - "1.16.5-latest": "1.6.0", - "1.16.5-recommended": "1.6.0" + "1.16.5-latest": "1.6.1", + "1.16.5-recommended": "1.6.1" }, "1.16.5": { "1.0.0": "Initial version release.", "1.0.1": "Fixed Ticking block entity on Bound Soul crash.\nFixed missing Loot Table error (for test.json).", "1.5.0": "Added mist - Gravestones, Bound Souls, and Wither Tree's poison and wither mist.\nAdded Key Ring.\nAdded key merging ability.\nAdded treasure maps to other Treasure chests.\nUpdated bounding boxes of gravestones.\nFixed Well and Wither Tree regitries.\nAttempt to fix LockItem.appendHoverText initialization crash with some performance mods.\nUses Forge-36.2.0", "1.5.1": "Fixed java.lang.NullPointerException: Initializing game at net.minecraft.item.Item.handler$zpo000$getDisplayName(Item.java:526) ~[?:?]", - "1.6.0": "Added Charms (except Harvesting).\nAdded Pouch Item.(standard only, Lucks, Apprentice and Master will not be added).\nUses GottschCore 1.4.0 which fixes crash bug on mob spawn by ProximitySpawner.\nPrevent crashes when coins thrown in wells has an exception.\n" + "1.6.0": "Added Charms (except Harvesting).\nAdded Pouch Item.(standard only, Lucks, Apprentice and Master will not be added).\nUses GottschCore 1.4.0 which fixes crash bug on mob spawn by ProximitySpawner.\nPrevent crashes when coins thrown in wells has an exception.\n", + "1.6.1": "Fixed Curios required crash (it is optional)." } } \ No newline at end of file