Skip to content

Commit

Permalink
Merge pull request #247 from gottsch/1.16.5-develop
Browse files Browse the repository at this point in the history
1.16.5 develop
  • Loading branch information
gottsch authored Aug 31, 2021
2 parents eac1430 + 95f4482 commit a6eccf5
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry combineaccessrules="false" kind="src" path="/GottschCore"/>
<classpathentry combineaccessrules="false" kind="src" path="/forge-1.16.5-36.2.0"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/ModCommonLibs/libs/curios-forge-1.16.5-4.0.5.2.jar" sourcepath="/ModCommonLibs/libs/curios-forge-1.16.5-4.0.5.2.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/gottsch-minecraft-GottschCore"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
30 changes: 1 addition & 29 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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
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
Expand Down
44 changes: 40 additions & 4 deletions src/main/java/com/someguyssoftware/treasure2/Treasure.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
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;
import com.someguyssoftware.treasure2.particle.TreasureParticles;

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;
import net.minecraftforge.fml.config.ModConfig.ModConfigEvent;
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;

/**
*
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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.
*/
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
*/
Expand All @@ -183,11 +193,11 @@ private static void processCharms(Event event, ServerPlayerEntity player) {
* @param player
* @return
*/
private static List<CharmContext> gatherCharms(Event event, ServerPlayerEntity player) {
private List<CharmContext> gatherCharms(Event event, ServerPlayerEntity player) {
final List<CharmContext> 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()) {
Expand Down Expand Up @@ -222,49 +232,10 @@ private static List<CharmContext> gatherCharms(Event event, ServerPlayerEntity p
}
}

// check slots
if (slotProviderId.equals(CURIOS_ID)) {
// check curio slots
LazyOptional<ICuriosItemHandler> 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<ICurioStacksHandler> 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<CharmContext> equipmentContexts = getEquipmentCharmHandler().handleEquipmentCharms(event, player);
contexts.addAll(equipmentContexts);

return contexts;
}

Expand All @@ -274,7 +245,7 @@ private static List<CharmContext> gatherCharms(Event event, ServerPlayerEntity p
* @param player
* @param contexts
*/
private static void executeCharms(Event event, ServerPlayerEntity player, List<CharmContext> contexts) {
private void executeCharms(Event event, ServerPlayerEntity player, List<CharmContext> contexts) {
/*
* a list of charm types that are non-stackable that should not be executed more than once.
*/
Expand Down Expand Up @@ -312,7 +283,16 @@ private static void executeCharms(Event event, ServerPlayerEntity player, List<C
}
});
}

/**
*
* @return
*/
private IEquipmentCharmHandler getEquipmentCharmHandler() {
return equipmentCharmHandler;
}

// TODO move to a new event handler
/**
*
* @param event
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl>.
*/
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<String> CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm");

@Override
public List<CharmContext> handleEquipmentCharms(Event event, ServerPlayerEntity player) {
List<CharmContext> contexts = new ArrayList<>();

// check curio slots
LazyOptional<ICuriosItemHandler> 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<ICurioStacksHandler> 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;
}
}
Loading

0 comments on commit a6eccf5

Please sign in to comment.