WIP porting to forge 1.14.4

This commit is contained in:
Stephen Seo 2019-10-21 16:13:11 +09:00
parent f05e5e6a07
commit d2f668187e
24 changed files with 2216 additions and 2262 deletions

View file

@ -1,93 +1,150 @@
buildscript { buildscript {
repositories { repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" } maven { url = "http://files.minecraftforge.net/maven" }
jcenter()
mavenCentral()
} }
dependencies { dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.1'
} }
} }
apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'eclipse'
//apply plugin: 'maven-publish'
version = "1.8" version = "1.9"
group = "com.seodisparate.TurnBasedMinecraft" group = "com.seodisparate.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft"
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
minecraft { minecraft {
version = "1.12.2-14.23.5.2768" // The mappings can be changed at any time, and must be in the following format.
runDir = "run" // snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work. // 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 = "snapshot_20171003" mappings channel: 'snapshot', version: '20190719-1.14.3'
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
TurnBasedMinecraftMod {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
TurnBasedMinecraftMod {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
args '--mod', 'TurnBasedMinecraftMod', '--all', '--output', file('src/generated/resources/')
mods {
TurnBasedMinecraftMod {
source sourceSets.main
}
}
}
}
} }
dependencies { dependencies {
// you may put jars on which you depend on in ./libs // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// or you may define them like so.. // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
//compile "some.group:artifact:version:classifier" // The userdev artifact is a special name and will get all sorts of transformations applied to it.
//compile "some.group:artifact:version" minecraft 'net.minecraftforge:forge:1.14.4-28.1.0'
// toml parser // You may put jars on which you depend on in ./libs or you may define them like so..
compile "net.consensys.cava:cava-toml:0.3.1" // compile "some.group:artifact:version:classifier"
// compile "some.group:artifact:version"
// real examples // Real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env // compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env // compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. // The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' // provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, // These dependencies get remapped to your current MCP mappings
// except that these dependencies get remapped to your current MCP mappings // deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev'
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// for more info... // For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html // http://www.gradle.org/docs/current/userguide/dependency_management.html
compile files('src/main/resources/META-INF/libraries/javamp3-1.0.3.jar')
} }
processResources { // Example for how to get properties into the manifest for reading by the runtime..
// this will ensure that this task is redone when the versions change. jar {
inputs.property "version", project.version manifest {
inputs.property "mcversion", project.minecraft.version attributes([
"Specification-Title": "TurnBasedMinecraftMod",
// replace stuff in mcmod.info, nothing else "Specification-Vendor": "TurnBasedMinecraftMod_SS",
from(sourceSets.main.resources.srcDirs) { "Specification-Version": "1", // We are version 1 of ourselves
include 'mcmod.info' "Implementation-Title": project.name,
"Implementation-Version": "${version}",
// replace version and mcversion "Implementation-Vendor" :"TurnBasedMinecraftMod_SS",
expand 'version':project.version, 'mcversion':project.minecraft.version "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
} "ContainedDeps": "javamp3-1.0.3.jar"
])
// copy everything else except the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
} }
} }
shadowJar { // Example configuration to allow publishing using the maven-publish task
classifier "" // we define a custom artifact that is sourced from the reobfJar output task
// and then declare that to be published
relocate 'net.consensys.cava', 'shadow.turnbasedmc.net.consensys.cava' // Note you'll need to add a repository here
relocate 'org.antlr.v4', 'shadow.turnbasedmc.org.antlr.v4' def reobfFile = file("$buildDir/reobfJar/output.jar")
relocate 'javax.annotation', 'shadow.turnbasedmc.javax.annotation' def reobfArtifact = artifacts.add('default', reobfFile) {
type 'jar'
relocate 'fr.delthas', 'shadow.turnbasedmc.fr.delthas' builtBy 'reobfJar'
} }
//publishing {
reobf { shadowJar { mappingType = "SEARGE" } } // publications {
tasks.reobfShadowJar.mustRunAfter shadowJar // mavenJava(MavenPublication) {
// artifact reobfArtifact
// }
// }
// repositories {
// maven {
// url "file:///${project.projectDir}/mcmodsrepo"
// }
// }
//}

View file

@ -1,6 +1,5 @@
package com.seodisparate.TurnBasedMinecraft.client; package com.seodisparate.TurnBasedMinecraft.client;
import java.io.IOException;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -13,11 +12,11 @@ import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;
public class BattleGui extends GuiScreen public class BattleGui extends Screen {
{
private AtomicInteger timeRemaining; private AtomicInteger timeRemaining;
private long lastInstant; private long lastInstant;
private long elapsedTime; private long elapsedTime;
@ -25,113 +24,83 @@ public class BattleGui extends GuiScreen
private boolean stateChanged; private boolean stateChanged;
private String info; private String info;
private enum MenuState private enum MenuState {
{ MAIN_MENU(0), ATTACK_TARGET(1), ITEM_ACTION(2), WAITING(3), SWITCH_ITEM(4), USE_ITEM(5);
MAIN_MENU(0),
ATTACK_TARGET(1),
ITEM_ACTION(2),
WAITING(3),
SWITCH_ITEM(4),
USE_ITEM(5);
private int value; private int value;
MenuState(int value) MenuState(int value) {
{
this.value = value; this.value = value;
} }
public int getValue() public int getValue() {
{
return value; return value;
} }
private static Map<Integer, MenuState> map; private static Map<Integer, MenuState> map;
static static {
{
map = new HashMap<Integer, MenuState>(); map = new HashMap<Integer, MenuState>();
for(MenuState state : MenuState.values()) for (MenuState state : MenuState.values()) {
{
map.put(state.getValue(), state); map.put(state.getValue(), state);
} }
} }
public static MenuState valueOf(int value) public static MenuState valueOf(int value) {
{
return map.get(value); return map.get(value);
} }
} }
private enum ButtonAction private enum ButtonAction {
{ ATTACK(0), DEFEND(1), ITEM(2), FLEE(3), ATTACK_TARGET(4), SWITCH_HELD_ITEM(5), DECIDE_USE_ITEM(6), CANCEL(7),
ATTACK(0), DO_ITEM_SWITCH(8), DO_USE_ITEM(9);
DEFEND(1),
ITEM(2),
FLEE(3),
ATTACK_TARGET(4),
SWITCH_HELD_ITEM(5),
DECIDE_USE_ITEM(6),
CANCEL(7),
DO_ITEM_SWITCH(8),
DO_USE_ITEM(9);
private int value; private int value;
ButtonAction(int value) ButtonAction(int value) {
{
this.value = value; this.value = value;
} }
public int getValue() public int getValue() {
{
return value; return value;
} }
private static Map<Integer, ButtonAction> map; private static Map<Integer, ButtonAction> map;
static static {
{
map = new HashMap<Integer, ButtonAction>(); map = new HashMap<Integer, ButtonAction>();
for(ButtonAction action : ButtonAction.values()) for (ButtonAction action : ButtonAction.values()) {
{
map.put(action.getValue(), action); map.put(action.getValue(), action);
} }
} }
public static ButtonAction valueOf(int value) public static ButtonAction valueOf(int value) {
{
return map.get(value); return map.get(value);
} }
} }
public BattleGui() public BattleGui() {
{ super(new StringTextComponent("Battle Gui"));
timeRemaining = new AtomicInteger((int)(Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L)); timeRemaining = new AtomicInteger((int) (Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L));
lastInstant = System.nanoTime(); lastInstant = System.nanoTime();
elapsedTime = 0; elapsedTime = 0;
state = MenuState.MAIN_MENU; state = MenuState.MAIN_MENU;
stateChanged = true; stateChanged = true;
} }
private void setState(MenuState state) private void setState(MenuState state) {
{
this.state = state; this.state = state;
stateChanged = true; stateChanged = true;
} }
public void turnBegin() public void turnBegin() {
{ if (TurnBasedMinecraftMod.proxy.getLocalBattle() != null) {
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.ACTION); TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.ACTION);
} }
setState(MenuState.WAITING); setState(MenuState.WAITING);
} }
public void turnEnd() public void turnEnd() {
{ if (TurnBasedMinecraftMod.proxy.getLocalBattle() != null) {
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION); TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION);
} }
timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds()); timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds());
@ -140,114 +109,129 @@ public class BattleGui extends GuiScreen
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
} }
public void battleChanged() public void battleChanged() {
{
stateChanged = true; stateChanged = true;
} }
public void updateState() public void updateState() {
{ if (!stateChanged) {
if(!stateChanged)
{
return; return;
} }
stateChanged = false; stateChanged = false;
buttonList.clear(); buttons.clear();
switch(state) children.clear();
{ switch (state) {
case MAIN_MENU: case MAIN_MENU:
info = "What will you do?"; info = "What will you do?";
buttonList.add(new GuiButton(ButtonAction.ATTACK.getValue(), width*3/7 - 25, 40, 50, 20, "Attack")); addButton(new Button(width * 3 / 7 - 25, 40, 50, 20, "Attack", (button) -> {
buttonList.add(new GuiButton(ButtonAction.DEFEND.getValue(), width*4/7 - 25, 40, 50, 20, "Defend")); buttonActionEvent(button, ButtonAction.ATTACK);
buttonList.add(new GuiButton(ButtonAction.ITEM.getValue(), width*3/7 - 25, 60, 50, 20, "Item")); }));
buttonList.add(new GuiButton(ButtonAction.FLEE.getValue(), width*4/7 - 25, 60, 50, 20, "Flee")); addButton(new Button(width * 4 / 7 - 25, 40, 50, 20, "Defend", (button) -> {
buttonActionEvent(button, ButtonAction.DEFEND);
}));
addButton(new Button(width * 3 / 7 - 25, 60, 50, 20, "Item", (button) -> {
buttonActionEvent(button, ButtonAction.ITEM);
}));
addButton(new Button(width * 4 / 7 - 25, 60, 50, 20, "Flee", (button) -> {
buttonActionEvent(button, ButtonAction.FLEE);
}));
break; break;
case ATTACK_TARGET: case ATTACK_TARGET:
info = "Who will you attack?"; info = "Who will you attack?";
int y = 30; int y = 30;
try try {
{ for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet()) .getSideAEntrySet()) {
{ if (e.getValue().entity != null) {
if(e.getValue().entity != null) addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), true, (button) -> {
{ buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), true)); }));
} } else {
else addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, "Unknown", e.getKey(), true, (button) -> {
{ buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey(), true)); }));
} }
y += 20; y += 20;
} }
} catch (ConcurrentModificationException e) } catch (ConcurrentModificationException e) {
{
// ignored // ignored
} }
y = 30; y = 30;
try try {
{ for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideBEntrySet()) .getSideBEntrySet()) {
{ if (e.getValue().entity != null) {
if(e.getValue().entity != null) addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), false, (button) -> {
{ buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), false)); }));
} } else {
else addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, "Unknown", e.getKey(), false, (button) -> {
{ buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey(), false)); }));
} }
y += 20; y += 20;
} }
} catch (ConcurrentModificationException e) } catch (ConcurrentModificationException e) {
{
// ignored // ignored
} }
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 30, height - 120, 60, 20, "Cancel")); addButton(new Button(width / 2 - 30, height - 120, 60, 20, "Cancel", (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
break; break;
case ITEM_ACTION: case ITEM_ACTION:
info = "What will you do with an item?"; info = "What will you do with an item?";
buttonList.add(new GuiButton(ButtonAction.SWITCH_HELD_ITEM.getValue(), width*1/4 - 40, height - 120, 80, 20, "Switch Held")); addButton(new Button(width * 1 / 4 - 40, height - 120, 80, 20, "Switch Held", (button) -> {
buttonList.add(new GuiButton(ButtonAction.DECIDE_USE_ITEM.getValue(), width*2/4 - 40, height - 120, 80, 20, "Use")); buttonActionEvent(button, ButtonAction.SWITCH_HELD_ITEM);
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width*3/4 - 40, height - 120, 80, 20, "Cancel")); }));
addButton(new Button(width * 2 / 4 - 40, height - 120, 80, 20, "Use", (button) -> {
buttonActionEvent(button, ButtonAction.DECIDE_USE_ITEM);
}));
addButton(new Button(width * 3 / 4 - 40, height - 120, 80, 20, "Cancel", (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
break; break;
case WAITING: case WAITING:
info = "Waiting..."; info = "Waiting...";
break; break;
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) {
{ addButton(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, "", i, (button) -> {
buttonList.add(new ItemSelectionButton(ButtonAction.DO_ITEM_SWITCH.getValue(), width/2 - 88 + i * 20, height - 19, 16, 16, "", i)); buttonActionEvent(button, ButtonAction.DO_ITEM_SWITCH);
}));
} }
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel")); addButton(new Button(width / 2 - 40, height - 120, 80, 20, "Cancel", (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
break; break;
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) {
{ addButton(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, "", i, (button) -> {
buttonList.add(new ItemSelectionButton(ButtonAction.DO_USE_ITEM.getValue(), width/2 - 88 + i * 20, height - 19, 16, 16, "", i)); buttonActionEvent(button, ButtonAction.DO_USE_ITEM);
}));
} }
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel")); addButton(new Button(width / 2 - 40, height - 120, 80, 20, "Cancel", (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
break; break;
} }
} }
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) public void render(int mouseX, int mouseY, float partialTicks) {
{ if (TurnBasedMinecraftMod.proxy.getLocalBattle() == null) {
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null) // drawHoveringText("Waiting...", width / 2 - 50, height / 2);
{ getMinecraft().fontRenderer.drawString("Waiting...", width / 2 - 50, height / 2, 0xFFFFFFFF);
drawHoveringText("Waiting...", width / 2 - 50, height / 2);
return; return;
} }
if(TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION && timeRemaining.get() > 0) if (TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION
{ && timeRemaining.get() > 0) {
long nextInstant = System.nanoTime(); long nextInstant = System.nanoTime();
elapsedTime += nextInstant - lastInstant; elapsedTime += nextInstant - lastInstant;
lastInstant = nextInstant; lastInstant = nextInstant;
while(elapsedTime > 1000000000) while (elapsedTime > 1000000000) {
{
elapsedTime -= 1000000000; elapsedTime -= 1000000000;
timeRemaining.decrementAndGet(); timeRemaining.decrementAndGet();
} }
@ -255,58 +239,51 @@ public class BattleGui extends GuiScreen
updateState(); updateState();
super.drawScreen(mouseX, mouseY, partialTicks); super.render(mouseX, mouseY, partialTicks);
String timeRemainingString = "Time remaining: "; String timeRemainingString = "Time remaining: ";
int timeRemainingInt = timeRemaining.get(); int timeRemainingInt = timeRemaining.get();
if(timeRemainingInt > 8) if (timeRemainingInt > 8) {
{
timeRemainingString += "\u00A7a"; timeRemainingString += "\u00A7a";
} } else if (timeRemainingInt > 4) {
else if(timeRemainingInt > 4)
{
timeRemainingString += "\u00A7e"; timeRemainingString += "\u00A7e";
} } else {
else
{
timeRemainingString += "\u00A7c"; timeRemainingString += "\u00A7c";
} }
timeRemainingString += Integer.toString(timeRemainingInt); timeRemainingString += Integer.toString(timeRemainingInt);
int stringWidth = Minecraft.getMinecraft().fontRenderer.getStringWidth(timeRemainingString); int stringWidth = getMinecraft().fontRenderer.getStringWidth(timeRemainingString);
drawRect(width/2 - stringWidth/2, 5, width/2 + stringWidth/2, 15, 0x70000000); fill(width / 2 - stringWidth / 2, 5, width / 2 + stringWidth / 2, 15, 0x70000000);
Minecraft.getMinecraft().fontRenderer.drawString(timeRemainingString, width/2 - stringWidth/2, 5, 0xFFFFFFFF); getMinecraft().fontRenderer.drawString(timeRemainingString, width / 2 - stringWidth / 2, 5, 0xFFFFFFFF);
stringWidth = Minecraft.getMinecraft().fontRenderer.getStringWidth(info); stringWidth = getMinecraft().fontRenderer.getStringWidth(info);
drawRect(width/2 - stringWidth/2, 20, width/2 + stringWidth/2, 30, 0x70000000); fill(width / 2 - stringWidth / 2, 20, width / 2 + stringWidth / 2, 30, 0x70000000);
Minecraft.getMinecraft().fontRenderer.drawString(info, width/2 - stringWidth/2, 20, 0xFFFFFFFF); getMinecraft().fontRenderer.drawString(info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF);
} }
@Override protected void buttonActionEvent(Button button, ButtonAction action) {
protected void actionPerformed(GuiButton button) throws IOException switch (action) {
{
switch(ButtonAction.valueOf(button.id))
{
case ATTACK: case ATTACK:
setState(MenuState.ATTACK_TARGET); setState(MenuState.ATTACK_TARGET);
break; break;
case DEFEND: case DEFEND:
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0)); TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ITEM: case ITEM:
setState(MenuState.ITEM_ACTION); setState(MenuState.ITEM_ACTION);
break; break;
case FLEE: case FLEE:
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0)); TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ATTACK_TARGET: case ATTACK_TARGET:
if(button instanceof EntitySelectionButton) if (button instanceof EntitySelectionButton) {
{ TurnBasedMinecraftMod.getHandler()
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID)); .sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID()));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} } else {
else
{
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
} }
break; break;
@ -320,28 +297,25 @@ public class BattleGui extends GuiScreen
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
break; break;
case DO_ITEM_SWITCH: case DO_ITEM_SWITCH:
if(button instanceof ItemSelectionButton) if (button instanceof ItemSelectionButton) {
{ TurnBasedMinecraftMod.getHandler()
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID)); .sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9) Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton) button).getID()));
{ if (((ItemSelectionButton) button).getID() >= 0 && ((ItemSelectionButton) button).getID() < 9) {
Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID; Minecraft.getInstance().player.inventory.currentItem = ((ItemSelectionButton) button).getID();
} }
setState(MenuState.WAITING); setState(MenuState.WAITING);
} } else {
else
{
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
} }
break; break;
case DO_USE_ITEM: case DO_USE_ITEM:
if(button instanceof ItemSelectionButton) if (button instanceof ItemSelectionButton) {
{ TurnBasedMinecraftMod.getHandler()
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID)); .sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
Battle.Decision.USE_ITEM, ((ItemSelectionButton) button).getID()));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} } else {
else
{
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
} }
break; break;
@ -349,34 +323,23 @@ public class BattleGui extends GuiScreen
} }
@Override @Override
public void initGui() protected void init() {
{
super.initGui();
} }
@Override @Override
public void onGuiClosed() public boolean isPauseScreen() {
{
super.onGuiClosed();
}
@Override
public boolean doesGuiPauseGame()
{
return false; return false;
} }
@Override @Override
protected void keyTyped(char typedChar, int keyCode) throws IOException public boolean keyPressed(int a, int b, int c) {
{ if (getMinecraft().player.isCreative()) {
if(Minecraft.getMinecraft().player.isCreative()) return super.keyPressed(a, b, c);
{
super.keyTyped(typedChar, keyCode);
} }
return false; // TODO verify return value
} }
public void setTimeRemaining(int remaining) public void setTimeRemaining(int remaining) {
{
timeRemaining.set(remaining); timeRemaining.set(remaining);
} }
} }

View file

@ -2,9 +2,6 @@ package com.seodisparate.TurnBasedMinecraft.client;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.sound.midi.MidiSystem; import javax.sound.midi.MidiSystem;
@ -186,9 +183,7 @@ public class BattleMusic
if(initialized && next != null) if(initialized && next != null)
{ {
logger.debug("play called with file " + next.getName() + " and vol " + volume); logger.debug("play called with file " + next.getName() + " and vol " + volume);
Minecraft.getMinecraft().addScheduledTask(() -> { Minecraft.getInstance().getSoundHandler().pause();
Minecraft.getMinecraft().getSoundHandler().pauseSounds();
});
String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase(); String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase();
if(suffix.equals("mid")) if(suffix.equals("mid"))
{ {
@ -305,7 +300,7 @@ public class BattleMusic
} }
if(resumeMCSounds) if(resumeMCSounds)
{ {
Minecraft.getMinecraft().addScheduledTask(() -> Minecraft.getMinecraft().getSoundHandler().resumeSounds() ); Minecraft.getInstance().getSoundHandler().resume();
} }
isPlaying = false; isPlaying = false;
} }

View file

@ -3,12 +3,12 @@ package com.seodisparate.TurnBasedMinecraft.client;
import com.seodisparate.TurnBasedMinecraft.common.Battle; import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy; import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
import net.minecraft.client.GameSettings;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
@ -44,13 +44,11 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void setBattleGuiAsGui() public void setBattleGuiAsGui()
{ {
Minecraft.getMinecraft().addScheduledTask(() -> { if(Minecraft.getInstance().currentScreen != battleGui)
if(Minecraft.getMinecraft().currentScreen != battleGui)
{ {
battleGui.turnEnd(); battleGui.turnEnd();
Minecraft.getMinecraft().displayGuiScreen(battleGui); Minecraft.getInstance().displayGuiScreen(battleGui);
} }
});
} }
@Override @Override
@ -75,10 +73,7 @@ public class ClientProxy extends CommonProxy
public void battleEnded() public void battleEnded()
{ {
localBattle = null; localBattle = null;
Minecraft.getMinecraft().addScheduledTask(() -> { Minecraft.getInstance().displayGuiScreen(null);
Minecraft.getMinecraft().displayGuiScreen(null);
Minecraft.getMinecraft().setIngameFocus();
});
stopMusic(true); stopMusic(true);
battleMusicCount = 0; battleMusicCount = 0;
sillyMusicCount = 0; sillyMusicCount = 0;
@ -93,14 +88,14 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void playBattleMusic() public void playBattleMusic()
{ {
GameSettings gs = Minecraft.getMinecraft().gameSettings; GameSettings gs = Minecraft.getInstance().gameSettings;
battleMusic.playBattle(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER)); battleMusic.playBattle(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER));
} }
@Override @Override
public void playSillyMusic() public void playSillyMusic()
{ {
GameSettings gs = Minecraft.getMinecraft().gameSettings; GameSettings gs = Minecraft.getInstance().gameSettings;
battleMusic.playSilly(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER)); battleMusic.playSilly(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER));
} }
@ -160,24 +155,24 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void displayString(String message) public void displayString(String message)
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString(message); ITextComponent text = new StringTextComponent(message);
prefix.appendSibling(text); prefix.appendSibling(text);
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
Minecraft.getMinecraft().player.sendMessage(prefix); Minecraft.getInstance().player.sendMessage(prefix);
} }
@Override @Override
public void displayTextComponent(ITextComponent text) public void displayTextComponent(ITextComponent text)
{ {
Minecraft.getMinecraft().player.sendMessage(text); Minecraft.getInstance().player.sendMessage(text);
} }
@Override @Override
public Entity getEntityByID(int id) public Entity getEntityByID(int id)
{ {
return Minecraft.getMinecraft().world.getEntityByID(id); return Minecraft.getInstance().world.getEntityByID(id);
} }
private void checkBattleTypes() private void checkBattleTypes()

View file

@ -1,92 +1,77 @@
package com.seodisparate.TurnBasedMinecraft.client; package com.seodisparate.TurnBasedMinecraft.client;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
public class EntitySelectionButton extends GuiButton public class EntitySelectionButton extends Button
{ {
public int entityID; private int entityID;
private boolean isSideA; private boolean isSideA;
public EntitySelectionButton(int buttonId, int x, int y, String buttonText, int entityID, boolean isSideA)
{ public EntitySelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA, Button.IPressable onPress) {
super(buttonId, x, y, buttonText); super(x, y, widthIn, heightIn, buttonText, onPress);
this.entityID = entityID; this.entityID = entityID;
this.isSideA = isSideA; this.isSideA = isSideA;
} }
public EntitySelectionButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA) public int getID() {
{ return entityID;
super(buttonId, x, y, widthIn, heightIn, buttonText); }
this.entityID = entityID;
this.isSideA = isSideA; public boolean getIsSideA() {
return isSideA;
} }
@Override @Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) public void render(int mouseX, int mouseY, float partialTicks) {
{ super.render(mouseX, mouseY, partialTicks);
super.drawButton(mc, mouseX, mouseY, partialTicks); Entity e = Minecraft.getInstance().world.getEntityByID(entityID);
Entity e = Minecraft.getMinecraft().world.getEntityByID(entityID); if(e != null && e instanceof LivingEntity && ((LivingEntity)e).isAlive()) {
if(e != null && e instanceof EntityLivingBase && ((EntityLivingBase)e).isEntityAlive()) int health = (int)(((LivingEntity)e).getHealth() + 0.5f);
{
int health = (int)(((EntityLivingBase)e).getHealth() + 0.5f);
int xpos = x; int xpos = x;
int xoffset; int xoffset;
if(isSideA) if(isSideA) {
{
xpos += width + 4; xpos += width + 4;
xoffset = 4; xoffset = 4;
} } else {
else
{
xpos -= 6; xpos -= 6;
xoffset = -4; xoffset = -4;
} }
if(health > 200) if(health > 200) {
{ fill(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); fill(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00); fill(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
drawRect(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00); fill(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
drawRect(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF); fill(xpos, y , xpos + 2, y + height / 5, 0xFF0000FF);
drawRect(xpos, y , xpos + 2, y + height / 5, 0xFF0000FF);
int healthHeight = ((health - 200) * height / 100); int healthHeight = ((health - 200) * height / 100);
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFFFF); fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFFFF);
} } else if(health > 100) {
else if(health > 100) fill(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
{ fill(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); fill(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00); fill(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
drawRect(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
drawRect(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
int healthHeight = ((health - 100) * height / 100); int healthHeight = ((health - 100) * height / 100);
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF0000FF); fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF0000FF);
} } else if(health > 50) {
else if(health > 50) fill(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
{ fill(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000); fill(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
drawRect(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
int healthHeight = ((health - 50) * height / 50); int healthHeight = ((health - 50) * height / 50);
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FFFF); fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FFFF);
} } else if(health > 20) {
else if(health > 20) fill(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
{ fill(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
int healthHeight = ((health - 20) * height / 30); int healthHeight = ((health - 20) * height / 30);
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FF00); fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FF00);
} } else if(health > 10) {
else if(health > 10) fill(xpos, y + height * 4 / 5, xpos + 2, y + height, 0xFFFF0000);
{
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height, 0xFFFF0000);
int healthHeight = ((health - 10) * height / 10); int healthHeight = ((health - 10) * height / 10);
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFF00); fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFF00);
} } else {
else
{
int healthHeight = (health * height / 10); int healthHeight = (health * height / 10);
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFF0000); fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFF0000);
} }
} }
} }

View file

@ -1,37 +1,28 @@
package com.seodisparate.TurnBasedMinecraft.client; package com.seodisparate.TurnBasedMinecraft.client;
import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.GuiButton;
public class ItemSelectionButton extends GuiButton public class ItemSelectionButton extends Button
{ {
int itemStackID; private int itemStackID;
public ItemSelectionButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID) public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, Button.IPressable onPress) {
{ super(x, y, widthIn, heightIn, buttonText, onPress);
super(buttonId, x, y, widthIn, heightIn, buttonText);
this.itemStackID = itemStackID; this.itemStackID = itemStackID;
} }
public ItemSelectionButton(int buttonId, int x, int y, String buttonText, int itemStackID) public int getID() {
{ return itemStackID;
super(buttonId, x, y, buttonText);
this.itemStackID = itemStackID;
} }
@Override @Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) public void render(int mouseX, int mouseY, float partialTicks) {
{ if(visible) {
if(visible) boolean hovered = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
{ if(hovered) {
hovered = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height; fill(x, y, x + width, y + height, 0x80FFFFFF);
if(hovered) } else {
{ fill(x, y, x + width, y + height, 0x20707070);
drawRect(x, y, x + width, y + height, 0x80FFFFFF);
}
else
{
drawRect(x, y, x + width, y + height, 0x20707070);
} }
} }
} }

View file

@ -6,10 +6,11 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage;
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketGeneralMessage; import com.seodisparate.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.network.NetworkDirection;
public class AttackEventHandler public class AttackEventHandler
{ {
@ -77,21 +78,31 @@ public class AttackEventHandler
event.setCanceled(true); event.setCanceled(true);
if(editingInfo.isEditingCustomName) if(editingInfo.isEditingCustomName)
{ {
if(event.getEntity().getCustomNameTag().isEmpty()) if(!event.getEntity().hasCustomName())
{ {
TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name"); TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name");
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.getHandler().sendTo(
new PacketGeneralMessage("Cannot edit custom name from entity without custom name"),
((ServerPlayerEntity)editingInfo.editor).connection.netManager,
NetworkDirection.PLAY_TO_CLIENT);
return; return;
} }
editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomNameTag()); //editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomNameTag());
editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomName().getString());
if(editingInfo.entityInfo == null) if(editingInfo.entityInfo == null)
{ {
editingInfo.entityInfo = new EntityInfo(); editingInfo.entityInfo = new EntityInfo();
editingInfo.entityInfo.customName = event.getEntity().getCustomNameTag(); editingInfo.entityInfo.customName = event.getEntity().getCustomName().getString();
} }
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomNameTag() + "\""), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.getHandler().sendTo(
TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomNameTag() + "\""); new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\""),
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor); ((ServerPlayerEntity)editingInfo.editor).connection.netManager,
NetworkDirection.PLAY_TO_CLIENT);
TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomName().getString() + "\"");
TurnBasedMinecraftMod.getHandler().sendTo(
new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo),
((ServerPlayerEntity)editingInfo.editor).connection.netManager,
NetworkDirection.PLAY_TO_CLIENT);
} }
else else
{ {
@ -105,9 +116,15 @@ public class AttackEventHandler
{ {
editingInfo.entityInfo = editingInfo.entityInfo.clone(); editingInfo.entityInfo = editingInfo.entityInfo.clone();
} }
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.getHandler().sendTo(
new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""),
((ServerPlayerEntity)editingInfo.editor).connection.netManager,
NetworkDirection.PLAY_TO_CLIENT);
TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\""); TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\"");
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor); TurnBasedMinecraftMod.getHandler().sendTo(
new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo),
((ServerPlayerEntity)editingInfo.editor).connection.netManager,
NetworkDirection.PLAY_TO_CLIENT);
} }
return; return;
} }

View file

@ -2,10 +2,11 @@ package com.seodisparate.TurnBasedMinecraft.common;
import java.util.*; import java.util.*;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
@ -152,7 +153,7 @@ public class CommonProxy
return editingPlayers.get(id); return editingPlayers.get(id);
} }
protected final EditingInfo setEditingPlayer(EntityPlayer player) protected final EditingInfo setEditingPlayer(PlayerEntity player)
{ {
return editingPlayers.put(player.getEntityId(), new EditingInfo(player)); return editingPlayers.put(player.getEntityId(), new EditingInfo(player));
} }

View file

@ -1,10 +1,10 @@
package com.seodisparate.TurnBasedMinecraft.common; package com.seodisparate.TurnBasedMinecraft.common;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
public class EditingInfo public class EditingInfo
{ {
public EntityPlayer editor; public PlayerEntity editor;
public EntityInfo entityInfo; public EntityInfo entityInfo;
public boolean isPendingEntitySelection; public boolean isPendingEntitySelection;
public boolean isEditingCustomName; public boolean isEditingCustomName;
@ -17,7 +17,7 @@ public class EditingInfo
isEditingCustomName = false; isEditingCustomName = false;
} }
public EditingInfo(EntityPlayer player) public EditingInfo(PlayerEntity player)
{ {
editor = player; editor = player;
entityInfo = null; entityInfo = null;

View file

@ -1,8 +1,8 @@
package com.seodisparate.TurnBasedMinecraft.common; package com.seodisparate.TurnBasedMinecraft.common;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
import net.minecraft.init.MobEffects; import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.Effects;
public class EntityInfo public class EntityInfo
{ {
@ -43,120 +43,84 @@ public class EntityInfo
WEAKNESS, WEAKNESS,
POISON, POISON,
WITHER, WITHER,
HEALTH_BOOST,
ABSORPTION, ABSORPTION,
SATURATION, SATURATION,
GLOWING, GLOWING,
LEVITATION, LEVITATION,
LUCK, LUCK,
UNLUCK, UNLUCK,
SLOW_FALLING,
CONDUIT_POWER,
DOLPHINS_GRACE,
BAD_OMEN,
FIRE, FIRE,
UNKNOWN; UNKNOWN;
public static Effect fromString(String c) public static Effect fromString(String c)
{ {
c = c.toLowerCase(); c = c.toLowerCase();
if(c.equals("speed")) if(c.equals("speed")) {
{
return SPEED; return SPEED;
} } else if(c.equals("slow")) {
else if(c.equals("slow"))
{
return SLOW; return SLOW;
} } else if(c.equals("haste")) {
else if(c.equals("haste"))
{
return HASTE; return HASTE;
} } else if(c.equals("mining_fatigue") || c.equals("fatigue")) {
else if(c.equals("mining_fatigue") || c.equals("fatigue"))
{
return MINING_FATIGUE; return MINING_FATIGUE;
} } else if(c.equals("strength")) {
else if(c.equals("strength"))
{
return STRENGTH; return STRENGTH;
} } else if(c.equals("jump_boost")) {
else if(c.equals("jump_boost"))
{
return JUMP_BOOST; return JUMP_BOOST;
} } else if(c.equals("nausea")) {
else if(c.equals("nausea"))
{
return NAUSEA; return NAUSEA;
} } else if(c.equals("regeneration")) {
else if(c.equals("regeneration"))
{
return REGENERATION; return REGENERATION;
} } else if(c.equals("resistance")) {
else if(c.equals("resistance"))
{
return RESISTANCE; return RESISTANCE;
} } else if(c.equals("fire_resistance")) {
else if(c.equals("fire_resistance"))
{
return FIRE_RESISTANCE; return FIRE_RESISTANCE;
} } else if(c.equals("water_breathing")) {
else if(c.equals("water_breathing"))
{
return WATER_BREATHING; return WATER_BREATHING;
} } else if(c.equals("invisibility")) {
else if(c.equals("invisibility"))
{
return INVISIBILITY; return INVISIBILITY;
} } else if(c.equals("blindness") || c.equals("blind")) {
else if(c.equals("blindness") || c.equals("blind"))
{
return BLINDNESS; return BLINDNESS;
} } else if(c.equals("night_vision")) {
else if(c.equals("night_vision"))
{
return NIGHT_VISION; return NIGHT_VISION;
} } else if(c.equals("hunger")) {
else if(c.equals("hunger"))
{
return HUNGER; return HUNGER;
} } else if(c.equals("weakness")) {
else if(c.equals("weakness"))
{
return WEAKNESS; return WEAKNESS;
} } else if(c.equals("poison")) {
else if(c.equals("poison"))
{
return POISON; return POISON;
} } else if(c.equals("wither")) {
else if(c.equals("wither"))
{
return WITHER; return WITHER;
} } else if(c.equals("health_boost")) {
else if(c.equals("absorption")) return HEALTH_BOOST;
{ } else if(c.equals("absorption")) {
return ABSORPTION; return ABSORPTION;
} } else if(c.equals("saturation")) {
else if(c.equals("saturation"))
{
return SATURATION; return SATURATION;
} } else if(c.equals("glowing")) {
else if(c.equals("glowing"))
{
return GLOWING; return GLOWING;
} } else if(c.equals("levitation")) {
else if(c.equals("levitation"))
{
return LEVITATION; return LEVITATION;
} } else if(c.equals("luck")) {
else if(c.equals("luck"))
{
return LUCK; return LUCK;
} } else if(c.equals("unluck")) {
else if(c.equals("unluck"))
{
return UNLUCK; return UNLUCK;
} } else if(c.equals("slow_falling")) {
else if(c.equals("fire")) return SLOW_FALLING;
{ } else if(c.equals("conduit_power")) {
return CONDUIT_POWER;
} else if(c.equals("dolphins_grace")) {
return DOLPHINS_GRACE;
} else if(c.equals("bad_omen")) {
return BAD_OMEN;
} else if(c.equals("fire")) {
return FIRE; return FIRE;
} } else {
else
{
return UNKNOWN; return UNKNOWN;
} }
} }
@ -201,6 +165,8 @@ public class EntityInfo
return "poison"; return "poison";
case WITHER: case WITHER:
return "wither"; return "wither";
case HEALTH_BOOST:
return "health_boost";
case ABSORPTION: case ABSORPTION:
return "absorption"; return "absorption";
case SATURATION: case SATURATION:
@ -213,6 +179,14 @@ public class EntityInfo
return "luck"; return "luck";
case UNLUCK: case UNLUCK:
return "unluck"; return "unluck";
case SLOW_FALLING:
return "slow_falling";
case CONDUIT_POWER:
return "conduit_power";
case DOLPHINS_GRACE:
return "dolphins_grace";
case BAD_OMEN:
return "bad_omen";
case FIRE: case FIRE:
return "fire"; return "fire";
default: default:
@ -220,63 +194,71 @@ public class EntityInfo
} }
} }
public PotionEffect getPotionEffect() public EffectInstance getPotionEffect()
{ {
return getPotionEffect(20 * 7, 0); return getPotionEffect(20 * 7, 0);
} }
public PotionEffect getPotionEffect(int duration, int amplifier) public EffectInstance getPotionEffect(int duration, int amplifier) {
{ switch(this) {
switch(this)
{
case SPEED: case SPEED:
return new PotionEffect(MobEffects.SPEED, duration, amplifier); return new EffectInstance(Effects.SPEED, duration, amplifier);
case SLOW: case SLOW:
return new PotionEffect(MobEffects.SLOWNESS, duration, amplifier); return new EffectInstance(Effects.SLOWNESS, duration, amplifier);
case HASTE: case HASTE:
return new PotionEffect(MobEffects.HASTE, duration, amplifier); return new EffectInstance(Effects.HASTE, duration, amplifier);
case MINING_FATIGUE: case MINING_FATIGUE:
return new PotionEffect(MobEffects.MINING_FATIGUE, duration, amplifier); return new EffectInstance(Effects.MINING_FATIGUE, duration, amplifier);
case STRENGTH: case STRENGTH:
return new PotionEffect(MobEffects.STRENGTH, duration, amplifier); return new EffectInstance(Effects.STRENGTH, duration, amplifier);
case JUMP_BOOST: case JUMP_BOOST:
return new PotionEffect(MobEffects.JUMP_BOOST, duration, amplifier); return new EffectInstance(Effects.JUMP_BOOST, duration, amplifier);
case NAUSEA: case NAUSEA:
return new PotionEffect(MobEffects.NAUSEA, duration, amplifier); return new EffectInstance(Effects.NAUSEA, duration, amplifier);
case REGENERATION: case REGENERATION:
return new PotionEffect(MobEffects.REGENERATION, duration, amplifier); return new EffectInstance(Effects.REGENERATION, duration, amplifier);
case RESISTANCE: case RESISTANCE:
return new PotionEffect(MobEffects.RESISTANCE, duration, amplifier); return new EffectInstance(Effects.RESISTANCE, duration, amplifier);
case FIRE_RESISTANCE: case FIRE_RESISTANCE:
return new PotionEffect(MobEffects.FIRE_RESISTANCE, duration, amplifier); return new EffectInstance(Effects.FIRE_RESISTANCE, duration, amplifier);
case WATER_BREATHING: case WATER_BREATHING:
return new PotionEffect(MobEffects.WATER_BREATHING, duration, amplifier); return new EffectInstance(Effects.WATER_BREATHING, duration, amplifier);
case INVISIBILITY: case INVISIBILITY:
return new PotionEffect(MobEffects.INVISIBILITY, duration, amplifier); return new EffectInstance(Effects.INVISIBILITY, duration, amplifier);
case BLINDNESS: case BLINDNESS:
return new PotionEffect(MobEffects.BLINDNESS, duration, amplifier); return new EffectInstance(Effects.BLINDNESS, duration, amplifier);
case NIGHT_VISION: case NIGHT_VISION:
return new PotionEffect(MobEffects.NIGHT_VISION, duration, amplifier); return new EffectInstance(Effects.NIGHT_VISION, duration, amplifier);
case HUNGER: case HUNGER:
return new PotionEffect(MobEffects.HUNGER, duration, amplifier); return new EffectInstance(Effects.HUNGER, duration, amplifier);
case WEAKNESS: case WEAKNESS:
return new PotionEffect(MobEffects.WEAKNESS, duration, amplifier); return new EffectInstance(Effects.WEAKNESS, duration, amplifier);
case POISON: case POISON:
return new PotionEffect(MobEffects.POISON, duration, amplifier); return new EffectInstance(Effects.POISON, duration, amplifier);
case WITHER: case WITHER:
return new PotionEffect(MobEffects.WITHER, duration, amplifier); return new EffectInstance(Effects.WITHER, duration, amplifier);
case HEALTH_BOOST:
return new EffectInstance(Effects.HEALTH_BOOST, duration, amplifier);
case ABSORPTION: case ABSORPTION:
return new PotionEffect(MobEffects.ABSORPTION, duration, amplifier); return new EffectInstance(Effects.ABSORPTION, duration, amplifier);
case SATURATION: case SATURATION:
return new PotionEffect(MobEffects.SATURATION, duration, amplifier); return new EffectInstance(Effects.SATURATION, duration, amplifier);
case GLOWING: case GLOWING:
return new PotionEffect(MobEffects.GLOWING, duration, amplifier); return new EffectInstance(Effects.GLOWING, duration, amplifier);
case LEVITATION: case LEVITATION:
return new PotionEffect(MobEffects.LEVITATION, duration, amplifier); return new EffectInstance(Effects.LEVITATION, duration, amplifier);
case LUCK: case LUCK:
return new PotionEffect(MobEffects.LUCK, duration, amplifier); return new EffectInstance(Effects.LUCK, duration, amplifier);
case UNLUCK: case UNLUCK:
return new PotionEffect(MobEffects.UNLUCK, duration, amplifier); return new EffectInstance(Effects.UNLUCK, duration, amplifier);
case SLOW_FALLING:
return new EffectInstance(Effects.SLOW_FALLING, duration, amplifier);
case CONDUIT_POWER:
return new EffectInstance(Effects.CONDUIT_POWER, duration, amplifier);
case DOLPHINS_GRACE:
return new EffectInstance(Effects.DOLPHINS_GRACE, duration, amplifier);
case BAD_OMEN:
return new EffectInstance(Effects.BAD_OMEN, duration, amplifier);
case FIRE: case FIRE:
// FIRE is not a PotionEffect and must be applied directly to the Entity // FIRE is not a PotionEffect and must be applied directly to the Entity
return null; return null;
@ -285,12 +267,12 @@ public class EntityInfo
} }
} }
public void applyEffectToEntity(EntityLivingBase entity) public void applyEffectToEntity(LivingEntity entity)
{ {
applyEffectToEntity(entity, 20 * 12, 0); applyEffectToEntity(entity, 20 * 12, 0);
} }
public void applyEffectToEntity(EntityLivingBase entity, int duration, int amplifier) public void applyEffectToEntity(LivingEntity entity, int duration, int amplifier)
{ {
if(this == FIRE) if(this == FIRE)
{ {
@ -343,6 +325,8 @@ public class EntityInfo
return "poisoned"; return "poisoned";
case WITHER: case WITHER:
return "withered"; return "withered";
case HEALTH_BOOST:
return "given more health";
case ABSORPTION: case ABSORPTION:
return "given absorption"; return "given absorption";
case SATURATION: case SATURATION:
@ -355,6 +339,12 @@ public class EntityInfo
return "given luck"; return "given luck";
case UNLUCK: case UNLUCK:
return "made unlucky"; return "made unlucky";
case SLOW_FALLING:
return "falls slower";
case CONDUIT_POWER:
return "made able to live underwater";
case BAD_OMEN:
return "feels a bad omen";
case FIRE: case FIRE:
return "set on fire"; return "set on fire";
default: default:

View file

@ -1,8 +1,8 @@
package com.seodisparate.TurnBasedMinecraft.common; package com.seodisparate.TurnBasedMinecraft.common;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
public class PlayerJoinEventHandler public class PlayerJoinEventHandler
{ {
@ -13,7 +13,7 @@ public class PlayerJoinEventHandler
{ {
return; return;
} }
if(event.getEntity() instanceof EntityPlayer && TurnBasedMinecraftMod.proxy.getConfig().getBattleDisabledForAll()) if(event.getEntity() instanceof PlayerEntity && TurnBasedMinecraftMod.proxy.getConfig().getBattleDisabledForAll())
{ {
TurnBasedMinecraftMod.proxy.getConfig().addBattleIgnoringPlayer(event.getEntity().getEntityId()); TurnBasedMinecraftMod.proxy.getConfig().addBattleIgnoringPlayer(event.getEntity().getEntityId());
} }

View file

@ -1,99 +1,122 @@
package com.seodisparate.TurnBasedMinecraft.common; package com.seodisparate.TurnBasedMinecraft.common;
import com.seodisparate.TurnBasedMinecraft.client.ClientProxy;
import com.seodisparate.TurnBasedMinecraft.common.networking.*; import com.seodisparate.TurnBasedMinecraft.common.networking.*;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import net.minecraftforge.common.MinecraftForge; @Mod(value = TurnBasedMinecraftMod.MODID)
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = TurnBasedMinecraftMod.MODID, name = TurnBasedMinecraftMod.NAME, version = TurnBasedMinecraftMod.VERSION)
public class TurnBasedMinecraftMod public class TurnBasedMinecraftMod
{ {
public static final String MODID = "com.seodisparate.turnbasedminecraft"; public static final String MODID = "com.seodisparate.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.8"; public static final String VERSION = "1.8";
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 CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME; public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME;
public static final String DEFAULT_CONFIG_FILE_PATH = CONFIG_DIRECTORY + DEFAULT_CONFIG_FILENAME;
public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME; public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME;
public static final String MUSIC_ROOT = CONFIG_DIRECTORY + "Music/"; public static final String MUSIC_ROOT = CONFIG_DIRECTORY + "Music/";
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/";
public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc"); private static final String PROTOCOL_VERSION = Integer.toString(1);
protected static Logger logger; private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel");
private static int packetHandlerID = 0; private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
.named(HANDLER_ID)
.clientAcceptedVersions(PROTOCOL_VERSION::equals)
.serverAcceptedVersions(PROTOCOL_VERSION::equals)
.networkProtocolVersion(() -> PROTOCOL_VERSION)
.simpleChannel();
protected static Logger logger = LogManager.getLogger();
@SidedProxy(modId=MODID, serverSide="com.seodisparate.TurnBasedMinecraft.common.CommonProxy", clientSide="com.seodisparate.TurnBasedMinecraft.client.ClientProxy") public static ResourceLocation getNetResourceLocation() {
public static CommonProxy proxy; return HANDLER_ID;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
logger = event.getModLog();
proxy.setLogger(logger);
} }
@EventHandler public static SimpleChannel getHandler() {
public void init(FMLInitializationEvent event) return HANDLER;
}
public static CommonProxy proxy;
@SubscribeEvent
public void firstInit(FMLCommonSetupEvent event)
{ {
proxy = DistExecutor.runForDist(()->()->new ClientProxy(), ()->()->new CommonProxy());
proxy.initialize(); proxy.initialize();
proxy.setLogger(logger);
// register packets // register packets
NWINSTANCE.registerMessage( int packetHandlerID = 0;
PacketBattleInfo.HandlerBattleInfo.class, HANDLER.registerMessage(
packetHandlerID++,
PacketBattleInfo.class, PacketBattleInfo.class,
PacketBattleInfo::encode,
PacketBattleInfo::decode,
PacketBattleInfo.Handler::handle);
HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
Side.CLIENT);
NWINSTANCE.registerMessage(
PacketBattleRequestInfo.HandlerBattleRequestInfo.class,
PacketBattleRequestInfo.class, PacketBattleRequestInfo.class,
PacketBattleRequestInfo::encode,
PacketBattleRequestInfo::decode,
PacketBattleRequestInfo.Handler::handle);
HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
Side.SERVER);
NWINSTANCE.registerMessage(
PacketBattleDecision.HandleBattleDecision.class,
PacketBattleDecision.class, PacketBattleDecision.class,
PacketBattleDecision::encode,
PacketBattleDecision::decode,
PacketBattleDecision.Handler::handle);
HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
Side.SERVER);
NWINSTANCE.registerMessage(
PacketBattleMessage.HandlerBattleMessage.class,
PacketBattleMessage.class, PacketBattleMessage.class,
PacketBattleMessage::encode,
PacketBattleMessage::decode,
PacketBattleMessage.Handler::handle);
HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
Side.CLIENT);
NWINSTANCE.registerMessage(
PacketGeneralMessage.HandlerGeneralMessage.class,
PacketGeneralMessage.class, PacketGeneralMessage.class,
PacketGeneralMessage::encode,
PacketGeneralMessage::decode,
PacketGeneralMessage.Handler::handle);
HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
Side.CLIENT);
NWINSTANCE.registerMessage(
PacketEditingMessage.HandlerEditingMessage.class,
PacketEditingMessage.class, PacketEditingMessage.class,
packetHandlerID++, PacketEditingMessage::encode,
Side.CLIENT PacketEditingMessage::decode,
); PacketEditingMessage.Handler::handle);
// register event handler(s) // register event handler(s)
MinecraftForge.EVENT_BUS.register(new AttackEventHandler()); MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler()); MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
} }
@EventHandler @SubscribeEvent
public void postInit(FMLPostInitializationEvent event) public void secondInitClient(FMLClientSetupEvent event)
{ {
proxy.postInit(); proxy.postInit();
} }
@EventHandler @SubscribeEvent
public void secondInitServer(FMLDedicatedServerSetupEvent event)
{
proxy.postInit();
}
@SubscribeEvent
public void serverStarting(FMLServerStartingEvent event) public void serverStarting(FMLServerStartingEvent event)
{ {
logger.debug("About to initialize BattleManager"); logger.debug("About to initialize BattleManager");
@ -113,7 +136,7 @@ public class TurnBasedMinecraftMod
event.registerServerCommand(new CommandTBMEdit(proxy.getConfig())); event.registerServerCommand(new CommandTBMEdit(proxy.getConfig()));
} }
@EventHandler @SubscribeEvent
public void serverStopping(FMLServerStoppingEvent event) public void serverStopping(FMLServerStoppingEvent event)
{ {
logger.debug("About to cleanup BattleManager"); logger.debug("About to cleanup BattleManager");

View file

@ -1,8 +1,8 @@
package com.seodisparate.TurnBasedMinecraft.common; package com.seodisparate.TurnBasedMinecraft.common;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemArrow; import net.minecraft.item.ArrowItem;
public class Utility public class Utility
{ {
@ -33,11 +33,11 @@ public class Utility
} }
} }
public static boolean doesPlayerHaveArrows(EntityPlayer player) public static boolean doesPlayerHaveArrows(PlayerEntity player)
{ {
for(int i = 0; i < player.inventory.getSizeInventory(); ++i) for(int i = 0; i < player.inventory.getSizeInventory(); ++i)
{ {
if(player.inventory.getStackInSlot(i).getItem() instanceof ItemArrow) if(player.inventory.getStackInSlot(i).getItem() instanceof ArrowItem)
{ {
return true; return true;
} }

View file

@ -1,16 +1,16 @@
package com.seodisparate.TurnBasedMinecraft.common.networking; package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier;
import com.seodisparate.TurnBasedMinecraft.common.Battle; import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.seodisparate.TurnBasedMinecraft.common.Battle.Decision; import com.seodisparate.TurnBasedMinecraft.common.Battle.Decision;
import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class PacketBattleDecision implements IMessage public class PacketBattleDecision
{ {
private int battleID; private int battleID;
private Battle.Decision decision; private Battle.Decision decision;
@ -25,34 +25,27 @@ public class PacketBattleDecision implements IMessage
this.targetIDOrItemID = targetIDOrItemID; this.targetIDOrItemID = targetIDOrItemID;
} }
@Override public static void encode(PacketBattleDecision pkt, PacketBuffer buf) {
public void fromBytes(ByteBuf buf) buf.writeInt(pkt.battleID);
{ buf.writeInt(pkt.decision.getValue());
battleID = buf.readInt(); buf.writeInt(pkt.targetIDOrItemID);
decision = Decision.valueOf(buf.readInt());
targetIDOrItemID = buf.readInt();
} }
@Override public static PacketBattleDecision decode(PacketBuffer buf) {
public void toBytes(ByteBuf buf) return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
{
buf.writeInt(battleID);
buf.writeInt(decision.getValue());
buf.writeInt(targetIDOrItemID);
} }
public static class HandleBattleDecision implements IMessageHandler<PacketBattleDecision, IMessage> public static class Handler {
{ public static void handle(final PacketBattleDecision pkt, Supplier<NetworkEvent.Context> ctx) {
@Override ctx.get().enqueueWork(() -> {
public IMessage onMessage(PacketBattleDecision message, MessageContext ctx) Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
{
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID);
if(b != null) if(b != null)
{ {
EntityPlayerMP player = ctx.getServerHandler().player; ServerPlayerEntity player = ctx.get().getSender();
b.setDecision(player.getEntityId(), message.decision, message.targetIDOrItemID); b.setDecision(player.getEntityId(), pkt.decision, pkt.targetIDOrItemID);
} }
return null; });
ctx.get().setPacketHandled(true);
} }
} }
} }

View file

@ -2,17 +2,16 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.function.Supplier;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class PacketBattleInfo implements IMessage public class PacketBattleInfo
{ {
private Collection<Integer> sideA; private Collection<Integer> sideA;
private Collection<Integer> sideB; private Collection<Integer> sideB;
@ -32,67 +31,61 @@ public class PacketBattleInfo implements IMessage
this.decisionNanos = decisionNanos; this.decisionNanos = decisionNanos;
} }
@Override public static void encode(PacketBattleInfo pkt, PacketBuffer buf) {
public void fromBytes(ByteBuf buf) buf.writeInt(pkt.sideA.size());
{ buf.writeInt(pkt.sideB.size());
for(Integer id : pkt.sideA) {
buf.writeInt(id);
}
for(Integer id : pkt.sideB) {
buf.writeInt(id);
}
buf.writeLong(pkt.decisionNanos);
}
public static PacketBattleInfo decode(PacketBuffer buf) {
int sideACount = buf.readInt(); int sideACount = buf.readInt();
int sideBCount = buf.readInt(); int sideBCount = buf.readInt();
for(int i = 0; i < sideACount; ++i) Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
{ Collection<Integer> sideB = new ArrayList<Integer>(sideBCount);
for(int i = 0; i < sideACount; ++i) {
sideA.add(buf.readInt()); sideA.add(buf.readInt());
} }
for(int i = 0; i < sideBCount; ++i) for(int i = 0; i < sideBCount; ++i) {
{
sideB.add(buf.readInt()); sideB.add(buf.readInt());
} }
decisionNanos = buf.readLong(); long decisionNanos = buf.readLong();
return new PacketBattleInfo(sideA, sideB, decisionNanos);
} }
@Override public static class Handler {
public void toBytes(ByteBuf buf) public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
{ ctx.get().enqueueWork(() -> {
buf.writeInt(sideA.size());
buf.writeInt(sideB.size());
for(Integer id : sideA)
{
buf.writeInt(id);
}
for(Integer id : sideB)
{
buf.writeInt(id);
}
buf.writeLong(decisionNanos);
}
public static class HandlerBattleInfo implements IMessageHandler<PacketBattleInfo, IMessage>
{
@Override
public IMessage onMessage(PacketBattleInfo message, MessageContext ctx)
{
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null) if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{ {
return null; return;
} }
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants(); TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : message.sideA) for(Integer id : pkt.sideA)
{ {
Entity e = Minecraft.getMinecraft().world.getEntityByID(id); Entity e = Minecraft.getInstance().world.getEntityByID(id);
if(e != null) if(e != null)
{ {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e); TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
} }
} }
for(Integer id : message.sideB) for(Integer id : pkt.sideB)
{ {
Entity e = Minecraft.getMinecraft().world.getEntityByID(id); Entity e = Minecraft.getInstance().world.getEntityByID(id);
if(e != null) if(e != null)
{ {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e); TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
} }
} }
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L)); TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
return null; });
ctx.get().setPacketHandled(true);
} }
} }
} }

View file

@ -2,19 +2,15 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.PacketBuffer;
import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class PacketBattleMessage implements IMessage public class PacketBattleMessage
{ {
public enum MessageType public enum MessageType
{ {
@ -125,120 +121,72 @@ public class PacketBattleMessage implements IMessage
this.custom = custom; this.custom = custom;
} }
@Override public static void encode(PacketBattleMessage pkt, PacketBuffer buf) {
public void fromBytes(ByteBuf buf) buf.writeInt(pkt.messageType.getValue());
{ buf.writeInt(pkt.entityIDFrom);
messageType = MessageType.valueOf(buf.readInt()); buf.writeInt(pkt.entityIDTo);
entityIDFrom = buf.readInt(); buf.writeInt(pkt.amount);
entityIDTo = buf.readInt(); buf.writeString(pkt.custom);
amount = buf.readInt();
custom = ByteBufUtils.readUTF8String(buf);
} }
@Override public static PacketBattleMessage decode(PacketBuffer buf) {
public void toBytes(ByteBuf buf) return new PacketBattleMessage(
{ MessageType.valueOf(
buf.writeInt(messageType.getValue()); buf.readInt()),
buf.writeInt(entityIDFrom); buf.readInt(),
buf.writeInt(entityIDTo); buf.readInt(),
buf.writeInt(amount); buf.readInt(),
ByteBufUtils.writeUTF8String(buf, custom); buf.readString());
} }
public static class HandlerBattleMessage implements IMessageHandler<PacketBattleMessage, IMessage> public static class Handler {
{ public static void handle(final PacketBattleMessage pkt, Supplier<NetworkEvent.Context> ctx) {
@Override ctx.get().enqueueWork(() -> {
public IMessage onMessage(PacketBattleMessage message, MessageContext ctx) Entity fromEntity = TurnBasedMinecraftMod.proxy.getEntityByID(pkt.entityIDFrom);
{
Entity fromEntity = TurnBasedMinecraftMod.proxy.getEntityByID(message.entityIDFrom);
String from = "Unknown"; String from = "Unknown";
if(fromEntity != null) if(fromEntity != null)
{ {
if(fromEntity.hasCustomName()) from = fromEntity.getDisplayName().getFormattedText();
{
from = fromEntity.getCustomNameTag();
}
else if(fromEntity instanceof EntityPlayer)
{
from = ScorePlayerTeam.formatPlayerName(fromEntity.getTeam(), fromEntity.getName());
}
else
{
from = fromEntity.getName();
}
} }
else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null) else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{ {
fromEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(message.entityIDFrom); fromEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(pkt.entityIDFrom);
if(fromEntity != null) if(fromEntity != null)
{ {
if(fromEntity.hasCustomName()) from = fromEntity.getDisplayName().getFormattedText();
{
from = fromEntity.getCustomNameTag();
}
else if(fromEntity instanceof EntityPlayer)
{
from = ScorePlayerTeam.formatPlayerName(fromEntity.getTeam(), fromEntity.getName());
}
else
{
from = fromEntity.getName();
} }
} }
} Entity toEntity = TurnBasedMinecraftMod.proxy.getEntityByID(pkt.entityIDTo);
Entity toEntity = TurnBasedMinecraftMod.proxy.getEntityByID(message.entityIDTo);
String to = "Unknown"; String to = "Unknown";
if(toEntity != null) if(toEntity != null)
{ {
if(toEntity.hasCustomName()) to = toEntity.getDisplayName().getFormattedText();
{
to = toEntity.getCustomNameTag();
}
else if(toEntity instanceof EntityPlayer)
{
to = ScorePlayerTeam.formatPlayerName(toEntity.getTeam(), toEntity.getName());
}
else
{
to = toEntity.getName();
}
} }
else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null) else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{ {
toEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(message.entityIDTo); toEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(pkt.entityIDTo);
if(toEntity != null) if(toEntity != null)
{ {
if(toEntity.hasCustomName()) to = toEntity.getDisplayName().getFormattedText();
{
to = toEntity.getCustomNameTag();
}
else if(toEntity instanceof EntityPlayer)
{
to = ScorePlayerTeam.formatPlayerName(toEntity.getTeam(), toEntity.getName());
}
else
{
to = toEntity.getName();
}
} }
} }
switch(message.messageType) switch(pkt.messageType)
{ {
case ENTERED: case ENTERED:
TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!"); TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!");
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != message.amount) if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != pkt.amount)
{ {
TurnBasedMinecraftMod.proxy.createLocalBattle(message.amount); TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.amount);
} }
TurnBasedMinecraftMod.proxy.battleStarted(); TurnBasedMinecraftMod.proxy.battleStarted();
TurnBasedMinecraftMod.proxy.typeEnteredBattle(message.custom); TurnBasedMinecraftMod.proxy.typeEnteredBattle(pkt.custom);
break; break;
case FLEE: case FLEE:
if(message.amount != 0) if(pkt.amount != 0)
{ {
TurnBasedMinecraftMod.proxy.displayString(from + " fled battle!"); TurnBasedMinecraftMod.proxy.displayString(from + " fled battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(message.custom); TurnBasedMinecraftMod.proxy.typeLeftBattle(pkt.custom);
} }
else else
{ {
@ -247,20 +195,20 @@ public class PacketBattleMessage implements IMessage
break; break;
case DIED: case DIED:
TurnBasedMinecraftMod.proxy.displayString(from + " died in battle!"); TurnBasedMinecraftMod.proxy.displayString(from + " died in battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(message.custom); TurnBasedMinecraftMod.proxy.typeLeftBattle(pkt.custom);
break; break;
case ENDED: case ENDED:
TurnBasedMinecraftMod.proxy.displayString("Battle has ended!"); TurnBasedMinecraftMod.proxy.displayString("Battle has ended!");
TurnBasedMinecraftMod.proxy.battleEnded(); TurnBasedMinecraftMod.proxy.battleEnded();
break; break;
case ATTACK: case ATTACK:
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " and dealt " + message.amount + " damage!"); TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " and dealt " + pkt.amount + " damage!");
break; break;
case DEFEND: case DEFEND:
TurnBasedMinecraftMod.proxy.displayString(from + " blocked " + to + "'s attack!"); TurnBasedMinecraftMod.proxy.displayString(from + " blocked " + to + "'s attack!");
break; break;
case DEFENSE_DAMAGE: case DEFENSE_DAMAGE:
TurnBasedMinecraftMod.proxy.displayString(from + " retaliated from " + to + "'s attack and dealt " + message.amount + " damage!"); TurnBasedMinecraftMod.proxy.displayString(from + " retaliated from " + to + "'s attack and dealt " + pkt.amount + " damage!");
break; break;
case MISS: case MISS:
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " but missed!"); TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " but missed!");
@ -272,15 +220,15 @@ public class PacketBattleMessage implements IMessage
TurnBasedMinecraftMod.proxy.displayString(from + " did nothing!"); TurnBasedMinecraftMod.proxy.displayString(from + " did nothing!");
break; break;
case USED_ITEM: case USED_ITEM:
switch(UsedItemAction.valueOf(message.amount)) switch(UsedItemAction.valueOf(pkt.amount))
{ {
case USED_NOTHING: case USED_NOTHING:
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use nothing!"); TurnBasedMinecraftMod.proxy.displayString(from + " tried to use nothing!");
break; break;
case USED_INVALID: case USED_INVALID:
if(message.custom.length() > 0) if(pkt.custom.length() > 0)
{ {
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume " + message.custom + " and failed!"); TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume " + pkt.custom + " and failed!");
} }
else else
{ {
@ -288,10 +236,10 @@ public class PacketBattleMessage implements IMessage
} }
break; break;
case USED_FOOD: case USED_FOOD:
TurnBasedMinecraftMod.proxy.displayString(from + " ate a " + message.custom + "!"); TurnBasedMinecraftMod.proxy.displayString(from + " ate a " + pkt.custom + "!");
break; break;
case USED_POTION: case USED_POTION:
TurnBasedMinecraftMod.proxy.displayString(from + " drank a " + message.custom + "!"); TurnBasedMinecraftMod.proxy.displayString(from + " drank a " + pkt.custom + "!");
break; break;
} }
break; break;
@ -302,7 +250,7 @@ public class PacketBattleMessage implements IMessage
case TURN_END: case TURN_END:
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null) if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{ {
if(message.amount == 0) if(pkt.amount == 0)
{ {
TurnBasedMinecraftMod.proxy.displayString("The turn ended!"); TurnBasedMinecraftMod.proxy.displayString("The turn ended!");
} }
@ -314,7 +262,7 @@ public class PacketBattleMessage implements IMessage
TurnBasedMinecraftMod.proxy.battleGuiTurnEnd(); TurnBasedMinecraftMod.proxy.battleGuiTurnEnd();
break; break;
case SWITCHED_ITEM: case SWITCHED_ITEM:
if(message.amount != 0) if(pkt.amount != 0)
{ {
TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item!"); TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item!");
} }
@ -324,7 +272,7 @@ public class PacketBattleMessage implements IMessage
} }
break; break;
case WAS_AFFECTED: case WAS_AFFECTED:
TurnBasedMinecraftMod.proxy.displayString(to + " was " + message.custom + " by " + from + "!"); TurnBasedMinecraftMod.proxy.displayString(to + " was " + pkt.custom + " by " + from + "!");
break; break;
case BECAME_CREATIVE: case BECAME_CREATIVE:
TurnBasedMinecraftMod.proxy.displayString(from + " entered creative mode and left battle!"); TurnBasedMinecraftMod.proxy.displayString(from + " entered creative mode and left battle!");
@ -339,7 +287,8 @@ public class PacketBattleMessage implements IMessage
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use their bow but ran out of ammo!"); TurnBasedMinecraftMod.proxy.displayString(from + " tried to use their bow but ran out of ammo!");
break; break;
} }
return null; });
ctx.get().setPacketHandled(true);
} }
} }
} }

View file

@ -1,14 +1,15 @@
package com.seodisparate.TurnBasedMinecraft.common.networking; package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier;
import com.seodisparate.TurnBasedMinecraft.common.Battle; import com.seodisparate.TurnBasedMinecraft.common.Battle;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class PacketBattleRequestInfo implements IMessage public class PacketBattleRequestInfo
{ {
private int battleID; private int battleID;
@ -19,29 +20,24 @@ public class PacketBattleRequestInfo implements IMessage
this.battleID = battleID; this.battleID = battleID;
} }
@Override public static void encode(PacketBattleRequestInfo pkt, PacketBuffer buf) {
public void fromBytes(ByteBuf buf) buf.writeInt(pkt.battleID);
{
battleID = buf.readInt();
} }
@Override public static PacketBattleRequestInfo decode(PacketBuffer buf) {
public void toBytes(ByteBuf buf) return new PacketBattleRequestInfo(buf.readInt());
{
buf.writeInt(battleID);
} }
public static class HandlerBattleRequestInfo implements IMessageHandler<PacketBattleRequestInfo, PacketBattleInfo> public static class Handler {
{ public static void handle(final PacketBattleRequestInfo pkt, Supplier<NetworkEvent.Context> ctx) {
@Override ctx.get().enqueueWork(() -> {
public PacketBattleInfo onMessage(PacketBattleRequestInfo message, MessageContext ctx) Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
{ if(b == null) {
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID); return;
if(b == null)
{
return null;
} }
return new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()); TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()), ctx.get());
});
ctx.get().setPacketHandled(true);
} }
} }
} }

View file

@ -2,21 +2,19 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
import com.seodisparate.TurnBasedMinecraft.common.EntityInfo; import com.seodisparate.TurnBasedMinecraft.common.EntityInfo;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent; import net.minecraft.util.text.event.HoverEvent;
import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
public class PacketEditingMessage implements IMessage public class PacketEditingMessage
{ {
public enum Type public enum Type
{ {
@ -84,76 +82,67 @@ public class PacketEditingMessage implements IMessage
} }
} }
@Override public static void encode(PacketEditingMessage pkt, PacketBuffer buf) {
public void fromBytes(ByteBuf buf) buf.writeInt(pkt.type.getValue());
{ if(pkt.entityInfo.classType != null) {
type = Type.valueOf(buf.readInt()); buf.writeString(pkt.entityInfo.classType.getName());
try } else {
{ buf.writeString("unknown");
entityInfo.classType = getClass().getClassLoader().loadClass(ByteBufUtils.readUTF8String(buf));
} }
catch (ClassNotFoundException e) { /* ignored */ } buf.writeBoolean(pkt.entityInfo.ignoreBattle);
entityInfo.ignoreBattle = buf.readBoolean(); buf.writeInt(pkt.entityInfo.attackPower);
entityInfo.attackPower = buf.readInt(); buf.writeInt(pkt.entityInfo.attackProbability);
entityInfo.attackProbability = buf.readInt(); buf.writeInt(pkt.entityInfo.attackVariance);
entityInfo.attackVariance = buf.readInt(); buf.writeString(pkt.entityInfo.attackEffect.toString());
entityInfo.attackEffect = EntityInfo.Effect.fromString(ByteBufUtils.readUTF8String(buf)); buf.writeInt(pkt.entityInfo.attackEffectProbability);
entityInfo.attackEffectProbability = buf.readInt(); buf.writeInt(pkt.entityInfo.defenseDamage);
entityInfo.defenseDamage = buf.readInt(); buf.writeInt(pkt.entityInfo.defenseDamageProbability);
entityInfo.defenseDamageProbability = buf.readInt(); buf.writeInt(pkt.entityInfo.evasion);
entityInfo.evasion = buf.readInt(); buf.writeInt(pkt.entityInfo.speed);
entityInfo.speed = buf.readInt(); buf.writeString(pkt.entityInfo.category);
entityInfo.category = ByteBufUtils.readUTF8String(buf); buf.writeInt(pkt.entityInfo.decisionAttack);
entityInfo.decisionAttack = buf.readInt(); buf.writeInt(pkt.entityInfo.decisionDefend);
entityInfo.decisionDefend = buf.readInt(); buf.writeInt(pkt.entityInfo.decisionFlee);
entityInfo.decisionFlee = buf.readInt(); buf.writeString(pkt.entityInfo.customName);
entityInfo.customName = ByteBufUtils.readUTF8String(buf);
} }
@Override public static PacketEditingMessage decode(PacketBuffer buf) {
public void toBytes(ByteBuf buf) Type type = Type.valueOf(buf.readInt());
{ EntityInfo einfo = new EntityInfo();
buf.writeInt(type.getValue()); try {
if(entityInfo.classType != null) einfo.classType = einfo.getClass().getClassLoader().loadClass(buf.readString());
{ } catch (ClassNotFoundException e) { /* ignored */ }
ByteBufUtils.writeUTF8String(buf, entityInfo.classType.getName()); einfo.ignoreBattle = buf.readBoolean();
} einfo.attackPower = buf.readInt();
else einfo.attackProbability = buf.readInt();
{ einfo.attackVariance = buf.readInt();
ByteBufUtils.writeUTF8String(buf, "unknown"); einfo.attackEffect = EntityInfo.Effect.fromString(buf.readString());
} einfo.attackEffectProbability = buf.readInt();
buf.writeBoolean(entityInfo.ignoreBattle); einfo.defenseDamage = buf.readInt();
buf.writeInt(entityInfo.attackPower); einfo.defenseDamageProbability = buf.readInt();
buf.writeInt(entityInfo.attackProbability); einfo.evasion = buf.readInt();
buf.writeInt(entityInfo.attackVariance); einfo.speed = buf.readInt();
ByteBufUtils.writeUTF8String(buf, entityInfo.attackEffect.toString()); einfo.category = buf.readString();
buf.writeInt(entityInfo.attackEffectProbability); einfo.decisionAttack = buf.readInt();
buf.writeInt(entityInfo.defenseDamage); einfo.decisionDefend = buf.readInt();
buf.writeInt(entityInfo.defenseDamageProbability); einfo.decisionFlee = buf.readInt();
buf.writeInt(entityInfo.evasion); einfo.customName = buf.readString();
buf.writeInt(entityInfo.speed); return new PacketEditingMessage(type, einfo);
ByteBufUtils.writeUTF8String(buf, entityInfo.category);
buf.writeInt(entityInfo.decisionAttack);
buf.writeInt(entityInfo.decisionDefend);
buf.writeInt(entityInfo.decisionFlee);
ByteBufUtils.writeUTF8String(buf, entityInfo.customName);
} }
public static class HandlerEditingMessage implements IMessageHandler<PacketEditingMessage, IMessage> public static class Handler {
{ public static void handle(final PacketEditingMessage pkt, Supplier<NetworkEvent.Context> ctx) {
@Override ctx.get().enqueueWork(() -> {
public IMessage onMessage(PacketEditingMessage message, MessageContext ctx) switch(pkt.type)
{
switch(message.type)
{ {
case ATTACK_ENTITY: case ATTACK_ENTITY:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("Attack the entity you want to edit for TurnBasedMinecraftMod. "); ITextComponent text = new StringTextComponent("Attack the entity you want to edit for TurnBasedMinecraftMod. ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
ITextComponent cancel = new TextComponentString("Cancel"); ITextComponent cancel = new StringTextComponent("Cancel");
cancel.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit cancel")); cancel.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit cancel"));
text.appendSibling(cancel); text.appendSibling(cancel);
@ -163,128 +152,128 @@ public class PacketEditingMessage implements IMessage
} }
case PICK_EDIT: case PICK_EDIT:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("Edit what value? "); ITextComponent text = new StringTextComponent("Edit what value? ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
ITextComponent option = new TextComponentString("IgB"); ITextComponent option = new StringTextComponent("IgB");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("IgnoreBattle"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("IgnoreBattle")));
ITextComponent value = new TextComponentString("(" + message.entityInfo.ignoreBattle + ") "); ITextComponent value = new StringTextComponent("(" + pkt.entityInfo.ignoreBattle + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("AP"); option = new StringTextComponent("AP");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackPower")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackPower"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("AttackPower"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("AttackPower")));
value = new TextComponentString("(" + message.entityInfo.attackPower + ") "); value = new StringTextComponent("(" + pkt.entityInfo.attackPower + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("APr"); option = new StringTextComponent("APr");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackProbability")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackProbability"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("AttackProbability"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("AttackProbability")));
value = new TextComponentString("(" + message.entityInfo.attackProbability + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.attackProbability + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("AV"); option = new StringTextComponent("AV");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackVariance")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackVariance"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("AttackVariance"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("AttackVariance")));
value = new TextComponentString("(" + message.entityInfo.attackVariance + ") "); value = new StringTextComponent("(" + pkt.entityInfo.attackVariance + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("AE"); option = new StringTextComponent("AE");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("AttackEffect"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("AttackEffect")));
value = new TextComponentString("(" + message.entityInfo.attackEffect.toString() + ") "); value = new StringTextComponent("(" + pkt.entityInfo.attackEffect.toString() + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("AEPr"); option = new StringTextComponent("AEPr");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("AttackEffectProbability"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("AttackEffectProbability")));
value = new TextComponentString("(" + message.entityInfo.attackEffectProbability + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.attackEffectProbability + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("DD"); option = new StringTextComponent("DD");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamage")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamage"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("DefenseDamage"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("DefenseDamage")));
value = new TextComponentString("(" + message.entityInfo.defenseDamage + ") "); value = new StringTextComponent("(" + pkt.entityInfo.defenseDamage + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("DDPr"); option = new StringTextComponent("DDPr");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamageProbability")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamageProbability"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("DefenseDamageProbability"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("DefenseDamageProbability")));
value = new TextComponentString("(" + message.entityInfo.defenseDamageProbability + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.defenseDamageProbability + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("E"); option = new StringTextComponent("E");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Evasion"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("Evasion")));
value = new TextComponentString("(" + message.entityInfo.evasion + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.evasion + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("S"); option = new StringTextComponent("S");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit speed")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit speed"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Speed"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("Speed")));
value = new TextComponentString("(" + message.entityInfo.speed + ") "); value = new StringTextComponent("(" + pkt.entityInfo.speed + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("C"); option = new StringTextComponent("C");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Category"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("Category")));
value = new TextComponentString("(" + message.entityInfo.category + ") "); value = new StringTextComponent("(" + pkt.entityInfo.category + ") ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("DecA"); option = new StringTextComponent("DecA");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionAttack")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionAttack"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("DecisionAttack"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("DecisionAttack")));
value = new TextComponentString("(" + message.entityInfo.decisionAttack + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.decisionAttack + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("DecD"); option = new StringTextComponent("DecD");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionDefend")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionDefend"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("DecisionDefend"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("DecisionDefend")));
value = new TextComponentString("(" + message.entityInfo.decisionDefend + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.decisionDefend + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("DecF"); option = new StringTextComponent("DecF");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionFlee")) option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionFlee"))
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("DecisionFlee"))); .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent("DecisionFlee")));
value = new TextComponentString("(" + message.entityInfo.decisionFlee + "%) "); value = new StringTextComponent("(" + pkt.entityInfo.decisionFlee + "%) ");
value.getStyle().setColor(TextFormatting.WHITE); value.getStyle().setColor(TextFormatting.WHITE);
option.appendSibling(value); option.appendSibling(value);
text.appendSibling(option); text.appendSibling(option);
option = new TextComponentString("Finished Editing"); option = new StringTextComponent("Finished Editing");
option.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit finish")); option.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit finish"));
text.appendSibling(option).appendText(" "); text.appendSibling(option).appendText(" ");
option = new TextComponentString("Cancel"); option = new StringTextComponent("Cancel");
option.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit cancel")); option.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit cancel"));
text.appendSibling(option); text.appendSibling(option);
@ -294,18 +283,18 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_IGNORE_BATTLE: case EDIT_IGNORE_BATTLE:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("ignoreBattle: "); ITextComponent text = new StringTextComponent("ignoreBattle: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
ITextComponent option = new TextComponentString("true"); ITextComponent option = new StringTextComponent("true");
option.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle true")); option.getStyle().setColor(TextFormatting.GREEN).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle true"));
text.appendSibling(option); text.appendSibling(option);
text.appendText(" "); text.appendText(" ");
option = new TextComponentString("false"); option = new StringTextComponent("false");
option.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle false")); option.getStyle().setColor(TextFormatting.RED).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle false"));
text.appendSibling(option); text.appendSibling(option);
@ -315,14 +304,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_ATTACK_POWER: case EDIT_ATTACK_POWER:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("attackPower: "); ITextComponent text = new StringTextComponent("attackPower: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 15; ++i) for(int i = 0; i <= 15; ++i)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i)); ITextComponent option = new StringTextComponent(Integer.toString(i));
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackPower " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackPower " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 15) if(i < 15)
@ -339,14 +328,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_ATTACK_PROBABILITY: case EDIT_ATTACK_PROBABILITY:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("attackProbability: "); ITextComponent text = new StringTextComponent("attackProbability: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 10; i <= 100; i += 10) for(int i = 10; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackProbability " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackProbability " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -363,14 +352,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_ATTACK_VARIANCE: case EDIT_ATTACK_VARIANCE:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("attackVariance: "); ITextComponent text = new StringTextComponent("attackVariance: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 10; ++i) for(int i = 0; i <= 10; ++i)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i)); ITextComponent option = new StringTextComponent(Integer.toString(i));
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackVariance " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackVariance " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 10) if(i < 10)
@ -387,14 +376,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_ATTACK_EFFECT: case EDIT_ATTACK_EFFECT:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("attackEffect: "); ITextComponent text = new StringTextComponent("attackEffect: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(EntityInfo.Effect e : EntityInfo.Effect.values()) for(EntityInfo.Effect e : EntityInfo.Effect.values())
{ {
ITextComponent option = new TextComponentString(e.toString()); ITextComponent option = new StringTextComponent(e.toString());
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect " + e.toString())); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect " + e.toString()));
text.appendSibling(option); text.appendSibling(option);
if(e != EntityInfo.Effect.UNKNOWN) if(e != EntityInfo.Effect.UNKNOWN)
@ -410,14 +399,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_ATTACK_EFFECT_PROBABILITY: case EDIT_ATTACK_EFFECT_PROBABILITY:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("attackEffectProbability: "); ITextComponent text = new StringTextComponent("attackEffectProbability: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -434,14 +423,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_DEFENSE_DAMAGE: case EDIT_DEFENSE_DAMAGE:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("defenseDamage: "); ITextComponent text = new StringTextComponent("defenseDamage: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 15; ++i) for(int i = 0; i <= 15; ++i)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i)); ITextComponent option = new StringTextComponent(Integer.toString(i));
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamage " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamage " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 15) if(i < 15)
@ -458,14 +447,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_DEFENSE_DAMAGE_PROBABILITY: case EDIT_DEFENSE_DAMAGE_PROBABILITY:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("defenseDamageProbability: "); ITextComponent text = new StringTextComponent("defenseDamageProbability: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamageProbability " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamageProbability " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -482,14 +471,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_EVASION: case EDIT_EVASION:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("evasion: "); ITextComponent text = new StringTextComponent("evasion: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -506,14 +495,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_SPEED: case EDIT_SPEED:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("speed: "); ITextComponent text = new StringTextComponent("speed: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i)); ITextComponent option = new StringTextComponent(Integer.toString(i));
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit speed " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit speed " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -530,115 +519,115 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_CATEGORY: case EDIT_CATEGORY:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("category: "); ITextComponent text = new StringTextComponent("category: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
ITextComponent option = new TextComponentString("monster"); ITextComponent option = new StringTextComponent("monster");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category monster")); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category monster"));
if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("monster")) if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("monster"))
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("disabled"); ITextComponent optionInfoBool = new StringTextComponent("disabled");
optionInfoBool.getStyle().setColor(TextFormatting.RED); optionInfoBool.getStyle().setColor(TextFormatting.RED);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
else else
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("enabled"); ITextComponent optionInfoBool = new StringTextComponent("enabled");
optionInfoBool.getStyle().setColor(TextFormatting.GREEN); optionInfoBool.getStyle().setColor(TextFormatting.GREEN);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
text.appendSibling(option).appendText(", "); text.appendSibling(option).appendText(", ");
option = new TextComponentString("animal"); option = new StringTextComponent("animal");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category animal")); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category animal"));
if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("animal")) if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("animal"))
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("disabled"); ITextComponent optionInfoBool = new StringTextComponent("disabled");
optionInfoBool.getStyle().setColor(TextFormatting.RED); optionInfoBool.getStyle().setColor(TextFormatting.RED);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
else else
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("enabled"); ITextComponent optionInfoBool = new StringTextComponent("enabled");
optionInfoBool.getStyle().setColor(TextFormatting.GREEN); optionInfoBool.getStyle().setColor(TextFormatting.GREEN);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
text.appendSibling(option).appendText(", "); text.appendSibling(option).appendText(", ");
option = new TextComponentString("passive"); option = new StringTextComponent("passive");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category passive")); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category passive"));
if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("passive")) if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("passive"))
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("disabled"); ITextComponent optionInfoBool = new StringTextComponent("disabled");
optionInfoBool.getStyle().setColor(TextFormatting.RED); optionInfoBool.getStyle().setColor(TextFormatting.RED);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
else else
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("enabled"); ITextComponent optionInfoBool = new StringTextComponent("enabled");
optionInfoBool.getStyle().setColor(TextFormatting.GREEN); optionInfoBool.getStyle().setColor(TextFormatting.GREEN);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
text.appendSibling(option).appendText(", "); text.appendSibling(option).appendText(", ");
option = new TextComponentString("boss"); option = new StringTextComponent("boss");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category boss")); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category boss"));
if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("boss")) if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("boss"))
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("disabled"); ITextComponent optionInfoBool = new StringTextComponent("disabled");
optionInfoBool.getStyle().setColor(TextFormatting.RED); optionInfoBool.getStyle().setColor(TextFormatting.RED);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
else else
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("enabled"); ITextComponent optionInfoBool = new StringTextComponent("enabled");
optionInfoBool.getStyle().setColor(TextFormatting.GREEN); optionInfoBool.getStyle().setColor(TextFormatting.GREEN);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
text.appendSibling(option).appendText(", "); text.appendSibling(option).appendText(", ");
option = new TextComponentString("player"); option = new StringTextComponent("player");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category player")); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category player"));
if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("player")) if(TurnBasedMinecraftMod.proxy.getConfig().isIgnoreBattleType("player"))
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("disabled"); ITextComponent optionInfoBool = new StringTextComponent("disabled");
optionInfoBool.getStyle().setColor(TextFormatting.RED); optionInfoBool.getStyle().setColor(TextFormatting.RED);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
} }
else else
{ {
ITextComponent optionInfo = new TextComponentString("(battle-"); ITextComponent optionInfo = new StringTextComponent("(battle-");
optionInfo.getStyle().setColor(TextFormatting.WHITE); optionInfo.getStyle().setColor(TextFormatting.WHITE);
ITextComponent optionInfoBool = new TextComponentString("enabled"); ITextComponent optionInfoBool = new StringTextComponent("enabled");
optionInfoBool.getStyle().setColor(TextFormatting.GREEN); optionInfoBool.getStyle().setColor(TextFormatting.GREEN);
optionInfo.appendSibling(optionInfoBool).appendText(")"); optionInfo.appendSibling(optionInfoBool).appendText(")");
option.appendSibling(optionInfo); option.appendSibling(optionInfo);
@ -653,14 +642,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_DECISION_ATTACK: case EDIT_DECISION_ATTACK:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("decisionAttack: "); ITextComponent text = new StringTextComponent("decisionAttack: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionAttack " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionAttack " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -675,14 +664,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_DECISION_DEFEND: case EDIT_DECISION_DEFEND:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("decisionDefend: "); ITextComponent text = new StringTextComponent("decisionDefend: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionDefend " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionDefend " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -697,14 +686,14 @@ public class PacketEditingMessage implements IMessage
} }
case EDIT_DECISION_FLEE: case EDIT_DECISION_FLEE:
{ {
ITextComponent prefix = new TextComponentString("TBM: "); ITextComponent prefix = new StringTextComponent("TBM: ");
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true); prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
ITextComponent text = new TextComponentString("decisionFlee: "); ITextComponent text = new StringTextComponent("decisionFlee: ");
text.getStyle().setColor(TextFormatting.WHITE).setBold(false); text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
for(int i = 0; i <= 100; i += 10) for(int i = 0; i <= 100; i += 10)
{ {
ITextComponent option = new TextComponentString(Integer.toString(i) + "%"); ITextComponent option = new StringTextComponent(Integer.toString(i) + "%");
option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionFlee " + Integer.toString(i))); option.getStyle().setColor(TextFormatting.YELLOW).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit decisionFlee " + Integer.toString(i)));
text.appendSibling(option); text.appendSibling(option);
if(i < 100) if(i < 100)
@ -720,7 +709,8 @@ public class PacketEditingMessage implements IMessage
default: default:
break; break;
} }
return null; });
ctx.get().setPacketHandled(true);
} }
} }
} }

View file

@ -1,14 +1,13 @@
package com.seodisparate.TurnBasedMinecraft.common.networking; package com.seodisparate.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import io.netty.buffer.ByteBuf; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class PacketGeneralMessage implements IMessage public class PacketGeneralMessage
{ {
String message; String message;
@ -22,25 +21,20 @@ public class PacketGeneralMessage implements IMessage
this.message = message; this.message = message;
} }
@Override public static void encode(PacketGeneralMessage pkt, PacketBuffer buf) {
public void fromBytes(ByteBuf buf) buf.writeString(pkt.message);
{
message = ByteBufUtils.readUTF8String(buf);
} }
@Override public static PacketGeneralMessage decode(PacketBuffer buf) {
public void toBytes(ByteBuf buf) return new PacketGeneralMessage(buf.readString());
{
ByteBufUtils.writeUTF8String(buf, message);
} }
public static class HandlerGeneralMessage implements IMessageHandler<PacketGeneralMessage, IMessage> public static class Handler {
{ public static void handle(final PacketGeneralMessage pkt, Supplier<NetworkEvent.Context> ctx) {
@Override ctx.get().enqueueWork(() -> {
public IMessage onMessage(PacketGeneralMessage message, MessageContext ctx) TurnBasedMinecraftMod.proxy.displayString(pkt.message);
{ });
TurnBasedMinecraftMod.proxy.displayString(message.message); ctx.get().setPacketHandled(true);
return null;
} }
} }
} }

View file

@ -1,11 +0,0 @@
package com.seodisparate.TurnBasedMinecraft.common.networking;
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
public class PacketHandler
{
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(TurnBasedMinecraftMod.MODID);
}

View file

@ -0,0 +1 @@
Maven-Artifact: fr.delthas:javamp3:1.0.3

View file

@ -1,12 +1,12 @@
# 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 = 1 version = 2
[client_config] [client_config]
# determines what categories use what type of music. # What categories play this type of music (battle_music). Unknown categories will default to this type.
# Unknown categories sent by the server will default to "battle_music".
battle_music = ["monster", "animal", "boss", "player"] battle_music = ["monster", "animal", "boss", "player"]
# What categories play this type of music (silly_music).
silly_music = ["passive"] silly_music = ["passive"]
# Minimum percentage of silly entities in battle to use silly music. # Minimum percentage of silly entities in battle to use silly music.
@ -41,19 +41,23 @@ freeze_battle_combatants = false
# Entity categories that will not initiate battle. # Entity categories that will not initiate battle.
ignore_battle_types = ["passive", "boss"] ignore_battle_types = ["passive", "boss"]
# Stats that apply to all players # speed stat of all players in battle
player_speed = 50 player_speed = 50
# speed stat of all players under the effects of haste
player_haste_speed = 80 player_haste_speed = 80
# speed stat of all players under the effects of slow
player_slow_speed = 20 player_slow_speed = 20
# attack probability stat for all players
player_attack_probability = 90 player_attack_probability = 90
# evasion stat for all players
player_evasion = 10 player_evasion = 10
# Number of attacks that a "defend" move will block # Number of attacks that a "defend" move will block
defense_duration = 1 defense_duration = 1
# If speed is greater than fastest speed of entity on opposing side, good # probability of fleeing from battle when speed is greater than fastest enemy's speed
# probability is used.
flee_good_probability = 90 flee_good_probability = 90
# probability of fleeing from battle when speed is less than fastest enemy's speed
flee_bad_probability = 40 flee_bad_probability = 40
# Minimum hit percentage for everyone. If option is set to less than 1, # Minimum hit percentage for everyone. If option is set to less than 1,