Skip to content

Commit a6eccf5

Browse files
authored
Merge pull request #247 from gottsch/1.16.5-develop
1.16.5 develop
2 parents eac1430 + 95f4482 commit a6eccf5

File tree

10 files changed

+254
-92
lines changed

10 files changed

+254
-92
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<classpath>
33
<classpathentry kind="src" path="src/main/java"/>
44
<classpathentry kind="src" path="src/main/resources"/>
5-
<classpathentry combineaccessrules="false" kind="src" path="/GottschCore"/>
65
<classpathentry combineaccessrules="false" kind="src" path="/forge-1.16.5-36.2.0"/>
76
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
87
<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"/>
8+
<classpathentry combineaccessrules="false" kind="src" path="/gottsch-minecraft-GottschCore"/>
99
<classpathentry kind="output" path="bin/default"/>
1010
</classpath>

build.gradle

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ repositories {
108108
}
109109
}
110110

111-
def gottschcore_path="../gottsch-minecraft-GottschCore/build/libs/GottschCore-mc${mc_version}-f${gottschcore_forge_version}-v${gottschcore_version}.jar"
111+
def gottschcore_path="../GottschCore/build/libs/GottschCore-mc${mc_version}-f${gottschcore_forge_version}-v${gottschcore_version}.jar"
112112
println gottschcore_path
113113
dependencies {
114114
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
@@ -137,31 +137,3 @@ jar {
137137
}
138138
}
139139

140-
// an array containing destination paths
141-
def destinations = ["${dest_folder}", "${mods_folder}"]
142-
143-
task deleteOldJar(type: Delete) {
144-
destinations.each { destination ->
145-
print 'deleting... '
146-
println destination
147-
// delete fileTree(destination) {
148-
// include "**/${mod_name}-mc${mc_version}-f${forge_version}-*.jar"
149-
// }
150-
delete "${destination}/${mod_name}-mc${mc_version}-f${forge_version}-*.jar"
151-
}
152-
}
153-
154-
task copyJar() {
155-
// iterate over the array with destination paths
156-
destinations.each { destination ->
157-
// for every destination define new CopySpec
158-
println destination
159-
copy {
160-
from jar
161-
into destination
162-
}
163-
}
164-
}
165-
166-
deleteOldJar.dependsOn minecraft
167-
copyJar.dependsOn deleteOldJar

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ package_group=someguyssoftware.treasure2
77
# use alpha, beta, or v (for version)
88
mod_version_type=v
99

10-
mod_version=1.6.0
10+
mod_version=1.6.1
1111

1212

1313
#versions
1414
mc_version=1.16.5
1515
forge_version=36.2.0
1616
mappings_channel=official
1717
mappings_version=1.16.5
18-
gottschcore_version=1.3.0
18+
gottschcore_version=1.4.0
1919
gottschcore_forge_version=36.1.0
2020

2121
# paths

src/main/java/com/someguyssoftware/treasure2/Treasure.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,30 @@
1010
import com.someguyssoftware.treasure2.charm.TreasureCharms;
1111
import com.someguyssoftware.treasure2.config.TreasureConfig;
1212
import com.someguyssoftware.treasure2.entity.TreasureEntities;
13-
import com.someguyssoftware.treasure2.eventhandler.PlayerEventHandler;
13+
import com.someguyssoftware.treasure2.eventhandler.CharmEventHandler;
14+
import com.someguyssoftware.treasure2.eventhandler.HotbarEquipmentCharmHandler;
15+
import com.someguyssoftware.treasure2.eventhandler.IEquipmentCharmHandler;
1416
import com.someguyssoftware.treasure2.eventhandler.WorldEventHandler;
1517
import com.someguyssoftware.treasure2.init.TreasureSetup;
1618
import com.someguyssoftware.treasure2.network.TreasureNetworking;
1719
import com.someguyssoftware.treasure2.particle.TreasureParticles;
1820

1921
import net.minecraftforge.common.MinecraftForge;
2022
import net.minecraftforge.eventbus.api.IEventBus;
23+
import net.minecraftforge.fml.InterModComms;
24+
import net.minecraftforge.fml.ModList;
2125
import net.minecraftforge.fml.ModLoadingContext;
2226
import net.minecraftforge.fml.common.Mod;
2327
import net.minecraftforge.fml.config.ModConfig;
2428
import net.minecraftforge.fml.config.ModConfig.ModConfigEvent;
2529
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
2630
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
2731
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
32+
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
2833
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
2934
import net.minecraftforge.fml.loading.FMLPaths;
35+
import top.theillusivec4.curios.api.SlotTypeMessage;
36+
import top.theillusivec4.curios.api.SlotTypePreset;
3037

3138
/**
3239
*
@@ -55,7 +62,7 @@ public class Treasure implements IMod {
5562
// constants
5663
public static final String MODID = "treasure2";
5764
protected static final String NAME = "Treasure2";
58-
protected static final String VERSION = "1.6.0";
65+
protected static final String VERSION = "1.6.1";
5966

6067
protected static final String UPDATE_JSON_URL = "https://raw.githubusercontent.com/gottsch/gottsch-minecraft-Treasure/1.16.5-master/update.json";
6168

@@ -83,12 +90,41 @@ public Treasure() {
8390
eventBus.addListener(TreasureCharms::setup);
8491
eventBus.addListener(TreasureSetup::clientSetup);
8592
eventBus.addListener(this::clientSetup);
93+
eventBus.addListener(this::interModComms);
8694

87-
// needs to be registered here instead of @Mod.EventBusSubscriber because we need to pass in a constructor argument
95+
// needs to be registered here instead of @Mod.EventBusSubscriber because an instance of the handler
96+
// is required and constructor arguments may need to be passed in
8897
MinecraftForge.EVENT_BUS.register(new WorldEventHandler(getInstance()));
89-
MinecraftForge.EVENT_BUS.register(new PlayerEventHandler()); // need to register here?
98+
99+
IEquipmentCharmHandler equipmentCharmHandler = null;
100+
if (ModList.get().isLoaded("curios")) {
101+
LOGGER.debug("curios IS loaded");
102+
try {
103+
equipmentCharmHandler =
104+
(IEquipmentCharmHandler) Class.forName("com.someguyssoftware.treasure2.eventhandler.CuriosEquipmentCharmHandler").newInstance();
105+
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
106+
LOGGER.warn("Unable to load Curios compatiblity class.");
107+
}
108+
}
109+
if (equipmentCharmHandler == null) {
110+
LOGGER.debug("equipmentHandler is null");
111+
equipmentCharmHandler = new HotbarEquipmentCharmHandler();
112+
}
113+
MinecraftForge.EVENT_BUS.register(new CharmEventHandler(equipmentCharmHandler));
90114
}
91115

116+
/**
117+
*
118+
* @param event
119+
*/
120+
private void interModComms(InterModEnqueueEvent event) {
121+
InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.CHARM.getMessageBuilder().build());
122+
InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.NECKLACE.getMessageBuilder().build());
123+
InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.RING.getMessageBuilder().build());
124+
InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.BRACELET.getMessageBuilder().build());
125+
InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.BELT.getMessageBuilder().build());
126+
}
127+
92128
public static void clientOnly() {
93129

94130
}

src/main/java/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java renamed to src/main/java/com/someguyssoftware/treasure2/eventhandler/CharmEventHandler.java

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,21 @@
6767
* @author Mark Gottschling on Apr 26, 2018
6868
*
6969
*/
70-
@Mod.EventBusSubscriber(modid = Treasure.MODID, bus = EventBusSubscriber.Bus.FORGE)
71-
public class PlayerEventHandler {
72-
private static final String CURIOS_ID = "curios";
73-
private static final List<String> CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm");
70+
//@Mod.EventBusSubscriber(modid = Treasure.MODID, bus = EventBusSubscriber.Bus.FORGE)
71+
public class CharmEventHandler {
72+
// private static final String CURIOS_ID = "curios";
73+
// private static final List<String> CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm");
7474

75+
private IEquipmentCharmHandler equipmentCharmHandler;
76+
77+
/**
78+
*
79+
* @param handler
80+
*/
81+
public CharmEventHandler(IEquipmentCharmHandler handler) {
82+
equipmentCharmHandler = handler;
83+
}
84+
7585
/*
7686
* Subscribing to multiple types of Living events for Charm Interactions so that instanceof doesn't have to be called everytime.
7787
*/
@@ -81,7 +91,7 @@ public class PlayerEventHandler {
8191
* @param event
8292
*/
8393
@SubscribeEvent
84-
public static void checkCharmsInteraction(LivingUpdateEvent event) {
94+
public void checkCharmsInteraction(LivingUpdateEvent event) {
8595
if (WorldInfo.isClientSide(event.getEntity().level)) {
8696
return;
8797
}
@@ -159,7 +169,7 @@ public void checkCharmsInteractionWithAttack(LivingHurtEvent event) {
159169
* @param event
160170
* @param player
161171
*/
162-
private static void processCharms(Event event, ServerPlayerEntity player) {
172+
private void processCharms(Event event, ServerPlayerEntity player) {
163173
/*
164174
* a list of charm contexts to execute
165175
*/
@@ -183,11 +193,11 @@ private static void processCharms(Event event, ServerPlayerEntity player) {
183193
* @param player
184194
* @return
185195
*/
186-
private static List<CharmContext> gatherCharms(Event event, ServerPlayerEntity player) {
196+
private List<CharmContext> gatherCharms(Event event, ServerPlayerEntity player) {
187197
final List<CharmContext> contexts = new ArrayList<>(5);
188198

189199
// get the slot provider - curios (general slots) or minecraft (hotbar)
190-
String slotProviderId = ModList.get().isLoaded(CURIOS_ID) ? CURIOS_ID : "minecaft";
200+
// String slotProviderId = ModList.get().isLoaded(CURIOS_ID) ? CURIOS_ID : "minecaft";
191201

192202
// check each hand
193203
for (Hand hand : Hand.values()) {
@@ -222,49 +232,10 @@ private static List<CharmContext> gatherCharms(Event event, ServerPlayerEntity p
222232
}
223233
}
224234

225-
// check slots
226-
if (slotProviderId.equals(CURIOS_ID)) {
227-
// check curio slots
228-
LazyOptional<ICuriosItemHandler> handler = CuriosApi.getCuriosHelper().getCuriosHandler(player);
229-
handler.ifPresent(itemHandler -> {
230-
// curios type names -> head, necklace, back, bracelet, hands, ring, belt, charm, feet
231-
CURIOS_SLOTS.forEach(slot -> {
232-
Optional<ICurioStacksHandler> stacksOptional = itemHandler.getStacksHandler(slot);
233-
stacksOptional.ifPresent(stacksHandler -> {
234-
ItemStack curiosStack = stacksHandler.getStacks().getStackInSlot(0);
235-
curiosStack.getCapability(TreasureCapabilities.CHARMABLE).ifPresent(cap -> {
236-
for (InventoryType type : InventoryType.values()) {
237-
AtomicInteger index = new AtomicInteger();
238-
// requires indexed for-loop
239-
for (int i = 0; i < cap.getCharmEntities()[type.getValue()].size(); i++) {
240-
ICharmEntity entity = cap.getCharmEntities()[type.getValue()].get(i);
241-
// if (!TreasureCharms.isCharmEventRegistered(event.getClass(), entity.getCharm().getType())) {
242-
if (!entity.getCharm().getRegisteredEvent().equals(event.getClass())) {
243-
// Treasure.LOGGER.debug("charm type -> {} is not register for this event -> {}", entity.getCharm().getType(), event.getClass().getSimpleName());
244-
continue;
245-
}
246-
index.set(i);
247-
CharmContext curiosContext = new CharmContext.Builder().with($ -> {
248-
$.slotProviderId = slotProviderId;
249-
$.slot = slot;
250-
$.itemStack = curiosStack;
251-
$.capability = cap;
252-
$.type = type;
253-
$.index = index.get();
254-
$.entity = entity;
255-
}).build();
256-
contexts.add(curiosContext);
257-
}
258-
}
259-
});
260-
});
261-
});
262-
});
263-
}
264-
else {
265-
// TODO check hotbar slots
266-
// TODO only allow IAdornments from hotbar
267-
}
235+
// check equipment slots
236+
List<CharmContext> equipmentContexts = getEquipmentCharmHandler().handleEquipmentCharms(event, player);
237+
contexts.addAll(equipmentContexts);
238+
268239
return contexts;
269240
}
270241

@@ -274,7 +245,7 @@ private static List<CharmContext> gatherCharms(Event event, ServerPlayerEntity p
274245
* @param player
275246
* @param contexts
276247
*/
277-
private static void executeCharms(Event event, ServerPlayerEntity player, List<CharmContext> contexts) {
248+
private void executeCharms(Event event, ServerPlayerEntity player, List<CharmContext> contexts) {
278249
/*
279250
* a list of charm types that are non-stackable that should not be executed more than once.
280251
*/
@@ -312,7 +283,16 @@ private static void executeCharms(Event event, ServerPlayerEntity player, List<C
312283
}
313284
});
314285
}
286+
287+
/**
288+
*
289+
* @return
290+
*/
291+
private IEquipmentCharmHandler getEquipmentCharmHandler() {
292+
return equipmentCharmHandler;
293+
}
315294

295+
// TODO move to a new event handler
316296
/**
317297
*
318298
* @param event
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* This file is part of Treasure2.
3+
* Copyright (c) 2021, Mark Gottschling (gottsch)
4+
*
5+
* All rights reserved.
6+
*
7+
* Treasure2 is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Treasure2 is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with Treasure2. If not, see <http://www.gnu.org/licenses/lgpl>.
19+
*/
20+
package com.someguyssoftware.treasure2.eventhandler;
21+
22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
import java.util.Optional;
26+
import java.util.concurrent.atomic.AtomicInteger;
27+
28+
import com.someguyssoftware.treasure2.capability.CharmableCapability.InventoryType;
29+
import com.someguyssoftware.treasure2.capability.TreasureCapabilities;
30+
import com.someguyssoftware.treasure2.charm.CharmContext;
31+
import com.someguyssoftware.treasure2.charm.ICharmEntity;
32+
33+
import net.minecraft.entity.player.ServerPlayerEntity;
34+
import net.minecraft.item.ItemStack;
35+
import net.minecraftforge.common.util.LazyOptional;
36+
import net.minecraftforge.eventbus.api.Event;
37+
import top.theillusivec4.curios.api.CuriosApi;
38+
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
39+
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
40+
41+
/**
42+
*
43+
* @author Mark Gottschling on Aug 30, 2021
44+
*
45+
*/
46+
public class CuriosEquipmentCharmHandler implements IEquipmentCharmHandler {
47+
private static final String CURIOS_ID = "curios";
48+
private static final List<String> CURIOS_SLOTS = Arrays.asList("necklace", "bracelet", "ring", "charm");
49+
50+
@Override
51+
public List<CharmContext> handleEquipmentCharms(Event event, ServerPlayerEntity player) {
52+
List<CharmContext> contexts = new ArrayList<>();
53+
54+
// check curio slots
55+
LazyOptional<ICuriosItemHandler> handler = CuriosApi.getCuriosHelper().getCuriosHandler(player);
56+
handler.ifPresent(itemHandler -> {
57+
// curios type names -> head, necklace, back, bracelet, hands, ring, belt, charm, feet
58+
CURIOS_SLOTS.forEach(slot -> {
59+
Optional<ICurioStacksHandler> stacksOptional = itemHandler.getStacksHandler(slot);
60+
stacksOptional.ifPresent(stacksHandler -> {
61+
ItemStack curiosStack = stacksHandler.getStacks().getStackInSlot(0);
62+
curiosStack.getCapability(TreasureCapabilities.CHARMABLE).ifPresent(cap -> {
63+
for (InventoryType type : InventoryType.values()) {
64+
AtomicInteger index = new AtomicInteger();
65+
// requires indexed for-loop
66+
for (int i = 0; i < cap.getCharmEntities()[type.getValue()].size(); i++) {
67+
ICharmEntity entity = cap.getCharmEntities()[type.getValue()].get(i);
68+
// if (!TreasureCharms.isCharmEventRegistered(event.getClass(), entity.getCharm().getType())) {
69+
if (!entity.getCharm().getRegisteredEvent().equals(event.getClass())) {
70+
// Treasure.LOGGER.debug("charm type -> {} is not register for this event -> {}", entity.getCharm().getType(), event.getClass().getSimpleName());
71+
continue;
72+
}
73+
index.set(i);
74+
CharmContext curiosContext = new CharmContext.Builder().with($ -> {
75+
$.slotProviderId = CURIOS_ID;
76+
$.slot = slot;
77+
$.itemStack = curiosStack;
78+
$.capability = cap;
79+
$.type = type;
80+
$.index = index.get();
81+
$.entity = entity;
82+
}).build();
83+
contexts.add(curiosContext);
84+
}
85+
}
86+
});
87+
});
88+
});
89+
});
90+
return contexts;
91+
}
92+
}

0 commit comments

Comments
 (0)