Add experimental support for Pam's HC foods
This commit is contained in:
parent
b49624cfd4
commit
ee633284df
8 changed files with 135 additions and 19 deletions
|
@ -1,5 +1,9 @@
|
||||||
# Upcoming changes
|
# Upcoming changes
|
||||||
|
|
||||||
|
# Version 1.17.1
|
||||||
|
|
||||||
|
Add experimental support for Pam's Harvestcraft foods.
|
||||||
|
|
||||||
# Version 1.17
|
# Version 1.17
|
||||||
|
|
||||||
Update mod for Forge 1.16.5-36.1.0 .
|
Update mod for Forge 1.16.5-36.1.0 .
|
||||||
|
|
|
@ -14,7 +14,7 @@ apply plugin: 'eclipse'
|
||||||
//apply plugin: 'maven-publish'
|
//apply plugin: 'maven-publish'
|
||||||
apply plugin: 'com.github.johnrengelman.shadow'
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
|
|
||||||
version = "1.17"
|
version = "1.17.1"
|
||||||
group = "com.burnedkirby.TurnBasedMinecraft"
|
group = "com.burnedkirby.TurnBasedMinecraft"
|
||||||
archivesBaseName = "TurnBasedMinecraft"
|
archivesBaseName = "TurnBasedMinecraft"
|
||||||
|
|
||||||
|
|
|
@ -1316,26 +1316,39 @@ public class Battle
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_NOTHING.getValue());
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_NOTHING.getValue());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(targetItem.getItemCategory() == ItemGroup.TAB_FOOD)
|
// check if use item is a food
|
||||||
{
|
boolean isFood = false;
|
||||||
|
// first check other mod foods
|
||||||
|
for(ItemGroup itemGroup : BattleManager.getOtherFoodItemGroups()) {
|
||||||
|
if(targetItem.getItemCategory() == itemGroup && targetItem.isEdible()) {
|
||||||
|
isFood = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(isFood) {
|
||||||
debugLog += " food";
|
debugLog += " food";
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
|
||||||
final Entity nextEntity = next.entity;
|
final Entity nextEntity = next.entity;
|
||||||
final int nextItemToUse = next.itemToUse;
|
final int nextItemToUse = next.itemToUse;
|
||||||
((PlayerEntity)nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity)nextEntity));
|
((PlayerEntity)nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity)nextEntity));
|
||||||
}
|
} else {
|
||||||
else if(targetItem instanceof PotionItem)
|
// then check vanilla foods
|
||||||
{
|
if (targetItem.getItemCategory() == ItemGroup.TAB_FOOD && targetItem.isEdible()) {
|
||||||
debugLog += " potion";
|
debugLog += " food";
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_POTION.getValue(), targetItemStack.getDisplayName().getString());
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
|
||||||
final Entity nextEntity = next.entity;
|
final Entity nextEntity = next.entity;
|
||||||
final int nextItemToUse = next.itemToUse;
|
final int nextItemToUse = next.itemToUse;
|
||||||
((PlayerEntity)nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity)nextEntity));
|
((PlayerEntity) nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity) nextEntity));
|
||||||
}
|
} else if (targetItem instanceof PotionItem) {
|
||||||
else
|
debugLog += " potion";
|
||||||
{
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_POTION.getValue(), targetItemStack.getDisplayName().getString());
|
||||||
debugLog += " non-consumable";
|
final Entity nextEntity = next.entity;
|
||||||
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue(), targetItemStack.getDisplayName().getString());
|
final int nextItemToUse = next.itemToUse;
|
||||||
|
((PlayerEntity) nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity) nextEntity));
|
||||||
|
} else {
|
||||||
|
debugLog += " non-consumable";
|
||||||
|
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_INVALID.getValue(), targetItemStack.getDisplayName().getString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SWITCH_ITEM: {
|
case SWITCH_ITEM: {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||||
import net.minecraft.entity.monster.CreeperEntity;
|
import net.minecraft.entity.monster.CreeperEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.util.RegistryKey;
|
import net.minecraft.util.RegistryKey;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
@ -29,6 +30,7 @@ public class BattleManager
|
||||||
private Map<Integer, Combatant> recentlyLeftBattle;
|
private Map<Integer, Combatant> recentlyLeftBattle;
|
||||||
private BattleUpdater battleUpdater;
|
private BattleUpdater battleUpdater;
|
||||||
private Map<EntityIDDimPair, Integer> entityToBattleMap;
|
private Map<EntityIDDimPair, Integer> entityToBattleMap;
|
||||||
|
private static Collection<ItemGroup> otherFoodItemGroups = new ArrayList<>();
|
||||||
|
|
||||||
public BattleManager(Logger logger)
|
public BattleManager(Logger logger)
|
||||||
{
|
{
|
||||||
|
@ -356,4 +358,12 @@ public class BattleManager
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addOtherModItemGroup(ItemGroup itemGroup) {
|
||||||
|
otherFoodItemGroups.add(itemGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<ItemGroup> getOtherFoodItemGroups() {
|
||||||
|
return otherFoodItemGroups;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,16 @@
|
||||||
package com.burnedkirby.TurnBasedMinecraft.common;
|
package com.burnedkirby.TurnBasedMinecraft.common;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.util.RegistryKey;
|
import net.minecraft.util.RegistryKey;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.world.DimensionType;
|
import net.minecraft.world.DimensionType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.ModContainer;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -71,11 +75,96 @@ public class CommonProxy
|
||||||
{
|
{
|
||||||
config = new Config(logger);
|
config = new Config(logger);
|
||||||
postInitClient();
|
postInitClient();
|
||||||
|
pamsFoodIntegrationLoading();
|
||||||
logger.debug("postInit proxy for com_burnedkirby_turnbasedminecraft");
|
logger.debug("postInit proxy for com_burnedkirby_turnbasedminecraft");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void postInitClient() {}
|
protected void postInitClient() {}
|
||||||
|
|
||||||
|
private final void pamsFoodIntegrationLoading() {
|
||||||
|
// TODO: generalize other mod's food loading via config with a list of mod ids
|
||||||
|
|
||||||
|
// pamhc2foodcore
|
||||||
|
{
|
||||||
|
ModList modList = ModList.get();
|
||||||
|
Optional<? extends ModContainer> pamsFoodCoreContainer = modList.getModContainerById("pamhc2foodcore");
|
||||||
|
if (pamsFoodCoreContainer.isPresent()) {
|
||||||
|
Object pamsFoodCore = pamsFoodCoreContainer.get().getMod();
|
||||||
|
try {
|
||||||
|
Field itemGroupField = pamsFoodCore.getClass().getField("ITEM_GROUP");
|
||||||
|
ItemGroup foodItemGroup = (ItemGroup) itemGroupField.get(null);
|
||||||
|
if(foodItemGroup != null) {
|
||||||
|
BattleManager.addOtherModItemGroup(foodItemGroup);
|
||||||
|
} else {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TurnBasedMinecraftMod.logger.info("Failed to get pamhc2foodcore ITEM_GROUP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pamhc2crops
|
||||||
|
{
|
||||||
|
ModList modList = ModList.get();
|
||||||
|
Optional<? extends ModContainer> pamsFoodCoreContainer = modList.getModContainerById("pamhc2crops");
|
||||||
|
if (pamsFoodCoreContainer.isPresent()) {
|
||||||
|
Object pamsFoodCore = pamsFoodCoreContainer.get().getMod();
|
||||||
|
try {
|
||||||
|
Field itemGroupField = pamsFoodCore.getClass().getField("ITEM_GROUP");
|
||||||
|
ItemGroup foodItemGroup = (ItemGroup) itemGroupField.get(null);
|
||||||
|
if(foodItemGroup != null) {
|
||||||
|
BattleManager.addOtherModItemGroup(foodItemGroup);
|
||||||
|
} else {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TurnBasedMinecraftMod.logger.info("Failed to get pamhc2crops ITEM_GROUP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pamhc2trees
|
||||||
|
{
|
||||||
|
ModList modList = ModList.get();
|
||||||
|
Optional<? extends ModContainer> pamsFoodCoreContainer = modList.getModContainerById("pamhc2trees");
|
||||||
|
if (pamsFoodCoreContainer.isPresent()) {
|
||||||
|
Object pamsFoodCore = pamsFoodCoreContainer.get().getMod();
|
||||||
|
try {
|
||||||
|
Field itemGroupField = pamsFoodCore.getClass().getField("ITEM_GROUP");
|
||||||
|
ItemGroup foodItemGroup = (ItemGroup) itemGroupField.get(null);
|
||||||
|
if(foodItemGroup != null) {
|
||||||
|
BattleManager.addOtherModItemGroup(foodItemGroup);
|
||||||
|
} else {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TurnBasedMinecraftMod.logger.info("Failed to get pamhc2trees ITEM_GROUP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pamhc2foodextended
|
||||||
|
{
|
||||||
|
ModList modList = ModList.get();
|
||||||
|
Optional<? extends ModContainer> pamsFoodCoreContainer = modList.getModContainerById("pamhc2foodextended");
|
||||||
|
if (pamsFoodCoreContainer.isPresent()) {
|
||||||
|
Object pamsFoodCore = pamsFoodCoreContainer.get().getMod();
|
||||||
|
try {
|
||||||
|
Field itemGroupField = pamsFoodCore.getClass().getField("ITEM_GROUP");
|
||||||
|
ItemGroup foodItemGroup = (ItemGroup) itemGroupField.get(null);
|
||||||
|
if(foodItemGroup != null) {
|
||||||
|
BattleManager.addOtherModItemGroup(foodItemGroup);
|
||||||
|
} else {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
TurnBasedMinecraftMod.logger.info("Failed to get pamhc2foodextended ITEM_GROUP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final void setLogger(Logger logger)
|
public final void setLogger(Logger logger)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class TurnBasedMinecraftMod
|
||||||
{
|
{
|
||||||
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
|
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
|
||||||
public static final String NAME = "Turn Based Minecraft Mod";
|
public static final String NAME = "Turn Based Minecraft Mod";
|
||||||
public static final String VERSION = "1.17";
|
public static final String VERSION = "1.17.1";
|
||||||
public static final String CONFIG_FILENAME = "TBM_Config.toml";
|
public static final String CONFIG_FILENAME = "TBM_Config.toml";
|
||||||
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
|
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
|
||||||
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
|
||||||
|
|
|
@ -15,7 +15,7 @@ license="MIT"
|
||||||
# The modid of the mod
|
# The modid of the mod
|
||||||
modId="com_burnedkirby_turnbasedminecraft" #mandatory
|
modId="com_burnedkirby_turnbasedminecraft" #mandatory
|
||||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||||
version="1.17" #mandatory
|
version="1.17.1" #mandatory
|
||||||
# A display name for the mod
|
# A display name for the mod
|
||||||
displayName="TurnBasedMinecraftMod" #mandatory
|
displayName="TurnBasedMinecraftMod" #mandatory
|
||||||
# A URL to query for updates for this mod. See the JSON update specification <here>
|
# A URL to query for updates for this mod. See the JSON update specification <here>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"modid": "com_burnedkirby_turnbasedminecraft",
|
"modid": "com_burnedkirby_turnbasedminecraft",
|
||||||
"name": "Turn Based Minecraft",
|
"name": "Turn Based Minecraft",
|
||||||
"description": "Changes battles to be turn-based.",
|
"description": "Changes battles to be turn-based.",
|
||||||
"version": "1.17",
|
"version": "1.17.1",
|
||||||
"mcversion": "1.16.3",
|
"mcversion": "1.16.3",
|
||||||
"url": "",
|
"url": "",
|
||||||
"updateUrl": "",
|
"updateUrl": "",
|
||||||
|
|
Loading…
Reference in a new issue