Add experimental support for Pam's HC foods

This commit is contained in:
Stephen Seo 2021-05-23 13:22:18 +09:00
parent b49624cfd4
commit ee633284df
8 changed files with 135 additions and 19 deletions

View file

@ -1,5 +1,9 @@
# Upcoming changes
# Version 1.17.1
Add experimental support for Pam's Harvestcraft foods.
# Version 1.17
Update mod for Forge 1.16.5-36.1.0 .

View file

@ -14,7 +14,7 @@ apply plugin: 'eclipse'
//apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
version = "1.17"
version = "1.17.1"
group = "com.burnedkirby.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft"

View file

@ -1316,27 +1316,40 @@ public class Battle
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_NOTHING.getValue());
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";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
final Entity nextEntity = next.entity;
final int nextItemToUse = next.itemToUse;
((PlayerEntity)nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity)nextEntity));
}
else if(targetItem instanceof PotionItem)
{
} else {
// then check vanilla foods
if (targetItem.getItemCategory() == ItemGroup.TAB_FOOD && targetItem.isEdible()) {
debugLog += " food";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_FOOD.getValue(), targetItemStack.getDisplayName().getString());
final Entity nextEntity = next.entity;
final int nextItemToUse = next.itemToUse;
((PlayerEntity) nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity) nextEntity));
} else if (targetItem instanceof PotionItem) {
debugLog += " potion";
sendMessageToAllPlayers(PacketBattleMessage.MessageType.USED_ITEM, next.entity.getId(), 0, PacketBattleMessage.UsedItemAction.USED_POTION.getValue(), targetItemStack.getDisplayName().getString());
final Entity nextEntity = next.entity;
final int nextItemToUse = next.itemToUse;
((PlayerEntity)nextEntity).inventory.setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity)nextEntity));
}
else
{
((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;
case SWITCH_ITEM: {
debugLog += " switch item";

View file

@ -9,6 +9,7 @@ import java.util.Map;
import net.minecraft.entity.monster.CreeperEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
@ -29,6 +30,7 @@ public class BattleManager
private Map<Integer, Combatant> recentlyLeftBattle;
private BattleUpdater battleUpdater;
private Map<EntityIDDimPair, Integer> entityToBattleMap;
private static Collection<ItemGroup> otherFoodItemGroups = new ArrayList<>();
public BattleManager(Logger logger)
{
@ -356,4 +358,12 @@ public class BattleManager
}
return result;
}
public static void addOtherModItemGroup(ItemGroup itemGroup) {
otherFoodItemGroups.add(itemGroup);
}
public static Collection<ItemGroup> getOtherFoodItemGroups() {
return otherFoodItemGroups;
}
}

View file

@ -1,12 +1,16 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import java.lang.reflect.Field;
import java.util.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger;
@ -71,11 +75,96 @@ public class CommonProxy
{
config = new Config(logger);
postInitClient();
pamsFoodIntegrationLoading();
logger.debug("postInit proxy for com_burnedkirby_turnbasedminecraft");
}
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)
{
this.logger = logger;

View file

@ -35,7 +35,7 @@ public class TurnBasedMinecraftMod
{
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
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 DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";

View file

@ -15,7 +15,7 @@ license="MIT"
# The modid of the mod
modId="com_burnedkirby_turnbasedminecraft" #mandatory
# 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
displayName="TurnBasedMinecraftMod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>

View file

@ -3,7 +3,7 @@
"modid": "com_burnedkirby_turnbasedminecraft",
"name": "Turn Based Minecraft",
"description": "Changes battles to be turn-based.",
"version": "1.17",
"version": "1.17.1",
"mcversion": "1.16.3",
"url": "",
"updateUrl": "",