Forge 52.0.21 (Minecraft 1.21.1)

Features should be almost the same as the NeoForge branch.
This commit is contained in:
Stephen Seo 2024-10-15 14:41:07 +09:00
parent e9019245dc
commit 1d12e8c3a7
22 changed files with 640 additions and 179 deletions

View file

@ -25,7 +25,7 @@ jobs:
- run: cd TurnBasedMinecraftMod && git checkout ${GITHUB_REF_NAME} - run: cd TurnBasedMinecraftMod && git checkout ${GITHUB_REF_NAME}
- run: cd TurnBasedMinecraftMod && sed -i '/org.gradle.jvmargs/s/Xmx[0-9]\+m/Xmx1024m/' gradle.properties - run: cd TurnBasedMinecraftMod && sed -i '/org.gradle.jvmargs/s/Xmx[0-9]\+m/Xmx1024m/' gradle.properties
- run: cd TurnBasedMinecraftMod && ./gradlew --console=plain build - run: cd TurnBasedMinecraftMod && ./gradlew --console=plain build
- run: cd TurnBasedMinecraftMod/build/libs && find . -type f -exec sha256sum '{}' ';' -exec bash -c 'sha256sum {} >> sha256sums.txt' ';' && java --version >> javaVersion.txt && javac --version >> javaVersion.txt - run: cd TurnBasedMinecraftMod/build/libs && find . -regex '.*all.jar$' -exec sha256sum '{}' ';' -exec bash -c 'sha256sum {} >> sha256sums.txt' ';' && java --version >> javaVersion.txt && javac --version >> javaVersion.txt
- name: Create release and attach jar - name: Create release and attach jar
run: | run: |
curl --fail-with-body -X 'POST' \ curl --fail-with-body -X 'POST' \

View file

@ -2,34 +2,64 @@ plugins {
id 'eclipse' id 'eclipse'
id 'idea' id 'idea'
id 'maven-publish' id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)' id 'net.minecraftforge.gradle' version '[6.0.24,6.2)'
} }
version = mod_version version = mod_version
group = mod_group_id group = mod_group_id
archivesBaseName = "TurnBasedMinecraft-Forge"
java.toolchain.languageVersion = JavaLanguageVersion.of(17) base {
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) archivesName = "TurnBasedMinecraft-Forge"
}
// Mojang ships Java 21 to end users in 1.20.5+, so your mod should target Java 21.
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
jarJar.enable() jarJar.enable()
minecraft { minecraft {
// The mappings can be changed at any time, and must be in the following format. // The mappings can be changed at any time and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly. // Channel: Version:
// stable_# Stables are built at the discretion of the MCP team. // official MCVersion Official field/method names from Mojang mapping files
// Use non-default mappings at your own risk. they may not always work. // parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official
//
// You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
//
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
// Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started
//
// 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. // Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: mapping_channel, version: mapping_version mappings channel: mapping_channel, version: mapping_version
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// Tell FG to not automtically create the reobf tasks, as we now use Official mappings at runtime, If you don't use them at dev time then you'll have to fix your reobf yourself.
reobf = false
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
// In most cases, it is not necessary to enable.
// enableEclipsePrepareRuns = true
// enableIdeaPrepareRuns = true
// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game. // This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
// It is REQUIRED to be set to true for this template to function. // It is REQUIRED to be set to true for this template to function.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
copyIdeResources = true copyIdeResources = true
// When true, this property will add the folder name of all declared run configurations to generated IDE run configurations.
// The folder name can be set on a run configuration using the "folderName" property.
// By default, the folder name of a run configuration is the name of the Gradle project containing it.
// generateRunFolders = true
// This property enables access transformers for use in development.
// They will be applied to the Minecraft artifact.
// The access transformer file can be anywhere in the project.
// However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge.
// This default location is a best practice to automatically put the file in the right place in the final jar.
// See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// 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 {
@ -81,6 +111,9 @@ minecraft {
sourceSets.main.resources { srcDir 'src/generated/resources' } sourceSets.main.resources { srcDir 'src/generated/resources' }
repositories { repositories {
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you
flatDir { flatDir {
dir 'libs' dir 'libs'
} }
@ -94,6 +127,24 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. // 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}"
// Example mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-forge-api:${jei_version}"
// runtimeOnly "mezz.jei:jei-${mc_version}-forge:${jei_version}"
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// 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
// Hack fix for now, force jopt-simple to be exactly 5.0.4 because Mojang ships that version, but some transitive dependencies request 6.0+
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
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'
@ -140,7 +191,7 @@ tasks.named('jar', Jar).configure {
} }
// This is the preferred method to reobfuscate your jar file // This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar' //finalizedBy 'reobfJar'
} }
// Reproducible Builds // Reproducible Builds
@ -162,3 +213,8 @@ sourceSets.each {
it.output.resourcesDir = dir it.output.resourcesDir = dir
it.java.destinationDirectory = dir it.java.destinationDirectory = dir
} }
// Ensure "jarJar" is run after "build"
tasks.named("build").configure {
finalizedBy "jarJar"
}

View file

@ -1,16 +1,19 @@
org.gradle.jvmargs=-Xmx4096m # Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false 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.21.1
# 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.21.1,1.22)
# 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=52.0.21
# 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=[0,)
# 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
@ -32,7 +35,8 @@ 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.21.1
## Mod Properties ## Mod Properties
@ -44,7 +48,7 @@ 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.2 mod_version=1.26.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

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000 networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -259,7 +259,7 @@ public class BattleMusic
// set volume // set volume
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(volume * 20.0f - 20.0f); // in decibels gainControl.setValue(BattleMusic.percentageToDecibels(volume)); // in decibels
clip.loop(Clip.LOOP_CONTINUOUSLY); clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start(); clip.start();
@ -387,6 +387,16 @@ public class BattleMusic
return !sillyMusic.isEmpty(); return !sillyMusic.isEmpty();
} }
public static float percentageToDecibels(float percentage) {
if (percentage > 1.0F) {
return 0.0F;
} else if (percentage <= 0.0F) {
return Float.NEGATIVE_INFINITY;
} else {
return (float) (Math.log10(percentage) * 20.0);
}
}
private class MP3Streamer implements Runnable private class MP3Streamer implements Runnable
{ {
private AtomicBoolean keepPlaying; private AtomicBoolean keepPlaying;
@ -438,7 +448,7 @@ public class BattleMusic
sdl.open(audioFormat); sdl.open(audioFormat);
{ {
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN); FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(volume * 20.0f - 20.0f); // in decibels volumeControl.setValue(BattleMusic.percentageToDecibels(volume)); // in decibels
} }
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -536,7 +546,7 @@ public class BattleMusic
sdl.open(audioFormat); sdl.open(audioFormat);
{ {
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN); FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(volume * 20.0f - 20.0f); // in decibels volumeControl.setValue(BattleMusic.percentageToDecibels(volume)); // in decibels
} }
AudioInputStream ais = reader.getAudioInputStream(oggVorbisFile); AudioInputStream ais = reader.getAudioInputStream(oggVorbisFile);

View file

@ -0,0 +1,68 @@
package com.burnedkirby.TurnBasedMinecraft.client;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraftforge.common.ForgeConfigSpec;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.List;
public class ClientConfig {
public static final ClientConfig CLIENT;
public static final ForgeConfigSpec CLIENT_SPEC;
static {
Pair<ClientConfig, ForgeConfigSpec> pair =
new ForgeConfigSpec.Builder().configure(ClientConfig::new);
CLIENT = pair.getKey();
CLIENT_SPEC = pair.getValue();
}
public final ForgeConfigSpec.ConfigValue<List<? extends String>> battleMusicList;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> sillyMusicList;
public final ForgeConfigSpec.DoubleValue sillyMusicThreshold;
public final ForgeConfigSpec.BooleanValue volumeAffectedByMasterVolume;
public final ForgeConfigSpec.BooleanValue volumeAffectedByMusicVolume;
public final ForgeConfigSpec.DoubleValue musicVolume;
ClientConfig(ForgeConfigSpec.Builder builder) {
//builder.push("music");
List<String> battleMusicList = new ArrayList<String>(8);
battleMusicList.add("monster");
battleMusicList.add("animal");
battleMusicList.add("boss");
battleMusicList.add("player");
this.battleMusicList = builder.comment("What categories of mobs that play \"battle\" music")
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.battle_music_list")
.defineList("battleMusicList", battleMusicList, (v) -> v instanceof String);
List<String> sillyMusicList = new ArrayList<String>(4);
sillyMusicList.add("passive");
this.sillyMusicList = builder.comment("What categories of mobs that play \"silly\" music")
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.silly_music_list")
.defineList("sillyMusicList", sillyMusicList, (v) -> true);
this.sillyMusicThreshold =
builder.comment("Minimum percentage of silly entities in battle to use silly music")
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.silly_percentage")
.defineInRange("sillyMusicThreshold", 0.4, 0.0, 1.0);
this.volumeAffectedByMasterVolume = builder.comment(
"If \"true\", music volume will be affected by global Master volume setting")
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.volume_affected_by_master")
.define("volumeAffectedByMasterVolume", true);
this.volumeAffectedByMusicVolume = builder.comment(
"If \"true\", music volume will be affected by global Music volume setting")
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.volume_affected_by_volume")
.define("volumeAffectedByMusicVolume", true);
this.musicVolume =
builder.comment("Volume of battle/silly music as a percentage between 0.0 and 1.0")
.translation(TurnBasedMinecraftMod.MODID + ".clientconfig.music_volume")
.defineInRange("musicVolume", 0.7, 0.0, 1.0);
//builder.pop();
}
}

View file

@ -0,0 +1,263 @@
package com.burnedkirby.TurnBasedMinecraft.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.*;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import java.util.ArrayList;
import java.util.List;
public class ClientConfigGui extends net.minecraft.client.gui.screens.Screen {
private final int widget_height = 20;
private boolean dirtyFlag;
private boolean accepted;
private EditBox battleListEditBox = null;
private EditBox sillyListEditBox = null;
private SliderPercentage sillyMusicThresholdSlider = null;
private Checkbox affectedByMasterVolCheckbox = null;
private Checkbox affectedByMusicVolCheckbox = null;
private SliderPercentage volumeSlider = null;
public ClientConfigGui() {
super(Component.literal("TurnBasedMC Client Config"));
dirtyFlag = true;
accepted = false;
}
public void onDirty() {
clearWidgets();
// Initialize GUI elements.
int widget_x_offset = 5;
int widget_width = this.width / 2 - widget_x_offset * 2;
int top_offset = 5;
addRenderableWidget(
new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
widget_width, widget_height, Component.literal("Battle Music Categories"),
font));
if (battleListEditBox == null) {
battleListEditBox =
new EditBox(font, this.width / 2 + widget_x_offset, top_offset, widget_width,
widget_height, Component.literal("Battle Music Categories Edit Box"));
} else {
battleListEditBox.setPosition(this.width / 2 + widget_x_offset, top_offset);
battleListEditBox.setSize(widget_width, widget_height);
}
String tempString = "";
for (String category : ClientConfig.CLIENT.battleMusicList.get()) {
if (tempString.isEmpty()) {
tempString = category;
} else {
tempString += "," + category;
}
}
battleListEditBox.setMaxLength(128);
battleListEditBox.setValue(tempString);
addRenderableWidget(battleListEditBox);
top_offset += widget_height;
addRenderableWidget(
new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
widget_width, widget_height, Component.literal("Silly Music Categories"),
font));
if (sillyListEditBox == null) {
sillyListEditBox =
new EditBox(font, this.width / 2 + widget_x_offset, top_offset, widget_width,
widget_height, Component.literal("Silly Music Categories Edit Box"));
} else {
sillyListEditBox.setPosition(this.width / 2 + widget_x_offset, top_offset);
sillyListEditBox.setSize(widget_width, widget_height);
}
tempString = "";
for (String category : ClientConfig.CLIENT.sillyMusicList.get()) {
if (tempString.isEmpty()) {
tempString = category;
} else {
tempString += "," + category;
}
}
sillyListEditBox.setMaxLength(128);
sillyListEditBox.setValue(tempString);
addRenderableWidget(sillyListEditBox);
top_offset += widget_height;
StringWidget stringWidget =
new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
widget_width, widget_height, Component.literal("Silly Music Threshold"), font);
stringWidget.setTooltip(Tooltip.create(
Component.literal("Ratio of minimum of silly mobs in battle to play silly music")));
addRenderableWidget(stringWidget);
if (sillyMusicThresholdSlider == null) {
sillyMusicThresholdSlider =
new SliderPercentage(this.width / 2 + widget_x_offset, top_offset, widget_width,
widget_height, Component.literal("Silly Music Threshold: " +
String.format("%.1f%%", ClientConfig.CLIENT.sillyMusicThreshold.get() * 100.0)),
ClientConfig.CLIENT.sillyMusicThreshold.get(), "Silly Music Threshold: ");
} else {
sillyMusicThresholdSlider.setPosition(this.width / 2 + widget_x_offset, top_offset);
sillyMusicThresholdSlider.setSize(widget_width, widget_height);
}
addRenderableWidget(sillyMusicThresholdSlider);
top_offset += widget_height;
stringWidget =
new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
widget_width, widget_height, Component.literal("Affected by Master Vol."),
font);
stringWidget.setTooltip(Tooltip.create(
Component.literal("If enabled, volume is affected by global master volume.")));
addRenderableWidget(stringWidget);
if (affectedByMasterVolCheckbox == null) {
affectedByMasterVolCheckbox = Checkbox.builder(Component.literal(""), font)
.pos(this.width / 2 + widget_x_offset, top_offset).build();
} else {
affectedByMasterVolCheckbox.setPosition(this.width / 2 + widget_x_offset,
top_offset);
}
if ((ClientConfig.CLIENT.volumeAffectedByMasterVolume.get() &&
!affectedByMasterVolCheckbox.selected()) ||
(!ClientConfig.CLIENT.volumeAffectedByMasterVolume.get() &&
affectedByMasterVolCheckbox.selected())) {
affectedByMasterVolCheckbox.onPress();
}
addRenderableWidget(affectedByMasterVolCheckbox);
top_offset += widget_height;
stringWidget =
new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
widget_width, widget_height, Component.literal("Affected by Music Vol."), font);
stringWidget.setTooltip(Tooltip.create(
Component.literal("If enabled, volume is affected by global music volume.")));
addRenderableWidget(stringWidget);
if (affectedByMusicVolCheckbox == null) {
affectedByMusicVolCheckbox = Checkbox.builder(Component.literal(""), font)
.pos(this.width / 2 + widget_x_offset, top_offset).build();
} else {
affectedByMusicVolCheckbox.setPosition(this.width / 2 + widget_x_offset,
top_offset);
}
if ((ClientConfig.CLIENT.volumeAffectedByMusicVolume.get() &&
!affectedByMusicVolCheckbox.selected()) ||
(!ClientConfig.CLIENT.volumeAffectedByMusicVolume.get() &&
affectedByMusicVolCheckbox.selected())) {
affectedByMusicVolCheckbox.onPress();
}
addRenderableWidget(affectedByMusicVolCheckbox);
top_offset += widget_height;
stringWidget =
new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
widget_width, widget_height, Component.literal("Music Volume"), font);
stringWidget.setTooltip(
Tooltip.create(Component.literal("Volume of battle/silly music")));
addRenderableWidget(stringWidget);
if (volumeSlider == null) {
volumeSlider =
new SliderPercentage(this.width / 2 + widget_x_offset, top_offset, widget_width,
widget_height, Component.literal(
"Volume: " + String.format("%.1f%%", ClientConfig.CLIENT.musicVolume.get() * 100.0)),
ClientConfig.CLIENT.musicVolume.get(), "Volume: ");
} else {
volumeSlider.setPosition(this.width / 2 + widget_x_offset, top_offset);
volumeSlider.setSize(widget_width, widget_height);
}
addRenderableWidget(volumeSlider);
addRenderableWidget(Button.builder(Component.literal("Cancel"),
(b) -> Minecraft.getInstance().setScreen(null))
.bounds(this.width / 2 - widget_width + widget_x_offset,
this.height - widget_height, widget_width, widget_height).build());
addRenderableWidget(Button.builder(Component.literal("Accept"), (b) -> {
accepted = true;
}).bounds(this.width / 2 + widget_x_offset, this.height - widget_height, widget_width,
widget_height).build());
dirtyFlag = false;
}
private void doAccepted() {
String temp = battleListEditBox.getValue();
{
List<String> battleList = new ArrayList<String>();
for (String category : temp.split(",")) {
battleList.add(category.strip());
}
ClientConfig.CLIENT.battleMusicList.set(battleList);
}
temp = sillyListEditBox.getValue();
{
List<String> sillyList = new ArrayList<String>();
for (String category : temp.split(",")) {
sillyList.add(category.strip());
}
ClientConfig.CLIENT.sillyMusicList.set(sillyList);
}
ClientConfig.CLIENT.sillyMusicThreshold.set(sillyMusicThresholdSlider.percentage);
ClientConfig.CLIENT.volumeAffectedByMasterVolume.set(affectedByMasterVolCheckbox.selected());
ClientConfig.CLIENT.volumeAffectedByMusicVolume.set(affectedByMusicVolCheckbox.selected());
ClientConfig.CLIENT.musicVolume.set(volumeSlider.percentage);
ClientConfig.CLIENT_SPEC.save();
}
@Override
public boolean isPauseScreen() {
return true;
}
@Override
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
if (accepted) {
doAccepted();
Minecraft.getInstance().setScreen(null);
return;
}
if (dirtyFlag) {
onDirty();
}
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
}
@Override
public void resize(Minecraft pMinecraft, int pWidth, int pHeight) {
dirtyFlag = true;
super.resize(pMinecraft, pWidth, pHeight);
}
private static class SliderPercentage extends AbstractSliderButton {
private final String messagePrefix;
private double percentage;
public SliderPercentage(int x, int y, int width, int height, Component message, double percentage, String messagePrefix) {
super(x, y, width, height, message, percentage);
this.percentage = percentage;
this.messagePrefix = messagePrefix;
}
@Override
protected void updateMessage() {
setMessage(
Component.literal(messagePrefix + String.format("%.1f%%", percentage * 100.0)));
}
@Override
protected void applyValue() {
percentage = value;
}
}
}

View file

@ -94,13 +94,27 @@ public class ClientProxy extends CommonProxy {
@Override @Override
public void playBattleMusic() { public void playBattleMusic() {
Options gs = Minecraft.getInstance().options; Options gs = Minecraft.getInstance().options;
battleMusic.playBattle(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER)); float volume = ClientConfig.CLIENT.musicVolume.get().floatValue();
if (ClientConfig.CLIENT.volumeAffectedByMasterVolume.get()) {
volume *= gs.getSoundSourceVolume(SoundSource.MASTER);
}
if (ClientConfig.CLIENT.volumeAffectedByMusicVolume.get()) {
volume *= gs.getSoundSourceVolume(SoundSource.MUSIC);
}
battleMusic.playBattle(volume);
} }
@Override @Override
public void playSillyMusic() { public void playSillyMusic() {
Options gs = Minecraft.getInstance().options; Options gs = Minecraft.getInstance().options;
battleMusic.playSilly(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER)); float volume = ClientConfig.CLIENT.musicVolume.get().floatValue();
if (ClientConfig.CLIENT.volumeAffectedByMasterVolume.get()) {
volume *= gs.getSoundSourceVolume(SoundSource.MASTER);
}
if (ClientConfig.CLIENT.volumeAffectedByMusicVolume.get()) {
volume *= gs.getSoundSourceVolume(SoundSource.MUSIC);
}
battleMusic.playSilly(volume);
} }
@Override @Override
@ -116,9 +130,9 @@ public class ClientProxy extends CommonProxy {
if (localBattle == null) { if (localBattle == null) {
return; return;
} }
if (type == null || type.isEmpty() || getConfig().isBattleMusicType(type)) { if (type == null || type.isEmpty() || ClientConfig.CLIENT.battleMusicList.get().contains(type)) {
++battleMusicCount; ++battleMusicCount;
} else if (getConfig().isSillyMusicType(type)) { } else if (ClientConfig.CLIENT.sillyMusicList.get().contains(type)) {
++sillyMusicCount; ++sillyMusicCount;
} else { } else {
++battleMusicCount; ++battleMusicCount;
@ -132,9 +146,9 @@ public class ClientProxy extends CommonProxy {
battleMusicCount = 0; battleMusicCount = 0;
sillyMusicCount = 0; sillyMusicCount = 0;
return; return;
} else if (type == null || type.isEmpty() || getConfig().isBattleMusicType(type)) { } else if (type == null || type.isEmpty() || ClientConfig.CLIENT.battleMusicList.get().contains(type)) {
--battleMusicCount; --battleMusicCount;
} else if (getConfig().isSillyMusicType(type)) { } else if (ClientConfig.CLIENT.sillyMusicList.get().contains(type)) {
--sillyMusicCount; --sillyMusicCount;
} else { } else {
--battleMusicCount; --battleMusicCount;
@ -185,7 +199,7 @@ public class ClientProxy extends CommonProxy {
percentage = 100.0f * (float) sillyMusicCount / (float) (sillyMusicCount + battleMusicCount); percentage = 100.0f * (float) sillyMusicCount / (float) (sillyMusicCount + battleMusicCount);
} }
if (percentage >= (float) getConfig().getSillyMusicThreshold()) { if (percentage >= ClientConfig.CLIENT.sillyMusicThreshold.get().floatValue()) {
if (battleMusic.isPlaying()) { if (battleMusic.isPlaying()) {
if (!battleMusic.isPlayingSilly() && battleMusic.hasSillyMusic()) { if (!battleMusic.isPlayingSilly() && battleMusic.hasSillyMusic()) {
stopMusic(false); stopMusic(false);
@ -1460,4 +1474,9 @@ public class ClientProxy extends CommonProxy {
} }
} }
} }
}
@Override
public void showClientConfigGui() {
Minecraft.getInstance().setScreen(new ClientConfigGui());
}
}

View file

@ -779,7 +779,7 @@ public class Battle {
final Entity targetEntity = target.entity; final Entity targetEntity = target.entity;
final float yawDirection = Utility.yawDirection(next.entity.getX(), next.entity.getZ(), target.entity.getX(), target.entity.getZ()); final float yawDirection = Utility.yawDirection(next.entity.getX(), next.entity.getZ(), target.entity.getX(), target.entity.getZ());
final float pitchDirection = Utility.pitchDirection(next.entity.getX(), next.entity.getY(), next.entity.getZ(), target.entity.getX(), target.entity.getY(), target.entity.getZ()); final float pitchDirection = Utility.pitchDirection(next.entity.getX(), next.entity.getY(), next.entity.getZ(), target.entity.getX(), target.entity.getY(), target.entity.getZ());
final int randomTimeLeft = random.nextInt(heldItemStack.getItem().getUseDuration(heldItemStack) / 3); final int randomTimeLeft = random.nextInt(heldItemStack.getUseDuration((LivingEntity)next.entity) / 3);
if (TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled()) { if (TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled()) {
next.yaw = yawDirection; next.yaw = yawDirection;
next.pitch = pitchDirection; next.pitch = pitchDirection;
@ -1088,7 +1088,7 @@ public class Battle {
debugLog += " null"; debugLog += " null";
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;
} else if (targetItem.isEdible()) { } else if (Utility.isItemEdible(targetItemStack)) {
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;
@ -1097,7 +1097,7 @@ public class Battle {
} else { } else {
// then check vanilla foods // then check vanilla foods
final CreativeModeTab foodAndDrinksTab = CreativeModeTabRegistry.getTab(CreativeModeTabs.FOOD_AND_DRINKS.location()); final CreativeModeTab foodAndDrinksTab = CreativeModeTabRegistry.getTab(CreativeModeTabs.FOOD_AND_DRINKS.location());
if (foodAndDrinksTab.contains(targetItemStack) && targetItem.isEdible()) { if (foodAndDrinksTab.contains(targetItemStack) && Utility.isItemEdible(targetItemStack)) {
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;

View file

@ -173,4 +173,6 @@ public class CommonProxy
} }
public <MSG> void handlePacket(MSG msg,CustomPayloadEvent.Context ctx) {} public <MSG> void handlePacket(MSG msg,CustomPayloadEvent.Context ctx) {}
}
public void showClientConfigGui() {}
}

View file

@ -37,10 +37,7 @@ public class Config
private int fleeBadProbability = 35; private int fleeBadProbability = 35;
private int minimumHitPercentage = 4; private int minimumHitPercentage = 4;
private int maxInBattle = 8; private int maxInBattle = 8;
private Set<String> musicBattleTypes;
private Set<String> musicSillyTypes;
private boolean freezeCombatantsInBattle = false; private boolean freezeCombatantsInBattle = false;
private int sillyMusicThreshold = 40;
private int configVersion = 0; private int configVersion = 0;
private Set<Integer> battleIgnoringPlayers = null; private Set<Integer> battleIgnoringPlayers = null;
private boolean onlyOPsSelfDisableTB = true; private boolean onlyOPsSelfDisableTB = true;
@ -63,8 +60,6 @@ public class Config
customEntityInfoMap = new HashMap<String, EntityInfo>(); customEntityInfoMap = new HashMap<String, EntityInfo>();
ignoreBattleTypes = new HashSet<String>(); ignoreBattleTypes = new HashSet<String>();
this.logger = logger; this.logger = logger;
musicBattleTypes = new HashSet<String>();
musicSillyTypes = new HashSet<String>();
battleIgnoringPlayers = new HashSet<Integer>(); battleIgnoringPlayers = new HashSet<Integer>();
possibleIgnoreHurtDamageSources = new HashSet<String>(); possibleIgnoreHurtDamageSources = new HashSet<String>();
ignoreHurtDamageSources = new HashSet<String>(); ignoreHurtDamageSources = new HashSet<String>();
@ -156,56 +151,6 @@ public class Config
{ {
CommentedFileConfig conf = getConfigObj(configFile); CommentedFileConfig conf = getConfigObj(configFile);
// client config
try {
Collection<String> battle_music_categories = conf.get("client_config.battle_music");
if (battle_music_categories != null) {
for (String category : battle_music_categories) {
musicBattleTypes.add(category);
}
} else {
musicBattleTypes.add("monster");
musicBattleTypes.add("animal");
musicBattleTypes.add("boss");
musicBattleTypes.add("player");
logNotFound("client_config.battle_music");
}
} catch (ClassCastException e) {
musicBattleTypes.add("monster");
musicBattleTypes.add("animal");
musicBattleTypes.add("boss");
musicBattleTypes.add("player");
logTOMLInvalidValue("client_config.battle_music");
}
try {
Collection<String> silly_music_categories = conf.get("client_config.silly_music");
if (silly_music_categories != null) {
for (String category : silly_music_categories) {
musicSillyTypes.add(category);
}
} else {
musicSillyTypes.add("passive");
logNotFound("client_config.silly_music");
}
} catch (ClassCastException e) {
musicSillyTypes.add("passive");
logTOMLInvalidValue("client_config.silly_music");
}
try {
OptionalInt silly_music_threshold = conf.getOptionalInt("client_config.silly_music_threshold");
if(silly_music_threshold.isPresent()) {
this.sillyMusicThreshold = silly_music_threshold.getAsInt();
} else {
this.sillyMusicThreshold = 40;
logNotFound("client_config.silly_music_threshold", "40");
}
} catch (ClassCastException e) {
this.sillyMusicThreshold = 40;
logTOMLInvalidValue("client_config.silly_music_threshold", "40");
}
// server_config // server_config
try { try {
OptionalInt leave_battle_cooldown = conf.getOptionalInt("server_config.leave_battle_cooldown"); OptionalInt leave_battle_cooldown = conf.getOptionalInt("server_config.leave_battle_cooldown");
@ -1328,16 +1273,6 @@ public class Config
this.maxInBattle = maxInBattle; this.maxInBattle = maxInBattle;
} }
public boolean isBattleMusicType(String type)
{
return musicBattleTypes.contains(type.toLowerCase());
}
public boolean isSillyMusicType(String type)
{
return musicSillyTypes.contains(type.toLowerCase());
}
public boolean isFreezeCombatantsEnabled() public boolean isFreezeCombatantsEnabled()
{ {
return freezeCombatantsInBattle; return freezeCombatantsInBattle;
@ -1347,11 +1282,6 @@ public class Config
freezeCombatantsInBattle = enabled; freezeCombatantsInBattle = enabled;
} }
public int getSillyMusicThreshold()
{
return sillyMusicThreshold;
}
public int getConfigVersion() public int getConfigVersion()
{ {
return configVersion; return configVersion;

View file

@ -276,7 +276,7 @@ public class EntityInfo
{ {
if(this == FIRE) if(this == FIRE)
{ {
entity.setSecondsOnFire(duration / 20); entity.setRemainingFireTicks(duration / 2);
return; return;
} }
else if(this != UNKNOWN) else if(this != UNKNOWN)

View file

@ -1,5 +1,6 @@
package com.burnedkirby.TurnBasedMinecraft.common; package com.burnedkirby.TurnBasedMinecraft.common;
import com.burnedkirby.TurnBasedMinecraft.client.ClientConfig;
import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy; import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy;
import com.burnedkirby.TurnBasedMinecraft.common.networking.*; import com.burnedkirby.TurnBasedMinecraft.common.networking.*;
import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.LiteralMessage;
@ -25,6 +26,7 @@ import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
@ -48,8 +50,8 @@ public class TurnBasedMinecraftMod {
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/"; public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/"; public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
private static final Integer PROTOCOL_VERSION = 3; private static final Integer PROTOCOL_VERSION = 4;
private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel"); private static final ResourceLocation HANDLER_ID = ResourceLocation.fromNamespaceAndPath(MODID, "main_channel");
private static final SimpleChannel HANDLER = ChannelBuilder private static final SimpleChannel HANDLER = ChannelBuilder
.named(HANDLER_ID) .named(HANDLER_ID)
@ -69,12 +71,14 @@ public class TurnBasedMinecraftMod {
public static CommonProxy proxy; public static CommonProxy proxy;
public TurnBasedMinecraftMod() { public TurnBasedMinecraftMod(FMLJavaModLoadingContext ctx) {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::firstInit); ctx.getModEventBus().addListener(this::firstInit);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitClient); ctx.getModEventBus().addListener(this::secondInitClient);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitServer); ctx.getModEventBus().addListener(this::secondInitServer);
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
ctx.registerConfig(ModConfig.Type.CLIENT, ClientConfig.CLIENT_SPEC);
} }
private void firstInit(final FMLCommonSetupEvent event) { private void firstInit(final FMLCommonSetupEvent event) {
@ -113,6 +117,11 @@ public class TurnBasedMinecraftMod {
.decoder(new PacketEditingMessage.Decoder()) .decoder(new PacketEditingMessage.Decoder())
.consumerNetworkThread(new PacketEditingMessage.Consumer()) .consumerNetworkThread(new PacketEditingMessage.Consumer())
.add(); .add();
HANDLER.messageBuilder(PacketClientGui.class, NetworkDirection.PLAY_TO_CLIENT)
.encoder(new PacketClientGui.Encoder())
.decoder(new PacketClientGui.Decoder())
.consumerNetworkThread(new PacketClientGui.Consumer())
.add();
// register event handler(s) // register event handler(s)
MinecraftForge.EVENT_BUS.register(new AttackEventHandler()); MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
@ -1683,6 +1692,15 @@ public class TurnBasedMinecraftMod {
return 1; return 1;
}))) })))
); );
// tbm-client-edit
event.getDispatcher().register(
Commands.literal("tbm-client-edit").executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
getHandler().send(new PacketClientGui(), PacketDistributor.PLAYER.with(player));
return 1;
})
);
} }
@SubscribeEvent @SubscribeEvent

View file

@ -1,11 +1,13 @@
package com.burnedkirby.TurnBasedMinecraft.common; package com.burnedkirby.TurnBasedMinecraft.common;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArrowItem; import net.minecraft.world.item.ArrowItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
public class Utility public class Utility
@ -59,7 +61,11 @@ public class Utility
} }
public static ResourceKey<Level> deserializeDimension(String dimString) { public static ResourceKey<Level> deserializeDimension(String dimString) {
ResourceLocation dimRes = new ResourceLocation(dimString); ResourceLocation dimRes = ResourceLocation.parse(dimString);
return ResourceKey.create(Registries.DIMENSION, dimRes); return ResourceKey.create(Registries.DIMENSION, dimRes);
} }
public static boolean isItemEdible(ItemStack itemStack) {
return itemStack.get(DataComponents.FOOD) != null;
}
} }

View file

@ -1,16 +1,15 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.Battle.Decision;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.network.CustomPayloadEvent;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.Battle.Decision;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleDecision public class PacketBattleDecision
{ {
private int battleID; private int battleID;
@ -26,22 +25,22 @@ public class PacketBattleDecision
this.targetIDOrItemID = targetIDOrItemID; this.targetIDOrItemID = targetIDOrItemID;
} }
public static class Encoder implements BiConsumer<PacketBattleDecision, FriendlyByteBuf> { public static class Encoder implements BiConsumer<PacketBattleDecision, RegistryFriendlyByteBuf> {
public Encoder() {} public Encoder() {}
@Override @Override
public void accept(PacketBattleDecision pkt, FriendlyByteBuf buf) { public void accept(PacketBattleDecision pkt, RegistryFriendlyByteBuf buf) {
buf.writeInt(pkt.battleID); buf.writeInt(pkt.battleID);
buf.writeInt(pkt.decision.getValue()); buf.writeInt(pkt.decision.getValue());
buf.writeInt(pkt.targetIDOrItemID); buf.writeInt(pkt.targetIDOrItemID);
} }
} }
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleDecision> { public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketBattleDecision> {
public Decoder() {} public Decoder() {}
@Override @Override
public PacketBattleDecision apply(FriendlyByteBuf buf) { public PacketBattleDecision apply(RegistryFriendlyByteBuf buf) {
return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt()); return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
} }
} }

View file

@ -1,17 +1,16 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.event.network.CustomPayloadEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleInfo public class PacketBattleInfo
{ {
private Collection<Integer> sideA; private Collection<Integer> sideA;
@ -39,11 +38,11 @@ public class PacketBattleInfo
this.turnTimerEnabled = turnTimerEnabled; this.turnTimerEnabled = turnTimerEnabled;
} }
public static class Encoder implements BiConsumer<PacketBattleInfo, FriendlyByteBuf> { public static class Encoder implements BiConsumer<PacketBattleInfo, RegistryFriendlyByteBuf> {
public Encoder() {} public Encoder() {}
@Override @Override
public void accept(PacketBattleInfo msg, FriendlyByteBuf buf) { public void accept(PacketBattleInfo msg, RegistryFriendlyByteBuf buf) {
buf.writeInt(msg.sideA.size()); buf.writeInt(msg.sideA.size());
buf.writeInt(msg.sideB.size()); buf.writeInt(msg.sideB.size());
for(Integer id : msg.sideA) { for(Integer id : msg.sideA) {
@ -58,11 +57,11 @@ public class PacketBattleInfo
} }
} }
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleInfo> { public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketBattleInfo> {
public Decoder() {} public Decoder() {}
@Override @Override
public PacketBattleInfo apply(FriendlyByteBuf buf) { public PacketBattleInfo apply(RegistryFriendlyByteBuf buf) {
int sideACount = buf.readInt(); int sideACount = buf.readInt();
int sideBCount = buf.readInt(); int sideBCount = buf.readInt();
Collection<Integer> sideA = new ArrayList<Integer>(sideACount); Collection<Integer> sideA = new ArrayList<Integer>(sideACount);

View file

@ -1,20 +1,19 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.Utility; import com.burnedkirby.TurnBasedMinecraft.common.Utility;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class PacketBattleMessage public class PacketBattleMessage
{ {
public enum MessageType public enum MessageType
@ -156,11 +155,11 @@ public class PacketBattleMessage
this.custom = custom; this.custom = custom;
} }
public static class Encoder implements BiConsumer<PacketBattleMessage, FriendlyByteBuf> { public static class Encoder implements BiConsumer<PacketBattleMessage, RegistryFriendlyByteBuf> {
public Encoder() {} public Encoder() {}
@Override @Override
public void accept(PacketBattleMessage pkt, FriendlyByteBuf buf) { public void accept(PacketBattleMessage pkt, RegistryFriendlyByteBuf buf) {
buf.writeInt(pkt.messageType.getValue()); buf.writeInt(pkt.messageType.getValue());
buf.writeInt(pkt.entityIDFrom); buf.writeInt(pkt.entityIDFrom);
buf.writeInt(pkt.entityIDTo); buf.writeInt(pkt.entityIDTo);
@ -170,11 +169,11 @@ public class PacketBattleMessage
} }
} }
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleMessage> { public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketBattleMessage> {
public Decoder() {} public Decoder() {}
@Override @Override
public PacketBattleMessage apply(FriendlyByteBuf buf) { public PacketBattleMessage apply(RegistryFriendlyByteBuf buf) {
return new PacketBattleMessage( return new PacketBattleMessage(
MessageType.valueOf( MessageType.valueOf(
buf.readInt()), buf.readInt()),

View file

@ -1,14 +1,13 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.Battle; import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class PacketBattleRequestInfo public class PacketBattleRequestInfo
{ {
private int battleID; private int battleID;
@ -20,20 +19,20 @@ public class PacketBattleRequestInfo
this.battleID = battleID; this.battleID = battleID;
} }
public static class Encoder implements BiConsumer<PacketBattleRequestInfo, FriendlyByteBuf> { public static class Encoder implements BiConsumer<PacketBattleRequestInfo, RegistryFriendlyByteBuf> {
public Encoder() {} public Encoder() {}
@Override @Override
public void accept(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) { public void accept(PacketBattleRequestInfo pkt, RegistryFriendlyByteBuf buf) {
buf.writeInt(pkt.battleID); buf.writeInt(pkt.battleID);
} }
} }
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleRequestInfo> { public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketBattleRequestInfo> {
public Decoder() {} public Decoder() {}
@Override @Override
public PacketBattleRequestInfo apply(FriendlyByteBuf buf) { public PacketBattleRequestInfo apply(RegistryFriendlyByteBuf buf) {
return new PacketBattleRequestInfo(buf.readInt()); return new PacketBattleRequestInfo(buf.readInt());
} }
} }

View file

@ -0,0 +1,52 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class PacketClientGui {
int reserved;
public PacketClientGui() {
reserved = 0;
}
public PacketClientGui(int reserved) {
this.reserved = reserved;
}
public static class Encoder implements BiConsumer<PacketClientGui, RegistryFriendlyByteBuf> {
public Encoder() {}
@Override
public void accept(PacketClientGui pkt, RegistryFriendlyByteBuf buf) {
buf.writeInt(pkt.reserved);
}
}
public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketClientGui> {
public Decoder() {}
@Override
public PacketClientGui apply(RegistryFriendlyByteBuf registryFriendlyByteBuf) {
return new PacketClientGui(registryFriendlyByteBuf.readInt());
}
}
public static class Consumer implements BiConsumer<PacketClientGui, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketClientGui pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.showClientConfigGui());
});
ctx.setPacketHandled(true);
}
}
}

View file

@ -2,7 +2,7 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import com.burnedkirby.TurnBasedMinecraft.common.EntityInfo; import com.burnedkirby.TurnBasedMinecraft.common.EntityInfo;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
@ -89,11 +89,11 @@ public class PacketEditingMessage
} }
} }
public static class Encoder implements BiConsumer<PacketEditingMessage, FriendlyByteBuf> { public static class Encoder implements BiConsumer<PacketEditingMessage, RegistryFriendlyByteBuf> {
public Encoder() {} public Encoder() {}
@Override @Override
public void accept(PacketEditingMessage pkt, FriendlyByteBuf buf) { public void accept(PacketEditingMessage pkt, RegistryFriendlyByteBuf buf) {
buf.writeInt(pkt.type.getValue()); buf.writeInt(pkt.type.getValue());
if(pkt.entityInfo.classType != null) { if(pkt.entityInfo.classType != null) {
buf.writeUtf(pkt.entityInfo.classType.getName()); buf.writeUtf(pkt.entityInfo.classType.getName());
@ -118,11 +118,11 @@ public class PacketEditingMessage
} }
} }
public static class Decoder implements Function<FriendlyByteBuf, PacketEditingMessage> { public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketEditingMessage> {
public Decoder() {} public Decoder() {}
@Override @Override
public PacketEditingMessage apply(FriendlyByteBuf buf) { public PacketEditingMessage apply(RegistryFriendlyByteBuf buf) {
Type type = Type.valueOf(buf.readInt()); Type type = Type.valueOf(buf.readInt());
EntityInfo einfo = new EntityInfo(); EntityInfo einfo = new EntityInfo();
try { try {

View file

@ -1,15 +1,14 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class PacketGeneralMessage public class PacketGeneralMessage
{ {
String message; String message;
@ -28,20 +27,20 @@ public class PacketGeneralMessage
this.message = message; this.message = message;
} }
public static class Encoder implements BiConsumer<PacketGeneralMessage, FriendlyByteBuf> { public static class Encoder implements BiConsumer<PacketGeneralMessage, RegistryFriendlyByteBuf> {
public Encoder() {} public Encoder() {}
@Override @Override
public void accept(PacketGeneralMessage pkt, FriendlyByteBuf buf) { public void accept(PacketGeneralMessage pkt, RegistryFriendlyByteBuf buf) {
buf.writeUtf(pkt.message); buf.writeUtf(pkt.message);
} }
} }
public static class Decoder implements Function<FriendlyByteBuf, PacketGeneralMessage> { public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketGeneralMessage> {
public Decoder() {} public Decoder() {}
@Override @Override
public PacketGeneralMessage apply(FriendlyByteBuf buf) { public PacketGeneralMessage apply(RegistryFriendlyByteBuf buf) {
return new PacketGeneralMessage(buf.readUtf()); return new PacketGeneralMessage(buf.readUtf());
} }
} }

View file

@ -1,21 +1,13 @@
# Please do not change this option, the mod uses this to keep track of what new # Please do not change this option, the mod uses this to keep track of what new
# changes to add to the config. # changes to add to the config.
version = 10 version = 11
# Change this to "true" if you want the config to never be replaced. This means # Change this to "true" if you want the config to never be replaced. This means
# that you will not get new mob listings from future updates unless this remains # that you will not get new mob listings from future updates unless this remains
# "false"! # "false"!
do_not_overwrite = false do_not_overwrite = false
[client_config]
# What categories play this type of music (battle_music). Unknown categories will default to this type.
battle_music = ["monster", "animal", "boss", "player"]
# What categories play this type of music (silly_music).
silly_music = ["passive"]
# Minimum percentage of silly entities in battle to use silly music.
silly_music_threshold = 40
# Note that client config is no longer stored here but rather in the settings.
[server_config] [server_config]
@ -138,6 +130,37 @@ decision_defend_probability = 0
decision_flee_probability = 0 decision_flee_probability = 0
ignore_battle = false ignore_battle = false
[[server_config.entity]]
name = "net.minecraft.world.entity.monster.Bogged"
attack_power = 3
attack_probability = 75
attack_variance = 1
attack_effect = "poison"
attack_effect_probability = 50
defense_damage = 0
evasion = 10
category = "monster"
speed = 20
decision_attack_probability = 100
decision_defend_probability = 0
decision_flee_probability = 0
ignore_battle = false
[[server_config.entity]]
name = "net.minecraft.world.entity.monster.breeze.Breeze"
attack_power = 1
attack_probability = 50
attack_effect = "unknown"
attack_variance = 0
defense_damage = 0
evasion = 45
category = "monster"
speed = 45
decision_attack_probability = 100
decision_defend_probability = 0
decision_flee_probability = 0
ignore_battle = false
[[server_config.entity]] [[server_config.entity]]
name = "net.minecraft.world.entity.monster.CaveSpider" name = "net.minecraft.world.entity.monster.CaveSpider"
attack_power = 2 attack_power = 2
@ -684,6 +707,21 @@ decision_defend_probability = 0
decision_flee_probability = 100 decision_flee_probability = 100
ignore_battle = false ignore_battle = false
[[server_config.entity]]
name = "net.minecraft.world.entity.animal.armadillo.Armadillo"
attack_power = 0
attack_probability = 0
attack_variance = 0
attack_effect = "unknown"
defense_damage = 0
evasion = 10
category = "passive"
speed = 20
decision_attack_probability = 0
decision_defend_probability = 50
decision_flee_probability = 50
ignore_battle = false
[[server_config.entity]] [[server_config.entity]]
name = "net.minecraft.world.entity.animal.axolotl.Axolotl" name = "net.minecraft.world.entity.animal.axolotl.Axolotl"
attack_power = 2 attack_power = 2