WIP porting to forge 1.14.4
This commit is contained in:
parent
f05e5e6a07
commit
d2f668187e
24 changed files with 2216 additions and 2262 deletions
179
build.gradle
179
build.gradle
|
@ -1,93 +1,150 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url = "http://files.minecraftforge.net/maven" }
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
||||
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.1'
|
||||
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
|
||||
}
|
||||
}
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: 'eclipse'
|
||||
//apply plugin: 'maven-publish'
|
||||
|
||||
version = "1.8"
|
||||
version = "1.9"
|
||||
group = "com.seodisparate.TurnBasedMinecraft"
|
||||
archivesBaseName = "TurnBasedMinecraft"
|
||||
|
||||
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
|
||||
compileJava {
|
||||
sourceCompatibility = targetCompatibility = '1.8'
|
||||
}
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
|
||||
|
||||
minecraft {
|
||||
version = "1.12.2-14.23.5.2768"
|
||||
runDir = "run"
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
// simply re-run your setup task after changing the mappings to update your workspace.
|
||||
mappings = "snapshot_20171003"
|
||||
// Simply re-run your setup task after changing the mappings to update your workspace.
|
||||
mappings channel: 'snapshot', version: '20190719-1.14.3'
|
||||
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
|
||||
|
||||
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
|
||||
// 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 {
|
||||
// you may put jars on which you depend on in ./libs
|
||||
// or you may define them like so..
|
||||
//compile "some.group:artifact:version:classifier"
|
||||
//compile "some.group:artifact:version"
|
||||
// Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
|
||||
// that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
|
||||
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
|
||||
minecraft 'net.minecraftforge:forge:1.14.4-28.1.0'
|
||||
|
||||
// toml parser
|
||||
compile "net.consensys.cava:cava-toml:0.3.1"
|
||||
// You may put jars on which you depend on in ./libs or you may define them like so..
|
||||
// compile "some.group:artifact:version:classifier"
|
||||
// compile "some.group:artifact:version"
|
||||
|
||||
// real examples
|
||||
//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
|
||||
// Real examples
|
||||
// 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
|
||||
|
||||
// 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'
|
||||
// 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'
|
||||
|
||||
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
|
||||
// except that these dependencies get remapped to your current MCP mappings
|
||||
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
||||
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
|
||||
// These dependencies get remapped to your current MCP mappings
|
||||
// deobf '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/dependency_management.html
|
||||
|
||||
compile files('src/main/resources/META-INF/libraries/javamp3-1.0.3.jar')
|
||||
}
|
||||
|
||||
processResources {
|
||||
// this will ensure that this task is redone when the versions change.
|
||||
inputs.property "version", project.version
|
||||
inputs.property "mcversion", project.minecraft.version
|
||||
|
||||
// replace stuff in mcmod.info, nothing else
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'mcmod.info'
|
||||
|
||||
// replace version and mcversion
|
||||
expand 'version':project.version, 'mcversion':project.minecraft.version
|
||||
}
|
||||
|
||||
// copy everything else except the mcmod.info
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'mcmod.info'
|
||||
// Example for how to get properties into the manifest for reading by the runtime..
|
||||
jar {
|
||||
manifest {
|
||||
attributes([
|
||||
"Specification-Title": "TurnBasedMinecraftMod",
|
||||
"Specification-Vendor": "TurnBasedMinecraftMod_SS",
|
||||
"Specification-Version": "1", // We are version 1 of ourselves
|
||||
"Implementation-Title": project.name,
|
||||
"Implementation-Version": "${version}",
|
||||
"Implementation-Vendor" :"TurnBasedMinecraftMod_SS",
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
"ContainedDeps": "javamp3-1.0.3.jar"
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
classifier ""
|
||||
|
||||
relocate 'net.consensys.cava', 'shadow.turnbasedmc.net.consensys.cava'
|
||||
relocate 'org.antlr.v4', 'shadow.turnbasedmc.org.antlr.v4'
|
||||
relocate 'javax.annotation', 'shadow.turnbasedmc.javax.annotation'
|
||||
|
||||
relocate 'fr.delthas', 'shadow.turnbasedmc.fr.delthas'
|
||||
// Example configuration to allow publishing using the maven-publish task
|
||||
// we define a custom artifact that is sourced from the reobfJar output task
|
||||
// and then declare that to be published
|
||||
// Note you'll need to add a repository here
|
||||
def reobfFile = file("$buildDir/reobfJar/output.jar")
|
||||
def reobfArtifact = artifacts.add('default', reobfFile) {
|
||||
type 'jar'
|
||||
builtBy 'reobfJar'
|
||||
}
|
||||
|
||||
reobf { shadowJar { mappingType = "SEARGE" } }
|
||||
tasks.reobfShadowJar.mustRunAfter shadowJar
|
||||
//publishing {
|
||||
// publications {
|
||||
// mavenJava(MavenPublication) {
|
||||
// artifact reobfArtifact
|
||||
// }
|
||||
// }
|
||||
// repositories {
|
||||
// maven {
|
||||
// url "file:///${project.projectDir}/mcmodsrepo"
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -13,370 +12,334 @@ import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
|||
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleDecision;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
public class BattleGui extends GuiScreen
|
||||
{
|
||||
private AtomicInteger timeRemaining;
|
||||
private long lastInstant;
|
||||
private long elapsedTime;
|
||||
private MenuState state;
|
||||
private boolean stateChanged;
|
||||
private String info;
|
||||
public class BattleGui extends Screen {
|
||||
private AtomicInteger timeRemaining;
|
||||
private long lastInstant;
|
||||
private long elapsedTime;
|
||||
private MenuState state;
|
||||
private boolean stateChanged;
|
||||
private String info;
|
||||
|
||||
private enum MenuState
|
||||
{
|
||||
MAIN_MENU(0),
|
||||
ATTACK_TARGET(1),
|
||||
ITEM_ACTION(2),
|
||||
WAITING(3),
|
||||
SWITCH_ITEM(4),
|
||||
USE_ITEM(5);
|
||||
private enum MenuState {
|
||||
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)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
MenuState(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Map<Integer, MenuState> map;
|
||||
private static Map<Integer, MenuState> map;
|
||||
|
||||
static
|
||||
{
|
||||
map = new HashMap<Integer, MenuState>();
|
||||
for(MenuState state : MenuState.values())
|
||||
{
|
||||
map.put(state.getValue(), state);
|
||||
}
|
||||
}
|
||||
static {
|
||||
map = new HashMap<Integer, MenuState>();
|
||||
for (MenuState state : MenuState.values()) {
|
||||
map.put(state.getValue(), state);
|
||||
}
|
||||
}
|
||||
|
||||
public static MenuState valueOf(int value)
|
||||
{
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
public static MenuState valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
|
||||
private enum ButtonAction
|
||||
{
|
||||
ATTACK(0),
|
||||
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 enum ButtonAction {
|
||||
ATTACK(0), 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)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
ButtonAction(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Map<Integer, ButtonAction> map;
|
||||
static
|
||||
{
|
||||
map = new HashMap<Integer, ButtonAction>();
|
||||
for(ButtonAction action : ButtonAction.values())
|
||||
{
|
||||
map.put(action.getValue(), action);
|
||||
}
|
||||
}
|
||||
private static Map<Integer, ButtonAction> map;
|
||||
static {
|
||||
map = new HashMap<Integer, ButtonAction>();
|
||||
for (ButtonAction action : ButtonAction.values()) {
|
||||
map.put(action.getValue(), action);
|
||||
}
|
||||
}
|
||||
|
||||
public static ButtonAction valueOf(int value)
|
||||
{
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
public static ButtonAction valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
}
|
||||
|
||||
public BattleGui()
|
||||
{
|
||||
timeRemaining = new AtomicInteger((int)(Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L));
|
||||
lastInstant = System.nanoTime();
|
||||
elapsedTime = 0;
|
||||
state = MenuState.MAIN_MENU;
|
||||
stateChanged = true;
|
||||
}
|
||||
public BattleGui() {
|
||||
super(new StringTextComponent("Battle Gui"));
|
||||
timeRemaining = new AtomicInteger((int) (Config.BATTLE_DECISION_DURATION_NANO_DEFAULT / 1000000000L));
|
||||
lastInstant = System.nanoTime();
|
||||
elapsedTime = 0;
|
||||
state = MenuState.MAIN_MENU;
|
||||
stateChanged = true;
|
||||
}
|
||||
|
||||
private void setState(MenuState state)
|
||||
{
|
||||
this.state = state;
|
||||
stateChanged = true;
|
||||
}
|
||||
private void setState(MenuState state) {
|
||||
this.state = state;
|
||||
stateChanged = true;
|
||||
}
|
||||
|
||||
public void turnBegin()
|
||||
{
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.ACTION);
|
||||
}
|
||||
setState(MenuState.WAITING);
|
||||
}
|
||||
public void turnBegin() {
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() != null) {
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.ACTION);
|
||||
}
|
||||
setState(MenuState.WAITING);
|
||||
}
|
||||
|
||||
public void turnEnd()
|
||||
{
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION);
|
||||
}
|
||||
timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds());
|
||||
elapsedTime = 0;
|
||||
lastInstant = System.nanoTime();
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
public void turnEnd() {
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() != null) {
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().setState(Battle.State.DECISION);
|
||||
}
|
||||
timeRemaining.set(TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationSeconds());
|
||||
elapsedTime = 0;
|
||||
lastInstant = System.nanoTime();
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
|
||||
public void battleChanged()
|
||||
{
|
||||
stateChanged = true;
|
||||
}
|
||||
public void battleChanged() {
|
||||
stateChanged = true;
|
||||
}
|
||||
|
||||
public void updateState()
|
||||
{
|
||||
if(!stateChanged)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void updateState() {
|
||||
if (!stateChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
stateChanged = false;
|
||||
buttonList.clear();
|
||||
switch(state)
|
||||
{
|
||||
case MAIN_MENU:
|
||||
info = "What will you do?";
|
||||
buttonList.add(new GuiButton(ButtonAction.ATTACK.getValue(), width*3/7 - 25, 40, 50, 20, "Attack"));
|
||||
buttonList.add(new GuiButton(ButtonAction.DEFEND.getValue(), width*4/7 - 25, 40, 50, 20, "Defend"));
|
||||
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"));
|
||||
break;
|
||||
case ATTACK_TARGET:
|
||||
info = "Who will you attack?";
|
||||
int y = 30;
|
||||
try
|
||||
{
|
||||
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideAEntrySet())
|
||||
{
|
||||
if(e.getValue().entity != null)
|
||||
{
|
||||
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), true));
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width/4 - 60, y, 120, 20, "Unknown", e.getKey(), true));
|
||||
}
|
||||
y += 20;
|
||||
}
|
||||
} catch (ConcurrentModificationException e)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
y = 30;
|
||||
try
|
||||
{
|
||||
for(Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle().getSideBEntrySet())
|
||||
{
|
||||
if(e.getValue().entity != null)
|
||||
{
|
||||
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, e.getValue().entity.getName(), e.getKey(), false));
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonList.add(new EntitySelectionButton(ButtonAction.ATTACK_TARGET.getValue(), width*3/4 - 60, y, 120, 20, "Unknown", e.getKey(), false));
|
||||
}
|
||||
y += 20;
|
||||
}
|
||||
} catch (ConcurrentModificationException e)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 30, height - 120, 60, 20, "Cancel"));
|
||||
break;
|
||||
case ITEM_ACTION:
|
||||
info = "What will you do with an item?";
|
||||
buttonList.add(new GuiButton(ButtonAction.SWITCH_HELD_ITEM.getValue(), width*1/4 - 40, height - 120, 80, 20, "Switch Held"));
|
||||
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"));
|
||||
break;
|
||||
case WAITING:
|
||||
info = "Waiting...";
|
||||
break;
|
||||
case SWITCH_ITEM:
|
||||
info = "To which item will you switch to?";
|
||||
for(int i = 0; i < 9; ++i)
|
||||
{
|
||||
buttonList.add(new ItemSelectionButton(ButtonAction.DO_ITEM_SWITCH.getValue(), width/2 - 88 + i * 20, height - 19, 16, 16, "", i));
|
||||
}
|
||||
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel"));
|
||||
break;
|
||||
case USE_ITEM:
|
||||
info = "Which item will you use?";
|
||||
for(int i = 0; i < 9; ++i)
|
||||
{
|
||||
buttonList.add(new ItemSelectionButton(ButtonAction.DO_USE_ITEM.getValue(), width/2 - 88 + i * 20, height - 19, 16, 16, "", i));
|
||||
}
|
||||
buttonList.add(new GuiButton(ButtonAction.CANCEL.getValue(), width/2 - 40, height - 120, 80, 20, "Cancel"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
stateChanged = false;
|
||||
buttons.clear();
|
||||
children.clear();
|
||||
switch (state) {
|
||||
case MAIN_MENU:
|
||||
info = "What will you do?";
|
||||
addButton(new Button(width * 3 / 7 - 25, 40, 50, 20, "Attack", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK);
|
||||
}));
|
||||
addButton(new Button(width * 4 / 7 - 25, 40, 50, 20, "Defend", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.DEFEND);
|
||||
}));
|
||||
addButton(new Button(width * 3 / 7 - 25, 60, 50, 20, "Item", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ITEM);
|
||||
}));
|
||||
addButton(new Button(width * 4 / 7 - 25, 60, 50, 20, "Flee", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.FLEE);
|
||||
}));
|
||||
break;
|
||||
case ATTACK_TARGET:
|
||||
info = "Who will you attack?";
|
||||
int y = 30;
|
||||
try {
|
||||
for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
|
||||
.getSideAEntrySet()) {
|
||||
if (e.getValue().entity != null) {
|
||||
addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), true, (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
|
||||
}));
|
||||
} else {
|
||||
addButton(new EntitySelectionButton(width / 4 - 60, y, 120, 20, "Unknown", e.getKey(), true, (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
|
||||
}));
|
||||
}
|
||||
y += 20;
|
||||
}
|
||||
} catch (ConcurrentModificationException e) {
|
||||
// ignored
|
||||
}
|
||||
y = 30;
|
||||
try {
|
||||
for (Map.Entry<Integer, Combatant> e : TurnBasedMinecraftMod.proxy.getLocalBattle()
|
||||
.getSideBEntrySet()) {
|
||||
if (e.getValue().entity != null) {
|
||||
addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, e.getValue().entity.getName().getString(), e.getKey(), false, (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
|
||||
}));
|
||||
} else {
|
||||
addButton(new EntitySelectionButton(width * 3 / 4 - 60, y, 120, 20, "Unknown", e.getKey(), false, (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.ATTACK_TARGET);
|
||||
}));
|
||||
}
|
||||
y += 20;
|
||||
}
|
||||
} catch (ConcurrentModificationException e) {
|
||||
// ignored
|
||||
}
|
||||
addButton(new Button(width / 2 - 30, height - 120, 60, 20, "Cancel", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.CANCEL);
|
||||
}));
|
||||
break;
|
||||
case ITEM_ACTION:
|
||||
info = "What will you do with an item?";
|
||||
addButton(new Button(width * 1 / 4 - 40, height - 120, 80, 20, "Switch Held", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.SWITCH_HELD_ITEM);
|
||||
}));
|
||||
addButton(new Button(width * 2 / 4 - 40, height - 120, 80, 20, "Use", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.DECIDE_USE_ITEM);
|
||||
}));
|
||||
addButton(new Button(width * 3 / 4 - 40, height - 120, 80, 20, "Cancel", (button) -> {
|
||||
buttonActionEvent(button, ButtonAction.CANCEL);
|
||||
}));
|
||||
break;
|
||||
case WAITING:
|
||||
info = "Waiting...";
|
||||
break;
|
||||
case SWITCH_ITEM:
|
||||
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
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
|
||||
{
|
||||
drawHoveringText("Waiting...", width / 2 - 50, height / 2);
|
||||
return;
|
||||
}
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION && timeRemaining.get() > 0)
|
||||
{
|
||||
long nextInstant = System.nanoTime();
|
||||
elapsedTime += nextInstant - lastInstant;
|
||||
lastInstant = nextInstant;
|
||||
while(elapsedTime > 1000000000)
|
||||
{
|
||||
elapsedTime -= 1000000000;
|
||||
timeRemaining.decrementAndGet();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() == null) {
|
||||
// drawHoveringText("Waiting...", width / 2 - 50, height / 2);
|
||||
getMinecraft().fontRenderer.drawString("Waiting...", width / 2 - 50, height / 2, 0xFFFFFFFF);
|
||||
return;
|
||||
}
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION
|
||||
&& timeRemaining.get() > 0) {
|
||||
long nextInstant = System.nanoTime();
|
||||
elapsedTime += nextInstant - lastInstant;
|
||||
lastInstant = nextInstant;
|
||||
while (elapsedTime > 1000000000) {
|
||||
elapsedTime -= 1000000000;
|
||||
timeRemaining.decrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
updateState();
|
||||
updateState();
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
|
||||
String timeRemainingString = "Time remaining: ";
|
||||
int timeRemainingInt = timeRemaining.get();
|
||||
if(timeRemainingInt > 8)
|
||||
{
|
||||
timeRemainingString += "\u00A7a";
|
||||
}
|
||||
else if(timeRemainingInt > 4)
|
||||
{
|
||||
timeRemainingString += "\u00A7e";
|
||||
}
|
||||
else
|
||||
{
|
||||
timeRemainingString += "\u00A7c";
|
||||
}
|
||||
timeRemainingString += Integer.toString(timeRemainingInt);
|
||||
int stringWidth = Minecraft.getMinecraft().fontRenderer.getStringWidth(timeRemainingString);
|
||||
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);
|
||||
}
|
||||
String timeRemainingString = "Time remaining: ";
|
||||
int timeRemainingInt = timeRemaining.get();
|
||||
if (timeRemainingInt > 8) {
|
||||
timeRemainingString += "\u00A7a";
|
||||
} else if (timeRemainingInt > 4) {
|
||||
timeRemainingString += "\u00A7e";
|
||||
} else {
|
||||
timeRemainingString += "\u00A7c";
|
||||
}
|
||||
timeRemainingString += Integer.toString(timeRemainingInt);
|
||||
int stringWidth = getMinecraft().fontRenderer.getStringWidth(timeRemainingString);
|
||||
fill(width / 2 - stringWidth / 2, 5, width / 2 + stringWidth / 2, 15, 0x70000000);
|
||||
getMinecraft().fontRenderer.drawString(timeRemainingString, width / 2 - stringWidth / 2, 5, 0xFFFFFFFF);
|
||||
stringWidth = getMinecraft().fontRenderer.getStringWidth(info);
|
||||
fill(width / 2 - stringWidth / 2, 20, width / 2 + stringWidth / 2, 30, 0x70000000);
|
||||
getMinecraft().fontRenderer.drawString(info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException
|
||||
{
|
||||
switch(ButtonAction.valueOf(button.id))
|
||||
{
|
||||
case ATTACK:
|
||||
setState(MenuState.ATTACK_TARGET);
|
||||
break;
|
||||
case DEFEND:
|
||||
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
|
||||
setState(MenuState.WAITING);
|
||||
break;
|
||||
case ITEM:
|
||||
setState(MenuState.ITEM_ACTION);
|
||||
break;
|
||||
case FLEE:
|
||||
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
|
||||
setState(MenuState.WAITING);
|
||||
break;
|
||||
case ATTACK_TARGET:
|
||||
if(button instanceof EntitySelectionButton)
|
||||
{
|
||||
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton)button).entityID));
|
||||
setState(MenuState.WAITING);
|
||||
}
|
||||
else
|
||||
{
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
break;
|
||||
case SWITCH_HELD_ITEM:
|
||||
setState(MenuState.SWITCH_ITEM);
|
||||
break;
|
||||
case DECIDE_USE_ITEM:
|
||||
setState(MenuState.USE_ITEM);
|
||||
break;
|
||||
case CANCEL:
|
||||
setState(MenuState.MAIN_MENU);
|
||||
break;
|
||||
case DO_ITEM_SWITCH:
|
||||
if(button instanceof ItemSelectionButton)
|
||||
{
|
||||
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton)button).itemStackID));
|
||||
if(((ItemSelectionButton)button).itemStackID >= 0 && ((ItemSelectionButton)button).itemStackID < 9)
|
||||
{
|
||||
Minecraft.getMinecraft().player.inventory.currentItem = ((ItemSelectionButton)button).itemStackID;
|
||||
}
|
||||
setState(MenuState.WAITING);
|
||||
}
|
||||
else
|
||||
{
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
break;
|
||||
case DO_USE_ITEM:
|
||||
if(button instanceof ItemSelectionButton)
|
||||
{
|
||||
TurnBasedMinecraftMod.NWINSTANCE.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton)button).itemStackID));
|
||||
setState(MenuState.WAITING);
|
||||
}
|
||||
else
|
||||
{
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected void buttonActionEvent(Button button, ButtonAction action) {
|
||||
switch (action) {
|
||||
case ATTACK:
|
||||
setState(MenuState.ATTACK_TARGET);
|
||||
break;
|
||||
case DEFEND:
|
||||
TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision(
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
|
||||
setState(MenuState.WAITING);
|
||||
break;
|
||||
case ITEM:
|
||||
setState(MenuState.ITEM_ACTION);
|
||||
break;
|
||||
case FLEE:
|
||||
TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision(
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
|
||||
setState(MenuState.WAITING);
|
||||
break;
|
||||
case ATTACK_TARGET:
|
||||
if (button instanceof EntitySelectionButton) {
|
||||
TurnBasedMinecraftMod.getHandler()
|
||||
.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
|
||||
Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID()));
|
||||
setState(MenuState.WAITING);
|
||||
} else {
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
break;
|
||||
case SWITCH_HELD_ITEM:
|
||||
setState(MenuState.SWITCH_ITEM);
|
||||
break;
|
||||
case DECIDE_USE_ITEM:
|
||||
setState(MenuState.USE_ITEM);
|
||||
break;
|
||||
case CANCEL:
|
||||
setState(MenuState.MAIN_MENU);
|
||||
break;
|
||||
case DO_ITEM_SWITCH:
|
||||
if (button instanceof ItemSelectionButton) {
|
||||
TurnBasedMinecraftMod.getHandler()
|
||||
.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
|
||||
Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton) button).getID()));
|
||||
if (((ItemSelectionButton) button).getID() >= 0 && ((ItemSelectionButton) button).getID() < 9) {
|
||||
Minecraft.getInstance().player.inventory.currentItem = ((ItemSelectionButton) button).getID();
|
||||
}
|
||||
setState(MenuState.WAITING);
|
||||
} else {
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
break;
|
||||
case DO_USE_ITEM:
|
||||
if (button instanceof ItemSelectionButton) {
|
||||
TurnBasedMinecraftMod.getHandler()
|
||||
.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
|
||||
Battle.Decision.USE_ITEM, ((ItemSelectionButton) button).getID()));
|
||||
setState(MenuState.WAITING);
|
||||
} else {
|
||||
setState(MenuState.MAIN_MENU);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
}
|
||||
@Override
|
||||
protected void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed()
|
||||
{
|
||||
super.onGuiClosed();
|
||||
}
|
||||
@Override
|
||||
public boolean isPauseScreen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean keyPressed(int a, int b, int c) {
|
||||
if (getMinecraft().player.isCreative()) {
|
||||
return super.keyPressed(a, b, c);
|
||||
}
|
||||
return false; // TODO verify return value
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException
|
||||
{
|
||||
if(Minecraft.getMinecraft().player.isCreative())
|
||||
{
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTimeRemaining(int remaining)
|
||||
{
|
||||
timeRemaining.set(remaining);
|
||||
}
|
||||
public void setTimeRemaining(int remaining) {
|
||||
timeRemaining.set(remaining);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@ package com.seodisparate.TurnBasedMinecraft.client;
|
|||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import javax.sound.midi.MidiSystem;
|
||||
|
@ -186,9 +183,7 @@ public class BattleMusic
|
|||
if(initialized && next != null)
|
||||
{
|
||||
logger.debug("play called with file " + next.getName() + " and vol " + volume);
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||
Minecraft.getMinecraft().getSoundHandler().pauseSounds();
|
||||
});
|
||||
Minecraft.getInstance().getSoundHandler().pause();
|
||||
String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase();
|
||||
if(suffix.equals("mid"))
|
||||
{
|
||||
|
@ -305,7 +300,7 @@ public class BattleMusic
|
|||
}
|
||||
if(resumeMCSounds)
|
||||
{
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> Minecraft.getMinecraft().getSoundHandler().resumeSounds() );
|
||||
Minecraft.getInstance().getSoundHandler().resume();
|
||||
}
|
||||
isPlaying = false;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package com.seodisparate.TurnBasedMinecraft.client;
|
|||
import com.seodisparate.TurnBasedMinecraft.common.Battle;
|
||||
import com.seodisparate.TurnBasedMinecraft.common.CommonProxy;
|
||||
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
public class ClientProxy extends CommonProxy
|
||||
|
@ -44,13 +44,11 @@ public class ClientProxy extends CommonProxy
|
|||
@Override
|
||||
public void setBattleGuiAsGui()
|
||||
{
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||
if(Minecraft.getMinecraft().currentScreen != battleGui)
|
||||
{
|
||||
battleGui.turnEnd();
|
||||
Minecraft.getMinecraft().displayGuiScreen(battleGui);
|
||||
}
|
||||
});
|
||||
if(Minecraft.getInstance().currentScreen != battleGui)
|
||||
{
|
||||
battleGui.turnEnd();
|
||||
Minecraft.getInstance().displayGuiScreen(battleGui);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,10 +73,7 @@ public class ClientProxy extends CommonProxy
|
|||
public void battleEnded()
|
||||
{
|
||||
localBattle = null;
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||
Minecraft.getMinecraft().displayGuiScreen(null);
|
||||
Minecraft.getMinecraft().setIngameFocus();
|
||||
});
|
||||
Minecraft.getInstance().displayGuiScreen(null);
|
||||
stopMusic(true);
|
||||
battleMusicCount = 0;
|
||||
sillyMusicCount = 0;
|
||||
|
@ -93,14 +88,14 @@ public class ClientProxy extends CommonProxy
|
|||
@Override
|
||||
public void playBattleMusic()
|
||||
{
|
||||
GameSettings gs = Minecraft.getMinecraft().gameSettings;
|
||||
GameSettings gs = Minecraft.getInstance().gameSettings;
|
||||
battleMusic.playBattle(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSillyMusic()
|
||||
{
|
||||
GameSettings gs = Minecraft.getMinecraft().gameSettings;
|
||||
GameSettings gs = Minecraft.getInstance().gameSettings;
|
||||
battleMusic.playSilly(gs.getSoundLevel(SoundCategory.MUSIC) * gs.getSoundLevel(SoundCategory.MASTER));
|
||||
}
|
||||
|
||||
|
@ -160,24 +155,24 @@ public class ClientProxy extends CommonProxy
|
|||
@Override
|
||||
public void displayString(String message)
|
||||
{
|
||||
ITextComponent prefix = new TextComponentString("TBM: ");
|
||||
ITextComponent prefix = new StringTextComponent("TBM: ");
|
||||
prefix.getStyle().setColor(TextFormatting.GREEN).setBold(true);
|
||||
ITextComponent text = new TextComponentString(message);
|
||||
ITextComponent text = new StringTextComponent(message);
|
||||
prefix.appendSibling(text);
|
||||
text.getStyle().setColor(TextFormatting.WHITE).setBold(false);
|
||||
Minecraft.getMinecraft().player.sendMessage(prefix);
|
||||
Minecraft.getInstance().player.sendMessage(prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayTextComponent(ITextComponent text)
|
||||
{
|
||||
Minecraft.getMinecraft().player.sendMessage(text);
|
||||
Minecraft.getInstance().player.sendMessage(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getEntityByID(int id)
|
||||
{
|
||||
return Minecraft.getMinecraft().world.getEntityByID(id);
|
||||
return Minecraft.getInstance().world.getEntityByID(id);
|
||||
}
|
||||
|
||||
private void checkBattleTypes()
|
||||
|
|
|
@ -1,92 +1,77 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.client;
|
||||
|
||||
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.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;
|
||||
public EntitySelectionButton(int buttonId, int x, int y, String buttonText, int entityID, boolean isSideA)
|
||||
{
|
||||
super(buttonId, x, y, buttonText);
|
||||
|
||||
public EntitySelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA, Button.IPressable onPress) {
|
||||
super(x, y, widthIn, heightIn, buttonText, onPress);
|
||||
this.entityID = entityID;
|
||||
this.isSideA = isSideA;
|
||||
}
|
||||
|
||||
public EntitySelectionButton(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText, int entityID, boolean isSideA)
|
||||
{
|
||||
super(buttonId, x, y, widthIn, heightIn, buttonText);
|
||||
this.entityID = entityID;
|
||||
this.isSideA = isSideA;
|
||||
public int getID() {
|
||||
return entityID;
|
||||
}
|
||||
|
||||
public boolean getIsSideA() {
|
||||
return isSideA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
super.drawButton(mc, mouseX, mouseY, partialTicks);
|
||||
Entity e = Minecraft.getMinecraft().world.getEntityByID(entityID);
|
||||
if(e != null && e instanceof EntityLivingBase && ((EntityLivingBase)e).isEntityAlive())
|
||||
{
|
||||
int health = (int)(((EntityLivingBase)e).getHealth() + 0.5f);
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
Entity e = Minecraft.getInstance().world.getEntityByID(entityID);
|
||||
if(e != null && e instanceof LivingEntity && ((LivingEntity)e).isAlive()) {
|
||||
int health = (int)(((LivingEntity)e).getHealth() + 0.5f);
|
||||
int xpos = x;
|
||||
int xoffset;
|
||||
if(isSideA)
|
||||
{
|
||||
if(isSideA) {
|
||||
xpos += width + 4;
|
||||
xoffset = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xpos -= 6;
|
||||
xoffset = -4;
|
||||
}
|
||||
if(health > 200)
|
||||
{
|
||||
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
|
||||
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);
|
||||
drawRect(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
|
||||
drawRect(xpos, y , xpos + 2, y + height / 5, 0xFF0000FF);
|
||||
if(health > 200) {
|
||||
fill(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
|
||||
fill(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);
|
||||
fill(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
|
||||
fill(xpos, y , xpos + 2, y + height / 5, 0xFF0000FF);
|
||||
int healthHeight = ((health - 200) * height / 100);
|
||||
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFFFF);
|
||||
}
|
||||
else if(health > 100)
|
||||
{
|
||||
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
|
||||
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);
|
||||
drawRect(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
|
||||
fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFFFF);
|
||||
} 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);
|
||||
fill(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
|
||||
fill(xpos, y + height / 5, xpos + 2, y + height * 2 / 5, 0xFF00FFFF);
|
||||
int healthHeight = ((health - 100) * height / 100);
|
||||
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF0000FF);
|
||||
}
|
||||
else if(health > 50)
|
||||
{
|
||||
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
|
||||
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);
|
||||
fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF0000FF);
|
||||
} 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);
|
||||
fill(xpos, y + height * 2 / 5, xpos + 2, y + height * 3 / 5, 0xFF00FF00);
|
||||
int healthHeight = ((health - 50) * height / 50);
|
||||
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FFFF);
|
||||
}
|
||||
else if(health > 20)
|
||||
{
|
||||
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height , 0xFFFF0000);
|
||||
drawRect(xpos, y + height * 3 / 5, xpos + 2, y + height * 4 / 5, 0xFFFFFF00);
|
||||
fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FFFF);
|
||||
} 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);
|
||||
int healthHeight = ((health - 20) * height / 30);
|
||||
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FF00);
|
||||
}
|
||||
else if(health > 10)
|
||||
{
|
||||
drawRect(xpos, y + height * 4 / 5, xpos + 2, y + height, 0xFFFF0000);
|
||||
fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFF00FF00);
|
||||
} else if(health > 10) {
|
||||
fill(xpos, y + height * 4 / 5, xpos + 2, y + height, 0xFFFF0000);
|
||||
int healthHeight = ((health - 10) * height / 10);
|
||||
drawRect(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFF00);
|
||||
}
|
||||
else
|
||||
{
|
||||
fill(xpos + xoffset, y + height - healthHeight, xpos + xoffset + 2, y + height, 0xFFFFFF00);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,28 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
|
||||
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)
|
||||
{
|
||||
super(buttonId, x, y, widthIn, heightIn, buttonText);
|
||||
public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, Button.IPressable onPress) {
|
||||
super(x, y, widthIn, heightIn, buttonText, onPress);
|
||||
this.itemStackID = itemStackID;
|
||||
}
|
||||
|
||||
public ItemSelectionButton(int buttonId, int x, int y, String buttonText, int itemStackID)
|
||||
{
|
||||
super(buttonId, x, y, buttonText);
|
||||
this.itemStackID = itemStackID;
|
||||
public int getID() {
|
||||
return itemStackID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
if(visible)
|
||||
{
|
||||
hovered = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
|
||||
if(hovered)
|
||||
{
|
||||
drawRect(x, y, x + width, y + height, 0x80FFFFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawRect(x, y, x + width, y + height, 0x20707070);
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
if(visible) {
|
||||
boolean hovered = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
|
||||
if(hovered) {
|
||||
fill(x, y, x + width, y + height, 0x80FFFFFF);
|
||||
} else {
|
||||
fill(x, y, x + width, y + height, 0x20707070);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ import com.seodisparate.TurnBasedMinecraft.common.networking.PacketBattleMessage
|
|||
|
||||
import com.seodisparate.TurnBasedMinecraft.common.networking.PacketEditingMessage;
|
||||
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.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
|
||||
public class AttackEventHandler
|
||||
{
|
||||
|
@ -77,21 +78,31 @@ public class AttackEventHandler
|
|||
event.setCanceled(true);
|
||||
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.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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
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.logger.info("Begin editing custom \"" + event.getEntity().getCustomNameTag() + "\"");
|
||||
TurnBasedMinecraftMod.NWINSTANCE.sendTo(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), (EntityPlayerMP) editingInfo.editor);
|
||||
TurnBasedMinecraftMod.getHandler().sendTo(
|
||||
new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\""),
|
||||
((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
|
||||
{
|
||||
|
@ -105,9 +116,15 @@ public class AttackEventHandler
|
|||
{
|
||||
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.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;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,11 @@ package com.seodisparate.TurnBasedMinecraft.common;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
|
@ -152,7 +153,7 @@ public class CommonProxy
|
|||
return editingPlayers.get(id);
|
||||
}
|
||||
|
||||
protected final EditingInfo setEditingPlayer(EntityPlayer player)
|
||||
protected final EditingInfo setEditingPlayer(PlayerEntity player)
|
||||
{
|
||||
return editingPlayers.put(player.getEntityId(), new EditingInfo(player));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,10 +1,10 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public class EditingInfo
|
||||
{
|
||||
public EntityPlayer editor;
|
||||
public PlayerEntity editor;
|
||||
public EntityInfo entityInfo;
|
||||
public boolean isPendingEntitySelection;
|
||||
public boolean isEditingCustomName;
|
||||
|
@ -17,7 +17,7 @@ public class EditingInfo
|
|||
isEditingCustomName = false;
|
||||
}
|
||||
|
||||
public EditingInfo(EntityPlayer player)
|
||||
public EditingInfo(PlayerEntity player)
|
||||
{
|
||||
editor = player;
|
||||
entityInfo = null;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
|
||||
public class EntityInfo
|
||||
{
|
||||
|
@ -43,120 +43,84 @@ public class EntityInfo
|
|||
WEAKNESS,
|
||||
POISON,
|
||||
WITHER,
|
||||
HEALTH_BOOST,
|
||||
ABSORPTION,
|
||||
SATURATION,
|
||||
GLOWING,
|
||||
LEVITATION,
|
||||
LUCK,
|
||||
UNLUCK,
|
||||
SLOW_FALLING,
|
||||
CONDUIT_POWER,
|
||||
DOLPHINS_GRACE,
|
||||
BAD_OMEN,
|
||||
FIRE,
|
||||
UNKNOWN;
|
||||
|
||||
public static Effect fromString(String c)
|
||||
{
|
||||
c = c.toLowerCase();
|
||||
if(c.equals("speed"))
|
||||
{
|
||||
if(c.equals("speed")) {
|
||||
return SPEED;
|
||||
}
|
||||
else if(c.equals("slow"))
|
||||
{
|
||||
} else if(c.equals("slow")) {
|
||||
return SLOW;
|
||||
}
|
||||
else if(c.equals("haste"))
|
||||
{
|
||||
} else if(c.equals("haste")) {
|
||||
return HASTE;
|
||||
}
|
||||
else if(c.equals("mining_fatigue") || c.equals("fatigue"))
|
||||
{
|
||||
} else if(c.equals("mining_fatigue") || c.equals("fatigue")) {
|
||||
return MINING_FATIGUE;
|
||||
}
|
||||
else if(c.equals("strength"))
|
||||
{
|
||||
} else if(c.equals("strength")) {
|
||||
return STRENGTH;
|
||||
}
|
||||
else if(c.equals("jump_boost"))
|
||||
{
|
||||
} else if(c.equals("jump_boost")) {
|
||||
return JUMP_BOOST;
|
||||
}
|
||||
else if(c.equals("nausea"))
|
||||
{
|
||||
} else if(c.equals("nausea")) {
|
||||
return NAUSEA;
|
||||
}
|
||||
else if(c.equals("regeneration"))
|
||||
{
|
||||
} else if(c.equals("regeneration")) {
|
||||
return REGENERATION;
|
||||
}
|
||||
else if(c.equals("resistance"))
|
||||
{
|
||||
} else if(c.equals("resistance")) {
|
||||
return RESISTANCE;
|
||||
}
|
||||
else if(c.equals("fire_resistance"))
|
||||
{
|
||||
} else if(c.equals("fire_resistance")) {
|
||||
return FIRE_RESISTANCE;
|
||||
}
|
||||
else if(c.equals("water_breathing"))
|
||||
{
|
||||
} else if(c.equals("water_breathing")) {
|
||||
return WATER_BREATHING;
|
||||
}
|
||||
else if(c.equals("invisibility"))
|
||||
{
|
||||
} else if(c.equals("invisibility")) {
|
||||
return INVISIBILITY;
|
||||
}
|
||||
else if(c.equals("blindness") || c.equals("blind"))
|
||||
{
|
||||
} else if(c.equals("blindness") || c.equals("blind")) {
|
||||
return BLINDNESS;
|
||||
}
|
||||
else if(c.equals("night_vision"))
|
||||
{
|
||||
} else if(c.equals("night_vision")) {
|
||||
return NIGHT_VISION;
|
||||
}
|
||||
else if(c.equals("hunger"))
|
||||
{
|
||||
} else if(c.equals("hunger")) {
|
||||
return HUNGER;
|
||||
}
|
||||
else if(c.equals("weakness"))
|
||||
{
|
||||
} else if(c.equals("weakness")) {
|
||||
return WEAKNESS;
|
||||
}
|
||||
else if(c.equals("poison"))
|
||||
{
|
||||
} else if(c.equals("poison")) {
|
||||
return POISON;
|
||||
}
|
||||
else if(c.equals("wither"))
|
||||
{
|
||||
} else if(c.equals("wither")) {
|
||||
return WITHER;
|
||||
}
|
||||
else if(c.equals("absorption"))
|
||||
{
|
||||
} else if(c.equals("health_boost")) {
|
||||
return HEALTH_BOOST;
|
||||
} else if(c.equals("absorption")) {
|
||||
return ABSORPTION;
|
||||
}
|
||||
else if(c.equals("saturation"))
|
||||
{
|
||||
} else if(c.equals("saturation")) {
|
||||
return SATURATION;
|
||||
}
|
||||
else if(c.equals("glowing"))
|
||||
{
|
||||
} else if(c.equals("glowing")) {
|
||||
return GLOWING;
|
||||
}
|
||||
else if(c.equals("levitation"))
|
||||
{
|
||||
} else if(c.equals("levitation")) {
|
||||
return LEVITATION;
|
||||
}
|
||||
else if(c.equals("luck"))
|
||||
{
|
||||
} else if(c.equals("luck")) {
|
||||
return LUCK;
|
||||
}
|
||||
else if(c.equals("unluck"))
|
||||
{
|
||||
} else if(c.equals("unluck")) {
|
||||
return UNLUCK;
|
||||
}
|
||||
else if(c.equals("fire"))
|
||||
{
|
||||
} else if(c.equals("slow_falling")) {
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +165,8 @@ public class EntityInfo
|
|||
return "poison";
|
||||
case WITHER:
|
||||
return "wither";
|
||||
case HEALTH_BOOST:
|
||||
return "health_boost";
|
||||
case ABSORPTION:
|
||||
return "absorption";
|
||||
case SATURATION:
|
||||
|
@ -213,6 +179,14 @@ public class EntityInfo
|
|||
return "luck";
|
||||
case 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:
|
||||
return "fire";
|
||||
default:
|
||||
|
@ -220,63 +194,71 @@ public class EntityInfo
|
|||
}
|
||||
}
|
||||
|
||||
public PotionEffect getPotionEffect()
|
||||
public EffectInstance getPotionEffect()
|
||||
{
|
||||
return getPotionEffect(20 * 7, 0);
|
||||
}
|
||||
|
||||
public PotionEffect getPotionEffect(int duration, int amplifier)
|
||||
{
|
||||
switch(this)
|
||||
{
|
||||
public EffectInstance getPotionEffect(int duration, int amplifier) {
|
||||
switch(this) {
|
||||
case SPEED:
|
||||
return new PotionEffect(MobEffects.SPEED, duration, amplifier);
|
||||
return new EffectInstance(Effects.SPEED, duration, amplifier);
|
||||
case SLOW:
|
||||
return new PotionEffect(MobEffects.SLOWNESS, duration, amplifier);
|
||||
return new EffectInstance(Effects.SLOWNESS, duration, amplifier);
|
||||
case HASTE:
|
||||
return new PotionEffect(MobEffects.HASTE, duration, amplifier);
|
||||
return new EffectInstance(Effects.HASTE, duration, amplifier);
|
||||
case MINING_FATIGUE:
|
||||
return new PotionEffect(MobEffects.MINING_FATIGUE, duration, amplifier);
|
||||
return new EffectInstance(Effects.MINING_FATIGUE, duration, amplifier);
|
||||
case STRENGTH:
|
||||
return new PotionEffect(MobEffects.STRENGTH, duration, amplifier);
|
||||
return new EffectInstance(Effects.STRENGTH, duration, amplifier);
|
||||
case JUMP_BOOST:
|
||||
return new PotionEffect(MobEffects.JUMP_BOOST, duration, amplifier);
|
||||
return new EffectInstance(Effects.JUMP_BOOST, duration, amplifier);
|
||||
case NAUSEA:
|
||||
return new PotionEffect(MobEffects.NAUSEA, duration, amplifier);
|
||||
return new EffectInstance(Effects.NAUSEA, duration, amplifier);
|
||||
case REGENERATION:
|
||||
return new PotionEffect(MobEffects.REGENERATION, duration, amplifier);
|
||||
return new EffectInstance(Effects.REGENERATION, duration, amplifier);
|
||||
case RESISTANCE:
|
||||
return new PotionEffect(MobEffects.RESISTANCE, duration, amplifier);
|
||||
return new EffectInstance(Effects.RESISTANCE, duration, amplifier);
|
||||
case FIRE_RESISTANCE:
|
||||
return new PotionEffect(MobEffects.FIRE_RESISTANCE, duration, amplifier);
|
||||
return new EffectInstance(Effects.FIRE_RESISTANCE, duration, amplifier);
|
||||
case WATER_BREATHING:
|
||||
return new PotionEffect(MobEffects.WATER_BREATHING, duration, amplifier);
|
||||
return new EffectInstance(Effects.WATER_BREATHING, duration, amplifier);
|
||||
case INVISIBILITY:
|
||||
return new PotionEffect(MobEffects.INVISIBILITY, duration, amplifier);
|
||||
return new EffectInstance(Effects.INVISIBILITY, duration, amplifier);
|
||||
case BLINDNESS:
|
||||
return new PotionEffect(MobEffects.BLINDNESS, duration, amplifier);
|
||||
return new EffectInstance(Effects.BLINDNESS, duration, amplifier);
|
||||
case NIGHT_VISION:
|
||||
return new PotionEffect(MobEffects.NIGHT_VISION, duration, amplifier);
|
||||
return new EffectInstance(Effects.NIGHT_VISION, duration, amplifier);
|
||||
case HUNGER:
|
||||
return new PotionEffect(MobEffects.HUNGER, duration, amplifier);
|
||||
return new EffectInstance(Effects.HUNGER, duration, amplifier);
|
||||
case WEAKNESS:
|
||||
return new PotionEffect(MobEffects.WEAKNESS, duration, amplifier);
|
||||
return new EffectInstance(Effects.WEAKNESS, duration, amplifier);
|
||||
case POISON:
|
||||
return new PotionEffect(MobEffects.POISON, duration, amplifier);
|
||||
return new EffectInstance(Effects.POISON, duration, amplifier);
|
||||
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:
|
||||
return new PotionEffect(MobEffects.ABSORPTION, duration, amplifier);
|
||||
return new EffectInstance(Effects.ABSORPTION, duration, amplifier);
|
||||
case SATURATION:
|
||||
return new PotionEffect(MobEffects.SATURATION, duration, amplifier);
|
||||
return new EffectInstance(Effects.SATURATION, duration, amplifier);
|
||||
case GLOWING:
|
||||
return new PotionEffect(MobEffects.GLOWING, duration, amplifier);
|
||||
return new EffectInstance(Effects.GLOWING, duration, amplifier);
|
||||
case LEVITATION:
|
||||
return new PotionEffect(MobEffects.LEVITATION, duration, amplifier);
|
||||
return new EffectInstance(Effects.LEVITATION, duration, amplifier);
|
||||
case LUCK:
|
||||
return new PotionEffect(MobEffects.LUCK, duration, amplifier);
|
||||
return new EffectInstance(Effects.LUCK, duration, amplifier);
|
||||
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:
|
||||
// FIRE is not a PotionEffect and must be applied directly to the Entity
|
||||
return null;
|
||||
|
@ -285,12 +267,12 @@ public class EntityInfo
|
|||
}
|
||||
}
|
||||
|
||||
public void applyEffectToEntity(EntityLivingBase entity)
|
||||
public void applyEffectToEntity(LivingEntity entity)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -343,6 +325,8 @@ public class EntityInfo
|
|||
return "poisoned";
|
||||
case WITHER:
|
||||
return "withered";
|
||||
case HEALTH_BOOST:
|
||||
return "given more health";
|
||||
case ABSORPTION:
|
||||
return "given absorption";
|
||||
case SATURATION:
|
||||
|
@ -355,6 +339,12 @@ public class EntityInfo
|
|||
return "given luck";
|
||||
case UNLUCK:
|
||||
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:
|
||||
return "set on fire";
|
||||
default:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
public class PlayerJoinEventHandler
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ public class PlayerJoinEventHandler
|
|||
{
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -1,99 +1,122 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common;
|
||||
|
||||
import com.seodisparate.TurnBasedMinecraft.client.ClientProxy;
|
||||
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 net.minecraftforge.common.MinecraftForge;
|
||||
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)
|
||||
@Mod(value = TurnBasedMinecraftMod.MODID)
|
||||
public class TurnBasedMinecraftMod
|
||||
{
|
||||
public static final String MODID = "com.seodisparate.turnbasedminecraft";
|
||||
public static final String NAME = "Turn Based Minecraft Mod";
|
||||
public static final String VERSION = "1.8";
|
||||
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_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 MUSIC_ROOT = CONFIG_DIRECTORY + "Music/";
|
||||
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
|
||||
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
|
||||
|
||||
public static final SimpleNetworkWrapper NWINSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("seodisparate.tbmc");
|
||||
protected static Logger logger;
|
||||
private static int packetHandlerID = 0;
|
||||
private static final String PROTOCOL_VERSION = Integer.toString(1);
|
||||
private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel");
|
||||
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 CommonProxy proxy;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
logger = event.getModLog();
|
||||
proxy.setLogger(logger);
|
||||
public static ResourceLocation getNetResourceLocation() {
|
||||
return HANDLER_ID;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
public static SimpleChannel getHandler() {
|
||||
return HANDLER;
|
||||
}
|
||||
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@SubscribeEvent
|
||||
public void firstInit(FMLCommonSetupEvent event)
|
||||
{
|
||||
proxy = DistExecutor.runForDist(()->()->new ClientProxy(), ()->()->new CommonProxy());
|
||||
proxy.initialize();
|
||||
proxy.setLogger(logger);
|
||||
|
||||
// register packets
|
||||
NWINSTANCE.registerMessage(
|
||||
PacketBattleInfo.HandlerBattleInfo.class,
|
||||
PacketBattleInfo.class,
|
||||
packetHandlerID++,
|
||||
Side.CLIENT);
|
||||
NWINSTANCE.registerMessage(
|
||||
PacketBattleRequestInfo.HandlerBattleRequestInfo.class,
|
||||
PacketBattleRequestInfo.class,
|
||||
packetHandlerID++,
|
||||
Side.SERVER);
|
||||
NWINSTANCE.registerMessage(
|
||||
PacketBattleDecision.HandleBattleDecision.class,
|
||||
PacketBattleDecision.class,
|
||||
packetHandlerID++,
|
||||
Side.SERVER);
|
||||
NWINSTANCE.registerMessage(
|
||||
PacketBattleMessage.HandlerBattleMessage.class,
|
||||
PacketBattleMessage.class,
|
||||
packetHandlerID++,
|
||||
Side.CLIENT);
|
||||
NWINSTANCE.registerMessage(
|
||||
PacketGeneralMessage.HandlerGeneralMessage.class,
|
||||
PacketGeneralMessage.class,
|
||||
packetHandlerID++,
|
||||
Side.CLIENT);
|
||||
NWINSTANCE.registerMessage(
|
||||
PacketEditingMessage.HandlerEditingMessage.class,
|
||||
PacketEditingMessage.class,
|
||||
packetHandlerID++,
|
||||
Side.CLIENT
|
||||
);
|
||||
int packetHandlerID = 0;
|
||||
HANDLER.registerMessage(
|
||||
packetHandlerID++,
|
||||
PacketBattleInfo.class,
|
||||
PacketBattleInfo::encode,
|
||||
PacketBattleInfo::decode,
|
||||
PacketBattleInfo.Handler::handle);
|
||||
HANDLER.registerMessage(
|
||||
packetHandlerID++,
|
||||
PacketBattleRequestInfo.class,
|
||||
PacketBattleRequestInfo::encode,
|
||||
PacketBattleRequestInfo::decode,
|
||||
PacketBattleRequestInfo.Handler::handle);
|
||||
HANDLER.registerMessage(
|
||||
packetHandlerID++,
|
||||
PacketBattleDecision.class,
|
||||
PacketBattleDecision::encode,
|
||||
PacketBattleDecision::decode,
|
||||
PacketBattleDecision.Handler::handle);
|
||||
HANDLER.registerMessage(
|
||||
packetHandlerID++,
|
||||
PacketBattleMessage.class,
|
||||
PacketBattleMessage::encode,
|
||||
PacketBattleMessage::decode,
|
||||
PacketBattleMessage.Handler::handle);
|
||||
HANDLER.registerMessage(
|
||||
packetHandlerID++,
|
||||
PacketGeneralMessage.class,
|
||||
PacketGeneralMessage::encode,
|
||||
PacketGeneralMessage::decode,
|
||||
PacketGeneralMessage.Handler::handle);
|
||||
HANDLER.registerMessage(
|
||||
packetHandlerID++,
|
||||
PacketEditingMessage.class,
|
||||
PacketEditingMessage::encode,
|
||||
PacketEditingMessage::decode,
|
||||
PacketEditingMessage.Handler::handle);
|
||||
|
||||
// register event handler(s)
|
||||
MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
@SubscribeEvent
|
||||
public void secondInitClient(FMLClientSetupEvent event)
|
||||
{
|
||||
proxy.postInit();
|
||||
proxy.postInit();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@SubscribeEvent
|
||||
public void secondInitServer(FMLDedicatedServerSetupEvent event)
|
||||
{
|
||||
proxy.postInit();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void serverStarting(FMLServerStartingEvent event)
|
||||
{
|
||||
logger.debug("About to initialize BattleManager");
|
||||
|
@ -113,7 +136,7 @@ public class TurnBasedMinecraftMod
|
|||
event.registerServerCommand(new CommandTBMEdit(proxy.getConfig()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@SubscribeEvent
|
||||
public void serverStopping(FMLServerStoppingEvent event)
|
||||
{
|
||||
logger.debug("About to cleanup BattleManager");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemArrow;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ArrowItem;
|
||||
|
||||
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)
|
||||
{
|
||||
if(player.inventory.getStackInSlot(i).getItem() instanceof ItemArrow)
|
||||
if(player.inventory.getStackInSlot(i).getItem() instanceof ArrowItem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.seodisparate.TurnBasedMinecraft.common.Battle;
|
||||
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||
import com.seodisparate.TurnBasedMinecraft.common.Battle.Decision;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
public class PacketBattleDecision implements IMessage
|
||||
public class PacketBattleDecision
|
||||
{
|
||||
private int battleID;
|
||||
private Battle.Decision decision;
|
||||
|
@ -25,34 +25,27 @@ public class PacketBattleDecision implements IMessage
|
|||
this.targetIDOrItemID = targetIDOrItemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
battleID = buf.readInt();
|
||||
decision = Decision.valueOf(buf.readInt());
|
||||
targetIDOrItemID = buf.readInt();
|
||||
public static void encode(PacketBattleDecision pkt, PacketBuffer buf) {
|
||||
buf.writeInt(pkt.battleID);
|
||||
buf.writeInt(pkt.decision.getValue());
|
||||
buf.writeInt(pkt.targetIDOrItemID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(battleID);
|
||||
buf.writeInt(decision.getValue());
|
||||
buf.writeInt(targetIDOrItemID);
|
||||
public static PacketBattleDecision decode(PacketBuffer buf) {
|
||||
return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
|
||||
}
|
||||
|
||||
public static class HandleBattleDecision implements IMessageHandler<PacketBattleDecision, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(PacketBattleDecision message, MessageContext ctx)
|
||||
{
|
||||
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID);
|
||||
if(b != null)
|
||||
{
|
||||
EntityPlayerMP player = ctx.getServerHandler().player;
|
||||
b.setDecision(player.getEntityId(), message.decision, message.targetIDOrItemID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static class Handler {
|
||||
public static void handle(final PacketBattleDecision pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
|
||||
if(b != null)
|
||||
{
|
||||
ServerPlayerEntity player = ctx.get().getSender();
|
||||
b.setDecision(player.getEntityId(), pkt.decision, pkt.targetIDOrItemID);
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,16 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
public class PacketBattleInfo implements IMessage
|
||||
public class PacketBattleInfo
|
||||
{
|
||||
private Collection<Integer> sideA;
|
||||
private Collection<Integer> sideB;
|
||||
|
@ -32,67 +31,61 @@ public class PacketBattleInfo implements IMessage
|
|||
this.decisionNanos = decisionNanos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
int sideACount = buf.readInt();
|
||||
int sideBCount = buf.readInt();
|
||||
for(int i = 0; i < sideACount; ++i)
|
||||
{
|
||||
sideA.add(buf.readInt());
|
||||
}
|
||||
for(int i = 0; i < sideBCount; ++i)
|
||||
{
|
||||
sideB.add(buf.readInt());
|
||||
}
|
||||
decisionNanos = buf.readLong();
|
||||
public static void encode(PacketBattleInfo pkt, PacketBuffer buf) {
|
||||
buf.writeInt(pkt.sideA.size());
|
||||
buf.writeInt(pkt.sideB.size());
|
||||
for(Integer id : pkt.sideA) {
|
||||
buf.writeInt(id);
|
||||
}
|
||||
for(Integer id : pkt.sideB) {
|
||||
buf.writeInt(id);
|
||||
}
|
||||
buf.writeLong(pkt.decisionNanos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(sideA.size());
|
||||
buf.writeInt(sideB.size());
|
||||
for(Integer id : sideA)
|
||||
{
|
||||
buf.writeInt(id);
|
||||
}
|
||||
for(Integer id : sideB)
|
||||
{
|
||||
buf.writeInt(id);
|
||||
}
|
||||
buf.writeLong(decisionNanos);
|
||||
public static PacketBattleInfo decode(PacketBuffer buf) {
|
||||
int sideACount = buf.readInt();
|
||||
int sideBCount = buf.readInt();
|
||||
Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
|
||||
Collection<Integer> sideB = new ArrayList<Integer>(sideBCount);
|
||||
for(int i = 0; i < sideACount; ++i) {
|
||||
sideA.add(buf.readInt());
|
||||
}
|
||||
for(int i = 0; i < sideBCount; ++i) {
|
||||
sideB.add(buf.readInt());
|
||||
}
|
||||
long decisionNanos = buf.readLong();
|
||||
return new PacketBattleInfo(sideA, sideB, decisionNanos);
|
||||
}
|
||||
|
||||
public static class HandlerBattleInfo implements IMessageHandler<PacketBattleInfo, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(PacketBattleInfo message, MessageContext ctx)
|
||||
{
|
||||
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)
|
||||
public static class Handler {
|
||||
public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(Integer id : message.sideB)
|
||||
{
|
||||
Entity e = Minecraft.getMinecraft().world.getEntityByID(id);
|
||||
if(e != null)
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
|
||||
for(Integer id : pkt.sideA)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
|
||||
Entity e = Minecraft.getInstance().world.getEntityByID(id);
|
||||
if(e != null)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(message.decisionNanos / 1000000000L));
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
||||
return null;
|
||||
}
|
||||
for(Integer id : pkt.sideB)
|
||||
{
|
||||
Entity e = Minecraft.getInstance().world.getEntityByID(id);
|
||||
if(e != null)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
|
||||
}
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,19 +2,15 @@ package com.seodisparate.TurnBasedMinecraft.common.networking;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.scoreboard.ScorePlayerTeam;
|
||||
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;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
public class PacketBattleMessage implements IMessage
|
||||
public class PacketBattleMessage
|
||||
{
|
||||
public enum MessageType
|
||||
{
|
||||
|
@ -125,221 +121,174 @@ public class PacketBattleMessage implements IMessage
|
|||
this.custom = custom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
messageType = MessageType.valueOf(buf.readInt());
|
||||
entityIDFrom = buf.readInt();
|
||||
entityIDTo = buf.readInt();
|
||||
amount = buf.readInt();
|
||||
custom = ByteBufUtils.readUTF8String(buf);
|
||||
public static void encode(PacketBattleMessage pkt, PacketBuffer buf) {
|
||||
buf.writeInt(pkt.messageType.getValue());
|
||||
buf.writeInt(pkt.entityIDFrom);
|
||||
buf.writeInt(pkt.entityIDTo);
|
||||
buf.writeInt(pkt.amount);
|
||||
buf.writeString(pkt.custom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(messageType.getValue());
|
||||
buf.writeInt(entityIDFrom);
|
||||
buf.writeInt(entityIDTo);
|
||||
buf.writeInt(amount);
|
||||
ByteBufUtils.writeUTF8String(buf, custom);
|
||||
public static PacketBattleMessage decode(PacketBuffer buf) {
|
||||
return new PacketBattleMessage(
|
||||
MessageType.valueOf(
|
||||
buf.readInt()),
|
||||
buf.readInt(),
|
||||
buf.readInt(),
|
||||
buf.readInt(),
|
||||
buf.readString());
|
||||
}
|
||||
|
||||
public static class HandlerBattleMessage implements IMessageHandler<PacketBattleMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(PacketBattleMessage message, MessageContext ctx)
|
||||
{
|
||||
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);
|
||||
public static class Handler {
|
||||
public static void handle(final PacketBattleMessage pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Entity fromEntity = TurnBasedMinecraftMod.proxy.getEntityByID(pkt.entityIDFrom);
|
||||
String from = "Unknown";
|
||||
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();
|
||||
}
|
||||
else if(fromEntity instanceof EntityPlayer)
|
||||
{
|
||||
from = ScorePlayerTeam.formatPlayerName(fromEntity.getTeam(), fromEntity.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
from = fromEntity.getName();
|
||||
from = fromEntity.getDisplayName().getFormattedText();
|
||||
}
|
||||
}
|
||||
}
|
||||
Entity toEntity = TurnBasedMinecraftMod.proxy.getEntityByID(message.entityIDTo);
|
||||
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);
|
||||
Entity toEntity = TurnBasedMinecraftMod.proxy.getEntityByID(pkt.entityIDTo);
|
||||
String to = "Unknown";
|
||||
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();
|
||||
}
|
||||
else if(toEntity instanceof EntityPlayer)
|
||||
{
|
||||
to = ScorePlayerTeam.formatPlayerName(toEntity.getTeam(), toEntity.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
to = toEntity.getName();
|
||||
to = toEntity.getDisplayName().getFormattedText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch(message.messageType)
|
||||
{
|
||||
case ENTERED:
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!");
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != message.amount)
|
||||
switch(pkt.messageType)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.createLocalBattle(message.amount);
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.battleStarted();
|
||||
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)
|
||||
case ENTERED:
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " entered battle!");
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != pkt.amount)
|
||||
{
|
||||
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
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " tried to consume an invalid item and failed!");
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " tried to flee battle but failed!");
|
||||
}
|
||||
break;
|
||||
case USED_FOOD:
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " ate a " + message.custom + "!");
|
||||
case DIED:
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " died in battle!");
|
||||
TurnBasedMinecraftMod.proxy.typeLeftBattle(pkt.custom);
|
||||
break;
|
||||
case USED_POTION:
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " drank a " + message.custom + "!");
|
||||
case ENDED:
|
||||
TurnBasedMinecraftMod.proxy.displayString("Battle has ended!");
|
||||
TurnBasedMinecraftMod.proxy.battleEnded();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TURN_BEGIN:
|
||||
TurnBasedMinecraftMod.proxy.displayString("The turn begins!");
|
||||
TurnBasedMinecraftMod.proxy.battleGuiTurnBegin();
|
||||
break;
|
||||
case TURN_END:
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() != null)
|
||||
{
|
||||
if(message.amount == 0)
|
||||
case ATTACK:
|
||||
TurnBasedMinecraftMod.proxy.displayString(from + " attacked " + to + " and dealt " + pkt.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 " + pkt.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(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
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.seodisparate.TurnBasedMinecraft.common.Battle;
|
||||
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
public class PacketBattleRequestInfo implements IMessage
|
||||
public class PacketBattleRequestInfo
|
||||
{
|
||||
private int battleID;
|
||||
|
||||
|
@ -19,29 +20,24 @@ public class PacketBattleRequestInfo implements IMessage
|
|||
this.battleID = battleID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
battleID = buf.readInt();
|
||||
public static void encode(PacketBattleRequestInfo pkt, PacketBuffer buf) {
|
||||
buf.writeInt(pkt.battleID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(battleID);
|
||||
public static PacketBattleRequestInfo decode(PacketBuffer buf) {
|
||||
return new PacketBattleRequestInfo(buf.readInt());
|
||||
}
|
||||
|
||||
public static class HandlerBattleRequestInfo implements IMessageHandler<PacketBattleRequestInfo, PacketBattleInfo>
|
||||
{
|
||||
@Override
|
||||
public PacketBattleInfo onMessage(PacketBattleRequestInfo message, MessageContext ctx)
|
||||
{
|
||||
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(message.battleID);
|
||||
if(b == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds());
|
||||
}
|
||||
public static class Handler {
|
||||
public static void handle(final PacketBattleRequestInfo pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
|
||||
if(b == null) {
|
||||
return;
|
||||
}
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()), ctx.get());
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,14 +1,13 @@
|
|||
package com.seodisparate.TurnBasedMinecraft.common.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.seodisparate.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
public class PacketGeneralMessage implements IMessage
|
||||
public class PacketGeneralMessage
|
||||
{
|
||||
String message;
|
||||
|
||||
|
@ -22,25 +21,20 @@ public class PacketGeneralMessage implements IMessage
|
|||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
message = ByteBufUtils.readUTF8String(buf);
|
||||
public static void encode(PacketGeneralMessage pkt, PacketBuffer buf) {
|
||||
buf.writeString(pkt.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
ByteBufUtils.writeUTF8String(buf, message);
|
||||
public static PacketGeneralMessage decode(PacketBuffer buf) {
|
||||
return new PacketGeneralMessage(buf.readString());
|
||||
}
|
||||
|
||||
public static class HandlerGeneralMessage implements IMessageHandler<PacketGeneralMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
public IMessage onMessage(PacketGeneralMessage message, MessageContext ctx)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.displayString(message.message);
|
||||
return null;
|
||||
}
|
||||
public static class Handler {
|
||||
public static void handle(final PacketGeneralMessage pkt, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
TurnBasedMinecraftMod.proxy.displayString(pkt.message);
|
||||
});
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Maven-Artifact: fr.delthas:javamp3:1.0.3
|
|
@ -1,12 +1,12 @@
|
|||
# Please do not change this option, the mod uses this to keep track of what new
|
||||
# changes to add to the config.
|
||||
version = 1
|
||||
version = 2
|
||||
|
||||
[client_config]
|
||||
|
||||
# determines what categories use what type of music.
|
||||
# Unknown categories sent by the server will default to "battle_music".
|
||||
# What categories play this type of music (battle_music). Unknown categories will default to this type.
|
||||
battle_music = ["monster", "animal", "boss", "player"]
|
||||
# What categories play this type of music (silly_music).
|
||||
silly_music = ["passive"]
|
||||
|
||||
# Minimum percentage of silly entities in battle to use silly music.
|
||||
|
@ -41,19 +41,23 @@ freeze_battle_combatants = false
|
|||
# Entity categories that will not initiate battle.
|
||||
ignore_battle_types = ["passive", "boss"]
|
||||
|
||||
# Stats that apply to all players
|
||||
# speed stat of all players in battle
|
||||
player_speed = 50
|
||||
# speed stat of all players under the effects of haste
|
||||
player_haste_speed = 80
|
||||
# speed stat of all players under the effects of slow
|
||||
player_slow_speed = 20
|
||||
# attack probability stat for all players
|
||||
player_attack_probability = 90
|
||||
# evasion stat for all players
|
||||
player_evasion = 10
|
||||
|
||||
# Number of attacks that a "defend" move will block
|
||||
defense_duration = 1
|
||||
|
||||
# If speed is greater than fastest speed of entity on opposing side, good
|
||||
# probability is used.
|
||||
# probability of fleeing from battle when speed is greater than fastest enemy's speed
|
||||
flee_good_probability = 90
|
||||
# probability of fleeing from battle when speed is less than fastest enemy's speed
|
||||
flee_bad_probability = 40
|
||||
|
||||
# Minimum hit percentage for everyone. If option is set to less than 1,
|
||||
|
|
Loading…
Reference in a new issue