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,370 +12,334 @@ 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; private MenuState state;
private MenuState state; 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());
} elapsedTime = 0;
timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds()); lastInstant = System.nanoTime();
elapsedTime = 0; setState(MenuState.MAIN_MENU);
lastInstant = System.nanoTime(); }
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) -> {
break; buttonActionEvent(button, ButtonAction.DEFEND);
case ATTACK_TARGET: }));
info = "Who will you attack?"; addButton(new Button(width * 3 / 7 - 25, 60, 50, 20, "Item", (button) -> {
int y = 30; buttonActionEvent(button, ButtonAction.ITEM);
try }));
{ addButton(new Button(width * 4 / 7 - 25, 60, 50, 20, "Flee", (button) -> {
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet()) buttonActionEvent(button, ButtonAction.FLEE);
{ }));
if(e.getValue().entity != null) break;
{ case ATTACK_TARGET:
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), true)); info = "Who will you attack?";
} int y = 30;
else try {
{ for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey(), true)); .getSideAEntrySet()) {
} if (e.getValue().entity != null) {
y += 20; addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), true, (button) -> {
} buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
} catch (ConcurrentModificationException e) }));
{ } else {
// ignored addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, "Unknown", e.getKey(), true, (button) -> {
} buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
y = 30; }));
try }
{ y += 20;
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideBEntrySet()) }
{ } catch (ConcurrentModificationException e) {
if(e.getValue().entity != null) // ignored
{ }
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), false)); y = 30;
} try {
else for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
{ .getSideBEntrySet()) {
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey(), false)); if (e.getValue().entity != null) {
} addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), false, (button) -> {
y += 20; buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
} }));
} catch (ConcurrentModificationException e) } else {
{ addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, "Unknown", e.getKey(), false, (button) -> {
// ignored buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
} }));
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 30, height - 120, 60, 20, "Cancel")); }
break; y += 20;
case ITEM_ACTION: }
info = "What will you do with an item?"; } catch (ConcurrentModificationException e) {
buttonList.add(new GuiButton(ButtonAction.SWITCH_HELD_ITEM.getValue(), width*1/4 - 40, height - 120, 80, 20, "Switch Held")); // ignored
buttonList.add(new GuiButton(ButtonAction.DECIDE_USE_ITEM.getValue(), width*2/4 - 40, height - 120, 80, 20, "Use")); }
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width*3/4 - 40, height - 120, 80, 20, "Cancel")); addButton(new Button(width / 2 - 30, height - 120, 60, 20, "Cancel", (button) -> {
break; buttonActionEvent(button, ButtonAction.CANCEL);
case WAITING: }));
info = "Waiting..."; break;
break; case ITEM_ACTION:
case SWITCH_ITEM: info = "What will you do with an item?";
info = "To which item will you switch to?"; addButton(new Button(width * 1 / 4 - 40, height - 120, 80, 20, "Switch Held", (button) -> {
for(int i = 0; i < 9; ++i) buttonActionEvent(button, ButtonAction.SWITCH_HELD_ITEM);
{ }));
buttonList.add(new ItemSelectionButton(ButtonAction.DO_ITEM_SWITCH.getValue(), width/2 - 88 + i * 20, height - 19, 16, 16, "", i)); addButton(new Button(width * 2 / 4 - 40, height - 120, 80, 20, "Use", (button) -> {
} buttonActionEvent(button, ButtonAction.DECIDE_USE_ITEM);
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel")); }));
break; addButton(new Button(width * 3 / 4 - 40, height - 120, 80, 20, "Cancel", (button) -> {
case USE_ITEM: buttonActionEvent(button, ButtonAction.CANCEL);
info = "Which item will you use?"; }));
for(int i = 0; i < 9; ++i) break;
{ case WAITING:
buttonList.add(new ItemSelectionButton(ButtonAction.DO_USE_ITEM.getValue(), width/2 - 88 + i * 20, height - 19, 16, 16, "", i)); info = "Waiting...";
} break;
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel")); case SWITCH_ITEM:
break; info = "To which item will you switch to?";
} for (int i = 0; i < 9; ++i) {
} addButton(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, "", i, (button) -> {
buttonActionEvent(button, ButtonAction.DO_ITEM_SWITCH);
}));
}
addButton(new Button(width / 2 - 40, height - 120, 80, 20, "Cancel", (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
break;
case USE_ITEM:
info = "Which item will you use?";
for (int i = 0; i < 9; ++i) {
addButton(new ItemSelectionButton(width / 2 - 88 + i * 20, height - 19, 16, 16, "", i, (button) -> {
buttonActionEvent(button, ButtonAction.DO_USE_ITEM);
}));
}
addButton(new Button(width / 2 - 40, height - 120, 80, 20, "Cancel", (button) -> {
buttonActionEvent(button, ButtonAction.CANCEL);
}));
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
if(TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION && timeRemaining.get() > 0) && 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;
{ timeRemaining.decrementAndGet();
elapsedTime -= 1000000000; }
timeRemaining.decrementAndGet(); }
}
}
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) {
} timeRemainingString += "\u00A7e";
else if(timeRemainingInt > 4) } else {
{ timeRemainingString += "\u00A7c";
timeRemainingString += "\u00A7e"; }
} timeRemainingString += Integer.toString(timeRemainingInt);
else int stringWidth = getMinecraft().fontRenderer.getStringWidth(timeRemainingString);
{ fill(width / 2 - stringWidth / 2, 5, width / 2 + stringWidth / 2, 15, 0x70000000);
timeRemainingString += "\u00A7c"; getMinecraft().fontRenderer.drawString(timeRemainingString, width / 2 - stringWidth / 2, 5, 0xFFFFFFFF);
} stringWidth = getMinecraft().fontRenderer.getStringWidth(info);
timeRemainingString += Integer.toString(timeRemainingInt); fill(width / 2 - stringWidth / 2, 20, width / 2 + stringWidth / 2, 30, 0x70000000);
int stringWidth = Minecraft.getMinecraft().fontRenderer.getStringWidth(timeRemainingString); getMinecraft().fontRenderer.drawString(info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF);
drawRect(width/2 - stringWidth/2, 5, width/2 + stringWidth/2, 15, 0x70000000); }
Minecraft.getMinecraft().fontRenderer.drawString(timeRemainingString, width/2 - stringWidth/2, 5, 0xFFFFFFFF);
stringWidth = Minecraft.getMinecraft().fontRenderer.getStringWidth(info);
drawRect(width/2 - stringWidth/2, 20, width/2 + stringWidth/2, 30, 0x70000000);
Minecraft.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) {
{ case ATTACK:
switch(ButtonAction.valueOf(button.id)) setState(MenuState.ATTACK_TARGET);
{ break;
case ATTACK: case DEFEND:
setState(MenuState.ATTACK_TARGET); TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision(
break; TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
case DEFEND: setState(MenuState.WAITING);
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0)); break;
setState(MenuState.WAITING); case ITEM:
break; setState(MenuState.ITEM_ACTION);
case ITEM: break;
setState(MenuState.ITEM_ACTION); case FLEE:
break; TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision(
case FLEE: TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
TurnBasedMinecraftMod.NWINSTANCE.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()
{ .sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID)); Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID()));
setState(MenuState.WAITING); setState(MenuState.WAITING);
} } else {
else setState(MenuState.MAIN_MENU);
{ }
setState(MenuState.MAIN_MENU); break;
} case SWITCH_HELD_ITEM:
break; setState(MenuState.SWITCH_ITEM);
case SWITCH_HELD_ITEM: break;
setState(MenuState.SWITCH_ITEM); case DECIDE_USE_ITEM:
break; setState(MenuState.USE_ITEM);
case DECIDE_USE_ITEM: break;
setState(MenuState.USE_ITEM); case CANCEL:
break; setState(MenuState.MAIN_MENU);
case CANCEL: break;
setState(MenuState.MAIN_MENU); case DO_ITEM_SWITCH:
break; if (button instanceof ItemSelectionButton) {
case DO_ITEM_SWITCH: TurnBasedMinecraftMod.getHandler()
if(button instanceof ItemSelectionButton) .sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
{ Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton) button).getID()));
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID)); if (((ItemSelectionButton) button).getID() >= 0 && ((ItemSelectionButton) button).getID() < 9) {
if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9) Minecraft.getInstance().player.inventory.currentItem = ((ItemSelectionButton) button).getID();
{ }
Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID; setState(MenuState.WAITING);
} } else {
setState(MenuState.WAITING); setState(MenuState.MAIN_MENU);
} }
else break;
{ case DO_USE_ITEM:
setState(MenuState.MAIN_MENU); if (button instanceof ItemSelectionButton) {
} TurnBasedMinecraftMod.getHandler()
break; .sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
case DO_USE_ITEM: Battle.Decision.USE_ITEM, ((ItemSelectionButton) button).getID()));
if(button instanceof ItemSelectionButton) setState(MenuState.WAITING);
{ } else {
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID)); setState(MenuState.MAIN_MENU);
setState(MenuState.WAITING); }
} break;
else }
{ }
setState(MenuState.MAIN_MENU);
}
break;
}
}
@Override @Override
public void initGui() protected void init() {
{ }
super.initGui();
}
@Override @Override
public void onGuiClosed() public boolean isPauseScreen() {
{ return false;
super.onGuiClosed(); }
}
@Override @Override
public boolean doesGuiPauseGame() public boolean keyPressed(int a, int b, int c) {
{ if (getMinecraft().player.isCreative()) {
return false; return super.keyPressed(a, b, c);
} }
return false; // TODO verify return value
}
@Override public void setTimeRemaining(int remaining) {
protected void keyTyped(char typedChar, int keyCode) throws IOException timeRemaining.set(remaining);
{ }
if(Minecraft.getMinecraft().player.isCreative())
{
super.keyTyped(typedChar, keyCode);
}
}
public void setTimeRemaining(int 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.getInstance().displayGuiScreen(battleGui);
Minecraft.getMinecraft().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(
PacketBattleInfo.class, packetHandlerID++,
packetHandlerID++, PacketBattleInfo.class,
Side.CLIENT); PacketBattleInfo::encode,
NWINSTANCE.registerMessage( PacketBattleInfo::decode,
PacketBattleRequestInfo.HandlerBattleRequestInfo.class, PacketBattleInfo.Handler::handle);
PacketBattleRequestInfo.class, HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
Side.SERVER); PacketBattleRequestInfo.class,
NWINSTANCE.registerMessage( PacketBattleRequestInfo::encode,
PacketBattleDecision.HandleBattleDecision.class, PacketBattleRequestInfo::decode,
PacketBattleDecision.class, PacketBattleRequestInfo.Handler::handle);
packetHandlerID++, HANDLER.registerMessage(
Side.SERVER); packetHandlerID++,
NWINSTANCE.registerMessage( PacketBattleDecision.class,
PacketBattleMessage.HandlerBattleMessage.class, PacketBattleDecision::encode,
PacketBattleMessage.class, PacketBattleDecision::decode,
packetHandlerID++, PacketBattleDecision.Handler::handle);
Side.CLIENT); HANDLER.registerMessage(
NWINSTANCE.registerMessage( packetHandlerID++,
PacketGeneralMessage.HandlerGeneralMessage.class, PacketBattleMessage.class,
PacketGeneralMessage.class, PacketBattleMessage::encode,
packetHandlerID++, PacketBattleMessage::decode,
Side.CLIENT); PacketBattleMessage.Handler::handle);
NWINSTANCE.registerMessage( HANDLER.registerMessage(
PacketEditingMessage.HandlerEditingMessage.class, packetHandlerID++,
PacketEditingMessage.class, PacketGeneralMessage.class,
packetHandlerID++, PacketGeneralMessage::encode,
Side.CLIENT PacketGeneralMessage::decode,
); PacketGeneralMessage.Handler::handle);
HANDLER.registerMessage(
packetHandlerID++,
PacketEditingMessage.class,
PacketEditingMessage::encode,
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);
{ if(b != null)
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID); {
if(b != null) ServerPlayerEntity player = ctx.get().getSender();
{ b.setDecision(player.getEntityId(), pkt.decision, pkt.targetIDOrItemID);
EntityPlayerMP player = ctx.getServerHandler().player; }
b.setDecision(player.getEntityId(), message.decision, message.targetIDOrItemID); });
} ctx.get().setPacketHandled(true);
return null; }
}
} }
} }

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());
int sideACount = buf.readInt(); for(Integer id : pkt.sideA) {
int sideBCount = buf.readInt(); buf.writeInt(id);
for(int i = 0; i < sideACount; ++i) }
{ for(Integer id : pkt.sideB) {
sideA.add(buf.readInt()); buf.writeInt(id);
} }
for(int i = 0; i < sideBCount; ++i) buf.writeLong(pkt.decisionNanos);
{
sideB.add(buf.readInt());
}
decisionNanos = buf.readLong();
} }
@Override public static PacketBattleInfo decode(PacketBuffer buf) {
public void toBytes(ByteBuf buf) int sideACount = buf.readInt();
{ int sideBCount = buf.readInt();
buf.writeInt(sideA.size()); Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
buf.writeInt(sideB.size()); Collection<Integer> sideB = new ArrayList<Integer>(sideBCount);
for(Integer id : sideA) for(int i = 0; i < sideACount; ++i) {
{ sideA.add(buf.readInt());
buf.writeInt(id); }
} for(int i = 0; i < sideBCount; ++i) {
for(Integer id : sideB) sideB.add(buf.readInt());
{ }
buf.writeInt(id); long decisionNanos = buf.readLong();
} return new PacketBattleInfo(sideA, sideB, decisionNanos);
buf.writeLong(decisionNanos);
} }
public static class HandlerBattleInfo implements IMessageHandler<PacketBattleInfo, IMessage> public static class Handler {
{ public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
@Override ctx.get().enqueueWork(() -> {
public IMessage onMessage(PacketBattleInfo message, MessageContext ctx) if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{
return null;
}
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : message.sideA)
{
Entity e = Minecraft.getMinecraft().world.getEntityByID(id);
if(e != null)
{ {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e); return;
} }
} TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : message.sideB) for(Integer id : pkt.sideA)
{
Entity e = Minecraft.getMinecraft().world.getEntityByID(id);
if(e != null)
{ {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e); Entity e = Minecraft.getInstance().world.getEntityByID(id);
if(e != null)
{
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
}
} }
} for(Integer id : pkt.sideB)
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L)); {
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); Entity e = Minecraft.getInstance().world.getEntityByID(id);
return null; if(e != null)
} {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
}
}
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
});
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,221 +121,174 @@ 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);
{ String from = "Unknown";
Entity fromEntity = TurnBasedMinecraftMod.proxy.getEntityByID(message.entityIDFrom);
String from = "Unknown";
if(fromEntity != null)
{
if(fromEntity.hasCustomName())
{
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)
{
fromEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(message.entityIDFrom);
if(fromEntity != null) if(fromEntity != null)
{ {
if(fromEntity.hasCustomName()) from = fromEntity.getDisplayName().getFormattedText();
}
else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
fromEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(pkt.entityIDFrom);
if(fromEntity != null)
{ {
from = fromEntity.getCustomNameTag(); from = fromEntity.getDisplayName().getFormattedText();
}
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.hasCustomName())
{
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)
{
toEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(message.entityIDTo);
if(toEntity != null) if(toEntity != null)
{ {
if(toEntity.hasCustomName()) to = toEntity.getDisplayName().getFormattedText();
}
else if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
toEntity = TurnBasedMinecraftMod.proxy.getLocalBattle().getCombatantEntity(pkt.entityIDTo);
if(toEntity != null)
{ {
to = toEntity.getCustomNameTag(); to = toEntity.getDisplayName().getFormattedText();
}
else if(toEntity instanceof EntityPlayer)
{
to = ScorePlayerTeam.formatPlayerName(toEntity.getTeam(), toEntity.getName());
}
else
{
to = toEntity.getName();
} }
} }
}
switch(message.messageType) switch(pkt.messageType)
{
case ENTERED:
TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!");
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != message.amount)
{ {
TurnBasedMinecraftMod.proxy.createLocalBattle(message.amount); case ENTERED:
} TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!");
TurnBasedMinecraftMod.proxy.battleStarted(); if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != pkt.amount)
TurnBasedMinecraftMod.proxy.typeEnteredBattle(message.custom);
break;
case FLEE:
if(message.amount != 0)
{
TurnBasedMinecraftMod.proxy.displayString(from + " fled battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(message.custom);
}
else
{
TurnBasedMinecraftMod.proxy.displayString(from + " tried to flee battle but failed!");
}
break;
case DIED:
TurnBasedMinecraftMod.proxy.displayString(from + " died in battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(message.custom);
break;
case ENDED:
TurnBasedMinecraftMod.proxy.displayString("Battle has ended!");
TurnBasedMinecraftMod.proxy.battleEnded();
break;
case ATTACK:
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " and dealt " + message.amount + " damage!");
break;
case DEFEND:
TurnBasedMinecraftMod.proxy.displayString(from + " blocked " + to + "'s attack!");
break;
case DEFENSE_DAMAGE:
TurnBasedMinecraftMod.proxy.displayString(from + " retaliated from " + to + "'s attack and dealt " + message.amount + " damage!");
break;
case MISS:
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " but missed!");
break;
case DEFENDING:
TurnBasedMinecraftMod.proxy.displayString(from + " is defending!");
break;
case DID_NOTHING:
TurnBasedMinecraftMod.proxy.displayString(from + " did nothing!");
break;
case USED_ITEM:
switch(UsedItemAction.valueOf(message.amount))
{
case USED_NOTHING:
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use nothing!");
break;
case USED_INVALID:
if(message.custom.length() > 0)
{ {
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume " + message.custom + " and failed!"); TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.amount);
}
TurnBasedMinecraftMod.proxy.battleStarted();
TurnBasedMinecraftMod.proxy.typeEnteredBattle(pkt.custom);
break;
case FLEE:
if(pkt.amount != 0)
{
TurnBasedMinecraftMod.proxy.displayString(from + " fled battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(pkt.custom);
} }
else else
{ {
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume an invalid item and failed!"); TurnBasedMinecraftMod.proxy.displayString(from + " tried to flee battle but failed!");
} }
break; break;
case USED_FOOD: case DIED:
TurnBasedMinecraftMod.proxy.displayString(from + " ate a " + message.custom + "!"); TurnBasedMinecraftMod.proxy.displayString(from + " died in battle!");
TurnBasedMinecraftMod.proxy.typeLeftBattle(pkt.custom);
break; break;
case USED_POTION: case ENDED:
TurnBasedMinecraftMod.proxy.displayString(from + " drank a " + message.custom + "!"); TurnBasedMinecraftMod.proxy.displayString("Battle has ended!");
TurnBasedMinecraftMod.proxy.battleEnded();
break; break;
} case ATTACK:
break; TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " and dealt " + pkt.amount + " damage!");
case TURN_BEGIN: break;
TurnBasedMinecraftMod.proxy.displayString("The turn begins!"); case DEFEND:
TurnBasedMinecraftMod.proxy.battleGuiTurnBegin(); TurnBasedMinecraftMod.proxy.displayString(from + " blocked " + to + "'s attack!");
break; break;
case TURN_END: case DEFENSE_DAMAGE:
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null) TurnBasedMinecraftMod.proxy.displayString(from + " retaliated from " + to + "'s attack and dealt " + pkt.amount + " damage!");
{ break;
if(message.amount == 0) case MISS:
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " but missed!");
break;
case DEFENDING:
TurnBasedMinecraftMod.proxy.displayString(from + " is defending!");
break;
case DID_NOTHING:
TurnBasedMinecraftMod.proxy.displayString(from + " did nothing!");
break;
case USED_ITEM:
switch(UsedItemAction.valueOf(pkt.amount))
{ {
TurnBasedMinecraftMod.proxy.displayString("The turn ended!"); case USED_NOTHING:
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use nothing!");
break;
case USED_INVALID:
if(pkt.custom.length() > 0)
{
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume " + pkt.custom + " and failed!");
}
else
{
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume an invalid item and failed!");
}
break;
case USED_FOOD:
TurnBasedMinecraftMod.proxy.displayString(from + " ate a " + pkt.custom + "!");
break;
case USED_POTION:
TurnBasedMinecraftMod.proxy.displayString(from + " drank a " + pkt.custom + "!");
break;
}
break;
case TURN_BEGIN:
TurnBasedMinecraftMod.proxy.displayString("The turn begins!");
TurnBasedMinecraftMod.proxy.battleGuiTurnBegin();
break;
case TURN_END:
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
{
if(pkt.amount == 0)
{
TurnBasedMinecraftMod.proxy.displayString("The turn ended!");
}
else
{
TurnBasedMinecraftMod.proxy.displayString("The turn ended (abnormally due to internal error)!");
}
}
TurnBasedMinecraftMod.proxy.battleGuiTurnEnd();
break;
case SWITCHED_ITEM:
if(pkt.amount != 0)
{
TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item!");
} }
else else
{ {
TurnBasedMinecraftMod.proxy.displayString("The turn ended (abnormally due to internal error)!"); TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item but failed because it was invalid!");
} }
break;
case WAS_AFFECTED:
TurnBasedMinecraftMod.proxy.displayString(to + " was " + pkt.custom + " by " + from + "!");
break;
case BECAME_CREATIVE:
TurnBasedMinecraftMod.proxy.displayString(from + " entered creative mode and left battle!");
break;
case FIRED_ARROW:
TurnBasedMinecraftMod.proxy.displayString(from + " let loose an arrow towards " + to + "!");
break;
case ARROW_HIT:
TurnBasedMinecraftMod.proxy.displayString(to + " was hit by " + from + "'s arrow!");
break;
case BOW_NO_AMMO:
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use their bow but ran out of ammo!");
break;
} }
TurnBasedMinecraftMod.proxy.battleGuiTurnEnd(); });
break; ctx.get().setPacketHandled(true);
case SWITCHED_ITEM: }
if(message.amount != 0)
{
TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item!");
}
else
{
TurnBasedMinecraftMod.proxy.displayString(from + " switched to a different item but failed because it was invalid!");
}
break;
case WAS_AFFECTED:
TurnBasedMinecraftMod.proxy.displayString(to + " was " + message.custom + " by " + from + "!");
break;
case BECAME_CREATIVE:
TurnBasedMinecraftMod.proxy.displayString(from + " entered creative mode and left battle!");
break;
case FIRED_ARROW:
TurnBasedMinecraftMod.proxy.displayString(from + " let loose an arrow towards " + to + "!");
break;
case ARROW_HIT:
TurnBasedMinecraftMod.proxy.displayString(to + " was hit by " + from + "'s arrow!");
break;
case BOW_NO_AMMO:
TurnBasedMinecraftMod.proxy.displayString(from + " tried to use their bow but ran out of ammo!");
break;
}
return null;
}
} }
} }

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) }
{ TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()), ctx.get());
return null; });
} ctx.get().setPacketHandled(true);
return new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()); }
}
} }
} }

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,