Compare commits

..

No commits in common. "b20f8314d0d90c2ee4e2e4075da5399055e17747" and "84006554e8b0cc433051e4056f40b16900a935d0" have entirely different histories.

12 changed files with 243 additions and 274 deletions

View file

@ -1,12 +1,7 @@
# Upcoming changes # Upcoming changes
# Version Forge-1.25.1
Add icon for mod in Mod list description. Add icon for mod in Mod list description.
Update for Forge 49.0.19.
Works on Forge Minecraft 1.20.4.
# Version NeoForge-1.25.1 # Version NeoForge-1.25.1
Add icon for mod in Mod list description. Add icon for mod in Mod list description.

View file

@ -71,7 +71,7 @@ configured for them.)
Simply invoke `./gradlew build` in the mod directory and after some time the Simply invoke `./gradlew build` in the mod directory and after some time the
finished jar will be saved at finished jar will be saved at
`build/libs/TurnBasedMinecraft-Forge-1.25.1-all.jar` `build/libs/TurnBasedMinecraft-Forge-1.25.0-all.jar`
# Reproducibility # Reproducibility

View file

@ -4,19 +4,6 @@ Starting with version 1.24.0 of this mod, this file will list what version of
Java was used to compile the jars. In theory, using the same version of Java Java was used to compile the jars. In theory, using the same version of Java
should result in an identical jar due to reproducible builds. should result in an identical jar due to reproducible builds.
## Forge 1.25.1
$ java --version
openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+8)
OpenJDK 64-Bit Server VM (build 17.0.9+8, mixed mode)
$ javac --version
javac 17.0.9
$ sha256sum build/libs/TurnBasedMinecraft-Forge-1.25.1-all.jar
33711947eed8b24fa7fd65d36ecdb6ed78e144af8d7fff6e1bfa304cfe4a1d3d build/libs/TurnBasedMinecraft-Forge-1.25.1-all.jar
## NeoForge 1.25.1 ## NeoForge 1.25.1
$ java --version $ java --version

View file

@ -5,8 +5,8 @@ plugins {
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)' id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
} }
version = mod_version version = "1.25.0"
group = mod_group_id group = "com.burnedkirby.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft-Forge" archivesBaseName = "TurnBasedMinecraft-Forge"
java.toolchain.languageVersion = JavaLanguageVersion.of(17) java.toolchain.languageVersion = JavaLanguageVersion.of(17)
@ -33,8 +33,48 @@ minecraft {
// Default run configurations. // Default run configurations.
// These can be tweaked, removed, or duplicated as needed. // These can be tweaked, removed, or duplicated as needed.
runs { runs {
// applies to all the run configs below client {
configureEach { workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
mods {
TurnBasedMinecraftMod {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
mods {
TurnBasedMinecraftMod {
source sourceSets.main
}
}
}
// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
workingDirectory project.file('run') workingDirectory project.file('run')
// Recommended logging data for a userdev environment // Recommended logging data for a userdev environment
@ -48,31 +88,33 @@ minecraft {
// You can set various levels here. // You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug' property 'forge.logging.console.level', 'debug'
}
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces. // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
}
server { mods {
property 'forge.enabledGameTestNamespaces', mod_id TurnBasedMinecraftMod {
args '--nogui' source sourceSets.main
} }
}
// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
property 'forge.enabledGameTestNamespaces', mod_id
} }
data { data {
// example of overriding the workingDirectory set in configureEach above workingDirectory project.file('run')
workingDirectory project.file('run-data')
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. // Recommended logging data for a userdev environment
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
args '--mod', 'TurnBasedMinecraftMod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources')
mods {
TurnBasedMinecraftMod {
source sourceSets.main
}
}
} }
} }
} }
@ -80,6 +122,22 @@ minecraft {
// Include resources generated by data generators. // Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' } sourceSets.main.resources { srcDir 'src/generated/resources' }
//repositories {
// // Put repositories for dependencies here
// // ForgeGradle automatically adds the Forge maven and Maven Central for you
//
// // If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
// // flatDir {
// // dir 'libs'
// // }
// mavenCentral()
// jcenter()
//
// dependencies {
// classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
// }
//}
repositories { repositories {
flatDir { flatDir {
dir 'libs' dir 'libs'
@ -87,13 +145,23 @@ repositories {
} }
dependencies { dependencies {
// Specify the version of Minecraft to use. // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact. // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The "userdev" classifier will be requested and setup by ForgeGradle. // The userdev artifact is a special name and will get all sorts of transformations applied to it.
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// 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
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
// implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency
// Examples using mod jars from ./libs
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
//implementation files('libs/javamp3-1.0.3.jar')
implementation 'fr.delthas:javamp3:1.0.3' implementation 'fr.delthas:javamp3:1.0.3'
implementation 'com.github.stephengold:j-ogg-vorbis:1.0.4' implementation 'com.github.stephengold:j-ogg-vorbis:1.0.4'
@ -126,21 +194,22 @@ tasks.named('processResources', ProcessResources).configure {
} }
} }
// Example for how to get properties into the manifest for reading at runtime. // Example for how to get properties into the manifest for reading by the runtime..
tasks.named('jar', Jar).configure { jar {
archiveClassifier = 'slim'
manifest { manifest {
attributes([ attributes([
'Specification-Title' : mod_id, "Specification-Title": "TurnBasedMinecraftMod",
'Specification-Vendor' : mod_authors, "Specification-Vendor": "TurnBasedMinecraftMod_BK",
'Specification-Version' : '1', // We are version 1 of ourselves "Specification-Version": "1", // We are version 1 of ourselves
'Implementation-Title' : "TurnBasedMinecraftMod", "Implementation-Title": "TurnBasedMinecraftMod",
'Implementation-Version' : project.jar.archiveVersion, "Implementation-Version": "${version}",
'Implementation-Vendor' : mod_authors "Implementation-Vendor" :"TurnBasedMinecraftMod_BK",
// Do not place timestamp for the sake of reproducible builds
// "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
// "ContainedDeps": "javamp3-1.0.3.jar"
]) ])
} }
// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
} }
// Reproducible Builds // Reproducible Builds
@ -149,16 +218,24 @@ tasks.withType(AbstractArchiveTask).configureEach {
reproducibleFileOrder = true reproducibleFileOrder = true
} }
tasks.withType(JavaCompile).configureEach { // Example configuration to allow publishing using the maven-publish task
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation // we define a custom artifact that is sourced from the reobfJar output task
} // and then declare that to be published
// Note you'll need to add a repository here
// Merge the resources and classes into the same directory. //def reobfFile = file("$buildDir/reobfJar/output.jar")
// This is done because java expects modules to be in a single directory. //def reobfArtifact = artifacts.add('default', reobfFile) {
// And if we have it in multiple we have to do performance intensive hacks like having the UnionFileSystem // type 'jar'
// This will eventually be migrated to ForgeGradle so modders don't need to manually do it. But that is later. // builtBy 'reobfJar'
sourceSets.each { //}
def dir = layout.buildDirectory.dir("sourcesSets/$it.name") //publishing {
it.output.resourcesDir = dir // publications {
it.java.destinationDirectory = dir // mavenJava(MavenPublication) {
} // artifact reobfArtifact
// }
// }
// repositories {
// maven {
// url "file:///${project.projectDir}/mcmodsrepo"
// }
// }
//}

View file

@ -4,17 +4,17 @@ org.gradle.daemon=false
## Environment Properties ## Environment Properties
# The Minecraft version must agree with the Forge version to get a valid artifact # The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.4 minecraft_version=1.20.2
# The Minecraft version range can use any release version of Minecraft as bounds. # The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions. # as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.4,1.21) minecraft_version_range=[1.20.2,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact # The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=49.0.19 forge_version=48.1.0
# The Forge version range can use any version of Forge as bounds or match the loader version range # The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[0,) forge_version_range=[48,)
# The loader version range can only use the major version of Forge/FML as bounds # The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[0,) loader_version_range=[48,)
# The mapping channel to use for mappings. # The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. # The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin. # Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
@ -32,7 +32,7 @@ loader_version_range=[0,)
mapping_channel=official mapping_channel=official
# The mapping version to query from the mapping channel. # The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel. # This must match the format required by the mapping channel.
mapping_version=1.20.4 mapping_version=1.20.2
## Mod Properties ## Mod Properties
@ -44,11 +44,11 @@ mod_name=TurnBasedMinecraftMod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT mod_license=MIT
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=1.25.1 mod_version=1.25.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=com.burnedkirby.TurnBasedMinecraft #mod_group_id=com.example.examplemod
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list. # The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=BurnedKirby a.k.a. Stephen Seo mod_authors=BurnedKirby a.k.a. Stephen Seo
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.

View file

@ -150,11 +150,11 @@ public class BattleGui extends Screen {
.getSideAEntrySet()) { .getSideAEntrySet()) {
if (e.getValue().entity != null) { if (e.getValue().entity != null) {
addRenderableWidget(new EntitySelectionButton(width / 4 - 60, y, 120, 20, e.getValue().entity.getDisplayName(), e.getKey(), true, (button) -> { addRenderableWidget(new EntitySelectionButton(width / 4 - 60, y, 120, 20, e.getValue().entity.getDisplayName(), e.getKey(), true, (button) -> {
entityButtonActionEvent(button, ButtonAction.ATTACK_TARGET); buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
})); }));
} else { } else {
addRenderableWidget(new EntitySelectionButton(width / 4 - 60, y, 120, 20, "Unknown", e.getKey(), true, (button) -> { addRenderableWidget(new EntitySelectionButton(width / 4 - 60, y, 120, 20, "Unknown", e.getKey(), true, (button) -> {
entityButtonActionEvent(button, ButtonAction.ATTACK_TARGET); buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
})); }));
} }
y += 20; y += 20;
@ -168,11 +168,11 @@ public class BattleGui extends Screen {
.getSideBEntrySet()) { .getSideBEntrySet()) {
if (e.getValue().entity != null) { if (e.getValue().entity != null) {
addRenderableWidget(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, e.getValue().entity.getDisplayName(), e.getKey(), false, (button) -> { addRenderableWidget(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, e.getValue().entity.getDisplayName(), e.getKey(), false, (button) -> {
entityButtonActionEvent(button, ButtonAction.ATTACK_TARGET); buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
})); }));
} else { } else {
addRenderableWidget(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, "Unknown", e.getKey(), false, (button) -> { addRenderableWidget(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, "Unknown", e.getKey(), false, (button) -> {
entityButtonActionEvent(button, ButtonAction.ATTACK_TARGET); buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
})); }));
} }
y += 20; y += 20;
@ -202,8 +202,8 @@ public class BattleGui extends Screen {
case SWITCH_ITEM: case SWITCH_ITEM:
info = "To which item will you switch to?"; info = "To which item will you switch to?";
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
addRenderableWidget(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, i, (button) -> { addRenderableWidget(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, "", i, (button) -> {
itemButtonActionEvent(button, ButtonAction.DO_ITEM_SWITCH); buttonActionEvent(button, ButtonAction.DO_ITEM_SWITCH);
})); }));
} }
addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> { addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> {
@ -213,8 +213,8 @@ public class BattleGui extends Screen {
case USE_ITEM: case USE_ITEM:
info = "Which item will you use?"; info = "Which item will you use?";
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
addRenderableWidget(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, i, (button) -> { addRenderableWidget(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, "", i, (button) -> {
itemButtonActionEvent(button, ButtonAction.DO_USE_ITEM); buttonActionEvent(button, ButtonAction.DO_USE_ITEM);
})); }));
} }
addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> { addRenderableWidget(Button.builder(Component.literal("Cancel"), (button) -> {
@ -269,6 +269,10 @@ public class BattleGui extends Screen {
drawString(guiGraphics, info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF); drawString(guiGraphics, info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF);
} }
@Override
public void renderBackground(GuiGraphics p_283688_, int p_299421_, int p_298679_, float p_297268_) {
}
protected void buttonActionEvent(AbstractButton button, ButtonAction action) { protected void buttonActionEvent(AbstractButton button, ButtonAction action) {
switch (action) { switch (action) {
case ATTACK: case ATTACK:
@ -290,8 +294,14 @@ public class BattleGui extends Screen {
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ATTACK_TARGET: case ATTACK_TARGET:
// Invalid but set to main menu anyways. if (button instanceof EntitySelectionButton) {
setState(MenuState.MAIN_MENU); TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID()),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING);
} else {
setState(MenuState.MAIN_MENU);
}
break; break;
case SWITCH_HELD_ITEM: case SWITCH_HELD_ITEM:
setState(MenuState.SWITCH_ITEM); setState(MenuState.SWITCH_ITEM);
@ -303,47 +313,28 @@ public class BattleGui extends Screen {
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
break; break;
case DO_ITEM_SWITCH: case DO_ITEM_SWITCH:
// Invalid but set to main menu anyways. if (button instanceof ItemSelectionButton) {
setState(MenuState.MAIN_MENU); TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
break; TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton) button).getID()),
case DO_USE_ITEM:
// Invalid, but set menu to main menu anyways.
setState(MenuState.MAIN_MENU);
break;
}
}
protected void entityButtonActionEvent(EntitySelectionButton button, ButtonAction action) {
if (action.equals(ButtonAction.ATTACK_TARGET)) {
TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, button.getID()),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING);
} else {
setState(MenuState.MAIN_MENU);
}
}
protected void itemButtonActionEvent(ItemSelectionButton button, ButtonAction action) {
switch (action) {
case DO_ITEM_SWITCH:
TurnBasedMinecraftMod.getHandler().send(
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, button.getID()),
PacketDistributor.SERVER.noArg()); PacketDistributor.SERVER.noArg());
if (button.getID() >= 0 && button.getID() < 9) { if (((ItemSelectionButton) button).getID() >= 0 && ((ItemSelectionButton) button).getID() < 9) {
Minecraft.getInstance().player.getInventory().selected = button.getID(); Minecraft.getInstance().player.getInventory().selected = ((ItemSelectionButton) button).getID();
} }
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; } else {
case DO_USE_ITEM: setState(MenuState.MAIN_MENU);
TurnBasedMinecraftMod.getHandler().send( }
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, button.getID()), break;
case DO_USE_ITEM:
if (button instanceof ItemSelectionButton) {
TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton) button).getID()),
PacketDistributor.SERVER.noArg()); PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; } else {
default:
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
break; }
break;
} }
} }
@ -360,11 +351,6 @@ public class BattleGui extends Screen {
return false; // TODO verify return value return false; // TODO verify return value
} }
@Override
public void renderBackground(GuiGraphics p_283688_, int p_299421_, int p_298679_, float p_297268_) {
// Left blank to not render background.
}
@Override @Override
public boolean keyReleased(int a, int b, int c) { public boolean keyReleased(int a, int b, int c) {
if (getMinecraft().player.isCreative()) { if (getMinecraft().player.isCreative()) {

View file

@ -1,49 +1,34 @@
package com.burnedkirby.TurnBasedMinecraft.client; package com.burnedkirby.TurnBasedMinecraft.client;
import com.burnedkirby.TurnBasedMinecraft.common.CommonProxy;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarratedElementType;
import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
public class EntitySelectionButton implements Renderable, GuiEventListener, NarratableEntry { public class EntitySelectionButton extends AbstractButton {
private int x; TBMButtonPress onPress;
private int y;
private int width;
private int height;
private boolean focused;
private Button nestedButton;
TBMEntityButtonPress onPress;
private int entityID; private int entityID;
private boolean isSideA; private boolean isSideA;
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA, TBMEntityButtonPress onPress) { public EntitySelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA, TBMButtonPress onPress) {
this.x = x; super(x, y, widthIn, heightIn, Component.literal(buttonText));
this.y = y;
this.width = widthIn;
this.height = heightIn;
this.onPress = onPress; this.onPress = onPress;
this.entityID = entityID; this.entityID = entityID;
this.isSideA = isSideA; this.isSideA = isSideA;
this.nestedButton = Button.builder(Component.literal(buttonText), (unused) -> {}).pos(x, y).size(widthIn, heightIn).build();
} }
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, Component buttonTextComponent, int entityID, boolean isSideA, TBMEntityButtonPress onPress) { public EntitySelectionButton(int x, int y, int widthIn, int heightIn, Component buttonTextComponent, int entityID, boolean isSideA, TBMButtonPress onPress) {
this.x = x; super(x, y, widthIn, heightIn, buttonTextComponent);
this.y = y;
this.width = widthIn;
this.height = heightIn;
this.onPress = onPress; this.onPress = onPress;
this.entityID = entityID; this.entityID = entityID;
this.isSideA = isSideA; this.isSideA = isSideA;
this.nestedButton = Button.builder(buttonTextComponent, (unused) -> {}).pos(x, y).size(widthIn, heightIn).build();
} }
public int getID() { public int getID() {
@ -56,86 +41,63 @@ public class EntitySelectionButton implements Renderable, GuiEventListener, Narr
@Override @Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
this.nestedButton.render(guiGraphics, mouseX, mouseY, partialTicks); super.render(guiGraphics, mouseX, mouseY, partialTicks);
Entity e = Minecraft.getInstance().level.getEntity(entityID); Entity e = Minecraft.getInstance().level.getEntity(entityID);
if (e != null && e instanceof LivingEntity && ((LivingEntity) e).isAlive()) { if (e != null && e instanceof LivingEntity && ((LivingEntity) e).isAlive()) {
int health = (int) (((LivingEntity) e).getHealth() + 0.5f); int health = (int) (((LivingEntity) e).getHealth() + 0.5f);
int xpos = this.x; int xpos = getX();
int xoffset; int xoffset;
if (isSideA) { if (isSideA) {
xpos += this.width + 4; xpos += getWidth() + 4;
xoffset = 4; xoffset = 4;
} else { } else {
xpos -= 6; xpos -= 6;
xoffset = -4; xoffset = -4;
} }
if (health > 200) { if (health > 200) {
guiGraphics.fill(xpos, this.y + this.height * 4 / 5, xpos + 2, this.y + this.height, 0xFFFF0000); guiGraphics.fill(xpos, getY() + getHeight() * 4 / 5, xpos + 2, getY() + getHeight(), 0xFFFF0000);
guiGraphics.fill(xpos, this.y + this.height * 3 / 5, xpos + 2, this.y + this.height * 4 / 5, 0xFFFFFF00); guiGraphics.fill(xpos, getY() + getHeight() * 3 / 5, xpos + 2, getY() + getHeight() * 4 / 5, 0xFFFFFF00);
guiGraphics.fill(xpos, this.y + this.height * 2 / 5, xpos + 2, this.y + this.height * 3 / 5, 0xFF00FF00); guiGraphics.fill(xpos, getY() + getHeight() * 2 / 5, xpos + 2, getY() + getHeight() * 3 / 5, 0xFF00FF00);
guiGraphics.fill(xpos, this.y + this.height / 5, xpos + 2, this.y + this.height * 2 / 5, 0xFF00FFFF); guiGraphics.fill(xpos, getY() + getHeight() / 5, xpos + 2, getY() + getHeight() * 2 / 5, 0xFF00FFFF);
guiGraphics.fill(xpos, this.y, xpos + 2, this.y + this.height / 5, 0xFF0000FF); guiGraphics.fill(xpos, getY(), xpos + 2, getY() + getHeight() / 5, 0xFF0000FF);
int healthHeight = ((health - 200) * this.height / 100); int healthHeight = ((health - 200) * getHeight() / 100);
guiGraphics.fill(xpos + xoffset, this.y + this.height - healthHeight, xpos + xoffset + 2, this.y + this.height, 0xFFFFFFFF); guiGraphics.fill(xpos + xoffset, getY() + getHeight() - healthHeight, xpos + xoffset + 2, getY() + getHeight(), 0xFFFFFFFF);
} else if (health > 100) { } else if (health > 100) {
guiGraphics.fill(xpos, this.y + this.height * 4 / 5, xpos + 2, this.y + this.height, 0xFFFF0000); guiGraphics.fill(xpos, getY() + getHeight() * 4 / 5, xpos + 2, getY() + getHeight(), 0xFFFF0000);
guiGraphics.fill(xpos, this.y + this.height * 3 / 5, xpos + 2, this.y + this.height * 4 / 5, 0xFFFFFF00); guiGraphics.fill(xpos, getY() + getHeight() * 3 / 5, xpos + 2, getY() + getHeight() * 4 / 5, 0xFFFFFF00);
guiGraphics.fill(xpos, this.y + this.height * 2 / 5, xpos + 2, this.y + this.height * 3 / 5, 0xFF00FF00); guiGraphics.fill(xpos, getY() + getHeight() * 2 / 5, xpos + 2, getY() + getHeight() * 3 / 5, 0xFF00FF00);
guiGraphics.fill(xpos, this.y + this.height / 5, xpos + 2, this.y + this.height * 2 / 5, 0xFF00FFFF); guiGraphics.fill(xpos, getY() + getHeight() / 5, xpos + 2, getY() + getHeight() * 2 / 5, 0xFF00FFFF);
int healthHeight = ((health - 100) * this.height / 100); int healthHeight = ((health - 100) * getHeight() / 100);
guiGraphics.fill(xpos + xoffset, this.y + this.height - healthHeight, xpos + xoffset + 2, this.y + this.height, 0xFF0000FF); guiGraphics.fill(xpos + xoffset, getY() + getHeight() - healthHeight, xpos + xoffset + 2, getY() + getHeight(), 0xFF0000FF);
} else if (health > 50) { } else if (health > 50) {
guiGraphics.fill(xpos, this.y + this.height * 4 / 5, xpos + 2, this.y + this.height, 0xFFFF0000); guiGraphics.fill(xpos, getY() + getHeight() * 4 / 5, xpos + 2, getY() + getHeight(), 0xFFFF0000);
guiGraphics.fill(xpos, this.y + this.height * 3 / 5, xpos + 2, this.y + this.height * 4 / 5, 0xFFFFFF00); guiGraphics.fill(xpos, getY() + getHeight() * 3 / 5, xpos + 2, getY() + getHeight() * 4 / 5, 0xFFFFFF00);
guiGraphics.fill(xpos, this.y + this.height * 2 / 5, xpos + 2, this.y + this.height * 3 / 5, 0xFF00FF00); guiGraphics.fill(xpos, getY() + getHeight() * 2 / 5, xpos + 2, getY() + getHeight() * 3 / 5, 0xFF00FF00);
int healthHeight = ((health - 50) * this.height / 50); int healthHeight = ((health - 50) * getHeight() / 50);
guiGraphics.fill(xpos + xoffset, this.y + this.height - healthHeight, xpos + xoffset + 2, this.y + this.height, 0xFF00FFFF); guiGraphics.fill(xpos + xoffset, getY() + getHeight() - healthHeight, xpos + xoffset + 2, getY() + getHeight(), 0xFF00FFFF);
} else if (health > 20) { } else if (health > 20) {
guiGraphics.fill(xpos, this.y + this.height * 4 / 5, xpos + 2, this.y + this.height, 0xFFFF0000); guiGraphics.fill(xpos, getY() + getHeight() * 4 / 5, xpos + 2, getY() + getHeight(), 0xFFFF0000);
guiGraphics.fill(xpos, this.y + this.height * 3 / 5, xpos + 2, this.y + this.height * 4 / 5, 0xFFFFFF00); guiGraphics.fill(xpos, getY() + getHeight() * 3 / 5, xpos + 2, getY() + getHeight() * 4 / 5, 0xFFFFFF00);
int healthHeight = ((health - 20) * this.height / 30); int healthHeight = ((health - 20) * getHeight() / 30);
guiGraphics.fill(xpos + xoffset, this.y + this.height - healthHeight, xpos + xoffset + 2, this.y + this.height, 0xFF00FF00); guiGraphics.fill(xpos + xoffset, getY() + getHeight() - healthHeight, xpos + xoffset + 2, getY() + getHeight(), 0xFF00FF00);
} else if (health > 10) { } else if (health > 10) {
guiGraphics.fill(xpos, this.y + this.height * 4 / 5, xpos + 2, this.y + this.height, 0xFFFF0000); guiGraphics.fill(xpos, getY() + getHeight() * 4 / 5, xpos + 2, getY() + getHeight(), 0xFFFF0000);
int healthHeight = ((health - 10) * this.height / 10); int healthHeight = ((health - 10) * getHeight() / 10);
guiGraphics.fill(xpos + xoffset, this.y + this.height - healthHeight, xpos + xoffset + 2, this.y + this.height, 0xFFFFFF00); guiGraphics.fill(xpos + xoffset, getY() + getHeight() - healthHeight, xpos + xoffset + 2, getY() + getHeight(), 0xFFFFFF00);
} else { } else {
int healthHeight = (health * this.height / 10); int healthHeight = (health * getHeight() / 10);
guiGraphics.fill(xpos + xoffset, this.y + this.height - healthHeight, xpos + xoffset + 2, this.y + this.height, 0xFFFF0000); guiGraphics.fill(xpos + xoffset, getY() + getHeight() - healthHeight, xpos + xoffset + 2, getY() + getHeight(), 0xFFFF0000);
} }
} }
} }
@Override
protected void updateWidgetNarration(NarrationElementOutput p_259858_) {
p_259858_.add(NarratedElementType.HINT, TurnBasedMinecraftMod.proxy.getEntity(entityID, Minecraft.getInstance().level.dimension()).getName());
}
@Override
public void onPress() { public void onPress() {
onPress.onPress(this); onPress.onPress(this);
} }
@Override
public void setFocused(boolean b) {
this.focused = b;
}
@Override
public boolean isFocused() {
return focused;
}
@Override
public NarrationPriority narrationPriority() {
return NarrationPriority.FOCUSED;
}
@Override
public void updateNarration(NarrationElementOutput narrationElementOutput) {
narrationElementOutput.add(NarratedElementType.HINT, TurnBasedMinecraftMod.proxy.getEntity(entityID, Minecraft.getInstance().level.dimension()).getName());
}
@Override
public boolean mouseClicked(double x, double y, int unknown) {
if (unknown == 0 && x >= this.x && y >= this.y && x <= (double)(this.x + this.width) && y <= (double)(this.y + this.height)) {
onPress();
return true;
}
return false;
}
} }

View file

@ -1,26 +1,19 @@
package com.burnedkirby.TurnBasedMinecraft.client; package com.burnedkirby.TurnBasedMinecraft.client;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Renderable; import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarratedElementType;
import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.network.chat.Component;
public class ItemSelectionButton implements Renderable, GuiEventListener, NarratableEntry { public class ItemSelectionButton extends AbstractButton {
private int x;
private int y; TBMButtonPress onPress;
private int width;
private int height;
TBMItemButtonPress onPress;
private int itemStackID; private int itemStackID;
private boolean focused;
public ItemSelectionButton(int x, int y, int widthIn, int heightIn, int itemStackID, TBMItemButtonPress onPress) { public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, TBMButtonPress onPress) {
this.x = x; super(x, y, widthIn, heightIn, Component.literal(buttonText));
this.y = y;
this.width = widthIn;
this.height = heightIn;
this.onPress = onPress; this.onPress = onPress;
this.itemStackID = itemStackID; this.itemStackID = itemStackID;
} }
@ -31,44 +24,23 @@ public class ItemSelectionButton implements Renderable, GuiEventListener, Narrat
@Override @Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float unk) { public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float unk) {
boolean hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; if (visible) {
if (hovered) { boolean hovered = mouseX >= getX() && mouseY >= getY() && mouseX < getX() + getWidth() && mouseY < getY() + getHeight();
guiGraphics.fill(this.x, this.y, this.x + this.width, this.y + this.height, 0x80FFFFFF); if (hovered) {
} else { guiGraphics.fill(getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x80FFFFFF);
guiGraphics.fill(this.x, this.y, this.x + this.width, this.y + this.height, 0x20707070); } else {
guiGraphics.fill(getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x20707070);
}
} }
} }
@Override
protected void updateWidgetNarration(NarrationElementOutput p_259858_) {
p_259858_.add(NarratedElementType.HINT, "Item " + this.itemStackID);
}
@Override
public void onPress() { public void onPress() {
onPress.onPress(this); onPress.onPress(this);
} }
@Override
public void setFocused(boolean b) {
focused = b;
}
@Override
public boolean isFocused() {
return focused;
}
@Override
public NarrationPriority narrationPriority() {
return NarrationPriority.FOCUSED;
}
@Override
public void updateNarration(NarrationElementOutput narrationElementOutput) {
narrationElementOutput.add(NarratedElementType.HINT, "Item " + this.itemStackID);
}
@Override
public boolean mouseClicked(double x, double y, int unknown) {
if (unknown == 0 && x >= this.x && y >= this.y && x <= (double)(this.x + this.width) && y <= (double)(this.y + this.height)) {
onPress();
return true;
}
return false;
}
} }

View file

@ -1,5 +0,0 @@
package com.burnedkirby.TurnBasedMinecraft.client;
public interface TBMEntityButtonPress {
void onPress(EntitySelectionButton button);
}

View file

@ -1,5 +0,0 @@
package com.burnedkirby.TurnBasedMinecraft.client;
public interface TBMItemButtonPress {
void onPress(ItemSelectionButton button);
}

View file

@ -37,7 +37,7 @@ import org.apache.logging.log4j.Logger;
public class TurnBasedMinecraftMod { 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.25.1"; public static final String VERSION = "1.25.0";
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/";
@ -78,7 +78,7 @@ public class TurnBasedMinecraftMod {
} }
private void firstInit(final FMLCommonSetupEvent event) { private void firstInit(final FMLCommonSetupEvent event) {
proxy = DistExecutor.unsafeRunForDist(() -> () -> new ClientProxy(), () -> () -> new CommonProxy()); proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
proxy.setLogger(logger); proxy.setLogger(logger);
proxy.initialize(); proxy.initialize();

View file

@ -33,7 +33,7 @@ description='''
Implements turn-based-battle in Minecraft. Implements turn-based-battle in Minecraft.
''' '''
logoFile="assets/com_burnedkirby_turnbasedminecraft/tbmm_icon.png" logoFile="/assets/com_burnedkirby_turnbasedminecraft/tbmm_icon.png"
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.com_burnedkirby_turnbasedminecraft]] #optional [[dependencies.com_burnedkirby_turnbasedminecraft]] #optional