Version 1.22.0: to Forge 1.19.3-44.1.1

This commit is contained in:
Stephen Seo 2023-03-31 14:22:58 +09:00
parent c8add16c86
commit 275a613f0f
14 changed files with 99 additions and 71 deletions

View File

@ -1,5 +1,9 @@
# Upcoming changes
# Version 1.22.0
Update to Forge 1.19.3-44.1.1.
# Version 1.21.4
More refactoring of check-if-in-battle lookup code.

View File

@ -58,7 +58,7 @@ configured for them.)
# Building
Simply invoke `./gradlew build` in the mod directory and after some time the
finished jar will be saved at "build/libs/TurnBasedMinecraft-1.21.4.jar"
finished jar will be saved at "build/libs/TurnBasedMinecraft-1.22.0.jar"
# Other notes

View File

@ -14,7 +14,7 @@ apply plugin: 'net.minecraftforge.gradle'
//apply plugin: 'eclipse'
//apply plugin: 'maven-publish'
version = "1.21.4"
version = "1.22.0"
group = "com.burnedkirby.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft"
@ -27,7 +27,7 @@ minecraft {
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.19.2'
mappings channel: 'official', version: '1.19.3'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
@ -151,7 +151,7 @@ dependencies {
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.19.2-43.1.1'
minecraft 'net.minecraftforge:forge:1.19.3-44.1.1'
// Real mod deobf dependency examples - these get remapped to your current mappings
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency

View File

@ -7,6 +7,7 @@ import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleDecision;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
@ -127,18 +128,18 @@ public class BattleGui extends Screen {
switch (state) {
case MAIN_MENU:
info = "What will you do?";
addRenderableWidget(new Button(width * 3 / 7 - 25, 40, 50, 20, Component.literal("Attack"), (button) -> {
addRenderableWidget(Button.builder(Component.literal("Attack"), (button) -> {
buttonActionEvent(button, ButtonAction.ATTACK);
}));
addRenderableWidget(new Button(width * 4 / 7 - 25, 40, 50, 20, Component.literal("Defend"), (button) -> {
}).bounds(width * 3 / 7 - 25, 40, 50, 20).build());
addRenderableWidget(Button.builder(Component.literal("Defend"), (button) -> {
buttonActionEvent(button, ButtonAction.DEFEND);
}));
addRenderableWidget(new Button(width * 3 / 7 - 25, 60, 50, 20, Component.literal("Item"), (button) -> {
}).bounds(width * 4 / 7 - 25, 40, 50, 20).build());
addRenderableWidget(Button.builder(Component.literal("Item"), (button) -> {
buttonActionEvent(button, ButtonAction.ITEM);
}));
addRenderableWidget(new Button(width * 4 / 7 - 25, 60, 50, 20, Component.literal("Flee"), (button) -> {
}).bounds(width * 3 / 7 - 25, 60, 50, 20).build());
addRenderableWidget(Button.builder(Component.literal("Flee"), (button) -> {
buttonActionEvent(button, ButtonAction.FLEE);
}));
}).bounds(width * 4 / 7 - 25, 60, 50, 20).build());
break;
case ATTACK_TARGET:
info = "Who will you attack?";
@ -178,21 +179,21 @@ public class BattleGui extends Screen {
} catch (ConcurrentModificationException e) {
// ignored
}
addRenderableWidget(new Button(width / 2 - 30, height - 120, 60, 20, Component.literal("Cancel"), (button) -> {
addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
}).bounds(width / 2 - 30, height - 120, 60, 20).build());
break;
case ITEM_ACTION:
info = "What will you do with an item?";
addRenderableWidget(new Button(width * 1 / 4 - 40, height - 120, 80, 20, Component.literal("Switch Held"), (button) -> {
addRenderableWidget(Button.builder(Component.literal("Switch Held"), (button) -> {
buttonActionEvent(button, ButtonAction.SWITCH_HELD_ITEM);
}));
addRenderableWidget(new Button(width * 2 / 4 - 40, height - 120, 80, 20, Component.literal("Use"), (button) -> {
}).bounds(width / 4 - 40, height - 120, 80, 20).build());
addRenderableWidget(Button.builder(Component.literal("Use"), (button) -> {
buttonActionEvent(button, ButtonAction.DECIDE_USE_ITEM);
}));
addRenderableWidget(new Button(width * 3 / 4 - 40, height - 120, 80, 20, Component.literal("Cancel"), (button) -> {
}).bounds(width * 2 / 4 - 40, height - 120, 80, 20).build());
addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
}).bounds(width * 3 / 4 - 40, height - 120, 80, 20).build());
break;
case WAITING:
info = "Waiting...";
@ -204,9 +205,9 @@ public class BattleGui extends Screen {
buttonActionEvent(button, ButtonAction.DO_ITEM_SWITCH);
}));
}
addRenderableWidget(new Button(width / 2 - 40, height - 120, 80, 20, Component.literal("Cancel"), (button) -> {
addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
}).bounds(width / 2 - 40, height - 120, 80, 20).build());
break;
case USE_ITEM:
info = "Which item will you use?";
@ -215,9 +216,9 @@ public class BattleGui extends Screen {
buttonActionEvent(button, ButtonAction.DO_USE_ITEM);
}));
}
addRenderableWidget(new Button(width / 2 - 40, height - 120, 80, 20, Component.literal("Cancel"), (button) -> {
addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
}).bounds(width / 2 - 40, height - 120, 80, 20).build());
break;
}
}
@ -267,7 +268,7 @@ public class BattleGui extends Screen {
drawString(poseStack, info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF);
}
protected void buttonActionEvent(Button button, ButtonAction action) {
protected void buttonActionEvent(AbstractButton button, ButtonAction action) {
switch (action) {
case ATTACK:
setState(MenuState.ATTACK_TARGET);

View File

@ -1,24 +1,31 @@
package com.burnedkirby.TurnBasedMinecraft.client;
import com.burnedkirby.TurnBasedMinecraft.common.CommonProxy;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.narration.NarratedElementType;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
public class EntitySelectionButton extends Button {
public class EntitySelectionButton extends AbstractButton {
TBMButtonPress onPress;
private int entityID;
private boolean isSideA;
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA, Button.OnPress onPress) {
super(x, y, widthIn, heightIn, Component.literal(buttonText), onPress);
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA, TBMButtonPress onPress) {
super(x, y, widthIn, heightIn, Component.literal(buttonText));
this.onPress = onPress;
this.entityID = entityID;
this.isSideA = isSideA;
}
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, Component buttonTextComponent, int entityID, boolean isSideA, Button.OnPress onPress) {
super(x, y, widthIn, heightIn, buttonTextComponent, onPress);
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, Component buttonTextComponent, int entityID, boolean isSideA, TBMButtonPress onPress) {
super(x, y, widthIn, heightIn, buttonTextComponent);
this.onPress = onPress;
this.entityID = entityID;
this.isSideA = isSideA;
}
@ -83,11 +90,13 @@ public class EntitySelectionButton extends Button {
}
}
private int getX() {
return x;
@Override
protected void updateWidgetNarration(NarrationElementOutput p_259858_) {
p_259858_.add(NarratedElementType.HINT, TurnBasedMinecraftMod.proxy.getEntity(entityID, Minecraft.getInstance().level.dimension()).getName());
}
private int getY() {
return y;
@Override
public void onPress() {
onPress.onPress(this);
}
}

View File

@ -1,14 +1,19 @@
package com.burnedkirby.TurnBasedMinecraft.client;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.narration.NarratedElementType;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
public class ItemSelectionButton extends Button {
public class ItemSelectionButton extends AbstractButton {
TBMButtonPress onPress;
private int itemStackID;
public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, Button.OnPress onPress) {
super(x, y, widthIn, heightIn, Component.literal(buttonText), onPress);
public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, TBMButtonPress onPress) {
super(x, y, widthIn, heightIn, Component.literal(buttonText));
this.onPress = onPress;
this.itemStackID = itemStackID;
}
@ -28,11 +33,13 @@ public class ItemSelectionButton extends Button {
}
}
private int getX() {
return x;
@Override
protected void updateWidgetNarration(NarrationElementOutput p_259858_) {
p_259858_.add(NarratedElementType.HINT, "Item " + this.itemStackID);
}
private int getY() {
return y;
@Override
public void onPress() {
onPress.onPress(this);
}
}

View File

@ -0,0 +1,7 @@
package com.burnedkirby.TurnBasedMinecraft.client;
import net.minecraft.client.gui.components.AbstractButton;
public interface TBMButtonPress {
void onPress(AbstractButton button);
}

View File

@ -9,7 +9,7 @@ import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.network.PacketDistributor;
@ -146,23 +146,23 @@ public class AttackEventHandler
}
@SubscribeEvent
public void entityTargeted(LivingSetAttackTargetEvent event)
public void entityTargeted(LivingChangeTargetEvent event)
{
Config config = TurnBasedMinecraftMod.proxy.getConfig();
BattleManager battleManager = TurnBasedMinecraftMod.proxy.getBattleManager();
if(event.getEntity().level.isClientSide
|| config.isOldBattleBehaviorEnabled()
|| (event.getEntity() != null && battleManager.isRecentlyLeftBattle(event.getEntity().getId()))
|| (event.getTarget() != null && battleManager.isRecentlyLeftBattle(event.getTarget().getId()))
|| (event.getEntity() != null && event.getTarget() != null && Utility.distanceBetweenEntities(event.getEntity(), event.getTarget()) > (double)config.getAggroStartBattleDistance()))
|| (event.getNewTarget() != null && battleManager.isRecentlyLeftBattle(event.getNewTarget().getId()))
|| (event.getEntity() != null && event.getNewTarget() != null && Utility.distanceBetweenEntities(event.getEntity(), event.getNewTarget()) > (double)config.getAggroStartBattleDistance()))
{
return;
}
else if(event.getEntity() != null
&& event.getTarget() != null
&& event.getNewTarget() != null
&& !config.getBattleIgnoringPlayers().contains(event.getEntity().getId())
&& !config.getBattleIgnoringPlayers().contains(event.getTarget().getId())
&& event.getEntity().level.dimension().equals(event.getTarget().level.dimension()))
&& !config.getBattleIgnoringPlayers().contains(event.getNewTarget().getId())
&& event.getEntity().level.dimension().equals(event.getNewTarget().level.dimension()))
{
TurnBasedMinecraftMod.proxy.getBattleManager().checkTargeted(event);
}

View File

@ -1071,7 +1071,7 @@ public class Battle {
((Player) nextEntity).getInventory().setItem(nextItemToUse, targetItem.finishUsingItem(targetItemStack, nextEntity.level, (LivingEntity) nextEntity));
} else {
// then check vanilla foods
if (targetItem.getItemCategory() == CreativeModeTab.TAB_FOOD && targetItem.isEdible()) {
if (CreativeModeTabs.FOOD_AND_DRINKS.contains(targetItemStack) && 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;

View File

@ -9,7 +9,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
import net.minecraftforge.network.PacketDistributor;
import org.apache.logging.log4j.Logger;
@ -179,17 +179,17 @@ public class BattleManager
return true;
}
public void checkTargeted(LivingSetAttackTargetEvent event)
public void checkTargeted(LivingChangeTargetEvent event)
{
// Check if "player_only_battles" is enabled and if both entities are players.
if (TurnBasedMinecraftMod.proxy.getConfig().isPlayerOnlyBattlesEnabled() &&
(!(event.getEntity() instanceof Player) || !(event.getTarget() instanceof Player))) {
(!(event.getEntity() instanceof Player) || !(event.getNewTarget() instanceof Player))) {
return;
}
String targetedCustomName;
try {
targetedCustomName = event.getTarget().getCustomName().getString();
targetedCustomName = event.getNewTarget().getCustomName().getString();
} catch (NullPointerException e) {
targetedCustomName = null;
}
@ -207,7 +207,7 @@ public class BattleManager
}
EntityInfo targetedInfo;
if(event.getTarget() instanceof Player)
if(event.getNewTarget() instanceof Player)
{
targetedInfo = null;
}
@ -216,10 +216,10 @@ public class BattleManager
targetedInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(targetedCustomName);
if(targetedInfo == null)
{
targetedInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getTarget());
targetedInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(event.getNewTarget());
}
}
if((event.getTarget() instanceof Player && ((Player)event.getTarget()).isCreative())
if((event.getNewTarget() instanceof Player && ((Player)event.getNewTarget()).isCreative())
|| attackerInfo == null
|| attackerInfo.ignoreBattle
|| TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType(attackerInfo.category)
@ -235,8 +235,8 @@ public class BattleManager
if(attackerBattle != null && !attackerBattle.hasCombatant(event.getEntity().getId())) {
attackerBattle = null;
}
Battle defenderBattle = battleMap.get(entityToBattleMap.get(new EntityIDDimPair(event.getTarget())));
if(defenderBattle != null && !defenderBattle.hasCombatant(event.getTarget().getId())) {
Battle defenderBattle = battleMap.get(entityToBattleMap.get(new EntityIDDimPair(event.getNewTarget())));
if(defenderBattle != null && !defenderBattle.hasCombatant(event.getNewTarget().getId())) {
defenderBattle = null;
}
@ -244,13 +244,13 @@ public class BattleManager
return;
} else if(attackerBattle == null && defenderBattle == null) {
// neither in battle
if(event.getEntity() instanceof Player || event.getTarget() instanceof Player)
if(event.getEntity() instanceof Player || event.getNewTarget() instanceof Player)
{
// at least one is a player, create battle
Collection<Entity> sideA = new ArrayList<Entity>(1);
Collection<Entity> sideB = new ArrayList<Entity>(1);
sideA.add(event.getEntity());
sideB.add(event.getTarget());
sideB.add(event.getNewTarget());
createBattle(sideA, sideB, event.getEntity().level.dimension());
logger.debug("neither in battle, at least one is player, creating new battle");
}
@ -261,16 +261,16 @@ public class BattleManager
// battle max reached, cannot add to battle
return;
} else if (attackerBattle.hasCombatantInSideA(event.getEntity().getId())) {
attackerBattle.addCombatantToSideB(event.getTarget());
attackerBattle.addCombatantToSideB(event.getNewTarget());
} else {
attackerBattle.addCombatantToSideA(event.getTarget());
attackerBattle.addCombatantToSideA(event.getNewTarget());
}
entityToBattleMap.put(new EntityIDDimPair(event.getTarget()), attackerBattle.getId());
entityToBattleMap.put(new EntityIDDimPair(event.getNewTarget()), attackerBattle.getId());
} else {
if (defenderBattle.getSize() >= TurnBasedMinecraftMod.proxy.getConfig().getMaxInBattle()) {
// battle max reached, cannot add to battle
return;
} else if (defenderBattle.hasCombatantInSideA(event.getTarget().getId())) {
} else if (defenderBattle.hasCombatantInSideA(event.getNewTarget().getId())) {
defenderBattle.addCombatantToSideB(event.getEntity());
} else {
defenderBattle.addCombatantToSideA(event.getEntity());

View File

@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger;
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.21.4";
public static final String VERSION = "1.22.0";
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

@ -1,6 +1,6 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
@ -60,6 +60,6 @@ public class Utility
public static ResourceKey<Level> deserializeDimension(String dimString) {
ResourceLocation dimRes = new ResourceLocation(dimString);
return ResourceKey.create(Registry.DIMENSION_REGISTRY, dimRes);
return ResourceKey.create(Registries.DIMENSION, dimRes);
}
}

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.21.4" #mandatory
version="1.22.0" #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.21.4",
"version": "1.22.0",
"mcversion": "1.18.2",
"url": "",
"updateUrl": "",