Some API related work
This commit is contained in:
parent
a034a379c4
commit
d097a422a4
4 changed files with 167 additions and 27 deletions
35
common/com/pahimar/ee3/api/StackValueMapping.java
Normal file
35
common/com/pahimar/ee3/api/StackValueMapping.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package com.pahimar.ee3.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.pahimar.ee3.emc.EmcValue;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
public class StackValueMapping {
|
||||
|
||||
private static Gson gsonSerializer = new Gson();
|
||||
|
||||
public final CustomWrappedStack customWrappedStack;
|
||||
public final EmcValue emcValue;
|
||||
|
||||
public StackValueMapping(CustomWrappedStack customWrappedStack, EmcValue emcValue) {
|
||||
this.customWrappedStack = customWrappedStack;
|
||||
this.emcValue = emcValue;
|
||||
}
|
||||
|
||||
public static StackValueMapping createFromJson(String jsonStackValueMapping) {
|
||||
|
||||
try {
|
||||
return (StackValueMapping) gsonSerializer.fromJson(jsonStackValueMapping, StackValueMapping.class);
|
||||
}
|
||||
catch (JsonSyntaxException exception) {
|
||||
// TODO Log something regarding the failed parse
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return gsonSerializer.toJson(this);
|
||||
}
|
||||
}
|
|
@ -1,41 +1,55 @@
|
|||
package com.pahimar.ee3.core.handler;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.pahimar.ee3.EquivalentExchange3;
|
||||
import com.pahimar.ee3.api.StackValueMapping;
|
||||
import com.pahimar.ee3.emc.EmcRegistry;
|
||||
import com.pahimar.ee3.emc.EmcValue;
|
||||
import com.pahimar.ee3.emc.EmcValuesIMC;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
import com.pahimar.ee3.lib.InterModComms;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
|
||||
public class InterModCommsHandler {
|
||||
|
||||
// TODO Logging
|
||||
// TODO Tick handler to grab runtime messages
|
||||
|
||||
public static void processIMCMessages(IMCEvent event) {
|
||||
|
||||
for (IMCMessage imcMessage : event.getMessages()) {
|
||||
processIMCMessage(imcMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void processIMCMessage(IMCMessage imcMessage) {
|
||||
|
||||
String requestedOperation = imcMessage.key;
|
||||
|
||||
String requestedOperation = imcMessage.key;
|
||||
|
||||
if (requestedOperation.equalsIgnoreCase(InterModComms.RECIPE_ADD)) {
|
||||
processAddRecipeMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.BLACKLIST_ADD_ENTRY)) {
|
||||
processAddBlackListMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.BLACKLIST_REMOVE_ENTRY)) {
|
||||
processRemoveBlackListMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_ASSIGN_VALUE_PRE)) {
|
||||
processPreAssignEmcValueMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_ASSIGN_VALUE_POST)) {
|
||||
processPostAssignEmcValueMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_HAS_VALUE)) {
|
||||
processHasEmcValueMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_GET_VALUE)) {
|
||||
processGetEmcValueMessage(imcMessage);
|
||||
}
|
||||
if (requestedOperation.equalsIgnoreCase(InterModComms.RECIPE_ADD)) {
|
||||
processAddRecipeMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.BLACKLIST_ADD_ENTRY)) {
|
||||
processAddBlackListMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.BLACKLIST_REMOVE_ENTRY)) {
|
||||
processRemoveBlackListMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_ASSIGN_VALUE_PRE)) {
|
||||
processPreAssignEmcValueMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_ASSIGN_VALUE_POST)) {
|
||||
processPostAssignEmcValueMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_HAS_VALUE)) {
|
||||
processHasEmcValueMessage(imcMessage);
|
||||
}
|
||||
else if (requestedOperation.equalsIgnoreCase(InterModComms.EMC_GET_VALUE)) {
|
||||
processGetEmcValueMessage(imcMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,21 +70,104 @@ public class InterModCommsHandler {
|
|||
|
||||
private static void processPreAssignEmcValueMessage(IMCMessage imcMessage) {
|
||||
|
||||
// TODO
|
||||
if (imcMessage.getMessageType() == String.class) {
|
||||
|
||||
StackValueMapping stackValueMapping = StackValueMapping.createFromJson(imcMessage.getStringValue());
|
||||
|
||||
if (stackValueMapping != null) {
|
||||
|
||||
CustomWrappedStack customWrappedStack = stackValueMapping.customWrappedStack;
|
||||
EmcValue emcValue = stackValueMapping.emcValue;
|
||||
|
||||
EmcValuesIMC.addPreAssignedValued(customWrappedStack, emcValue);
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payloads json was invalid
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payload is of an invalid type
|
||||
}
|
||||
}
|
||||
|
||||
private static void processPostAssignEmcValueMessage(IMCMessage imcMessage) {
|
||||
|
||||
// TODO
|
||||
if (imcMessage.getMessageType() == String.class) {
|
||||
|
||||
StackValueMapping stackValueMapping = StackValueMapping.createFromJson(imcMessage.getStringValue());
|
||||
|
||||
if (stackValueMapping != null) {
|
||||
|
||||
CustomWrappedStack customWrappedStack = stackValueMapping.customWrappedStack;
|
||||
EmcValue emcValue = stackValueMapping.emcValue;
|
||||
|
||||
EmcValuesIMC.addPostAssignedValued(customWrappedStack, emcValue);
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payloads json was invalid
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payload is of an invalid type
|
||||
}
|
||||
}
|
||||
|
||||
private static void processHasEmcValueMessage(IMCMessage imcMessage) {
|
||||
|
||||
// TODO
|
||||
if (imcMessage.getMessageType() == String.class) {
|
||||
|
||||
// TODO What if it is an encoded ItemStack | OreStack | EnergyStack | FluidStack
|
||||
CustomWrappedStack customWrappedStack = CustomWrappedStack.createFromJson(imcMessage.getStringValue());
|
||||
|
||||
if (customWrappedStack != null) {
|
||||
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payloads json was invalid
|
||||
}
|
||||
}
|
||||
else if (imcMessage.getMessageType() == ItemStack.class) {
|
||||
|
||||
/*
|
||||
* Reply back to the mod that queried for the existance of an EmcValue for the given ItemStack
|
||||
*/
|
||||
FMLInterModComms.sendRuntimeMessage(EquivalentExchange3.instance, imcMessage.getSender(), InterModComms.EMC_RETURN_HAS_VALUE, String.valueOf(EmcRegistry.hasEmcValue(imcMessage.getItemStackValue())));
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payload is of an invalid type
|
||||
}
|
||||
}
|
||||
|
||||
private static void processGetEmcValueMessage(IMCMessage imcMessage) {
|
||||
|
||||
// TODO
|
||||
if (imcMessage.getMessageType() == String.class) {
|
||||
|
||||
// TODO What if it is an encoded ItemStack | OreStack | EnergyStack | FluidStack
|
||||
CustomWrappedStack customWrappedStack = CustomWrappedStack.createFromJson(imcMessage.getStringValue());
|
||||
|
||||
if (customWrappedStack != null) {
|
||||
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payloads json was invalid
|
||||
}
|
||||
}
|
||||
else if (imcMessage.getMessageType() == ItemStack.class) {
|
||||
|
||||
/*
|
||||
* Reply back to the mod that queried for the existance of an EmcValue for the given ItemStack
|
||||
*/
|
||||
EmcValue emcValue = EmcRegistry.getEmcValue(imcMessage.getItemStackValue());
|
||||
|
||||
if (emcValue != null) {
|
||||
FMLInterModComms.sendRuntimeMessage(EquivalentExchange3.instance, imcMessage.getSender(), InterModComms.EMC_RETURN_GET_VALUE, emcValue.toJson());
|
||||
}
|
||||
else {
|
||||
FMLInterModComms.sendRuntimeMessage(EquivalentExchange3.instance, imcMessage.getSender(), InterModComms.EMC_RETURN_GET_VALUE, "null");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO Log that the message payload is of an invalid type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@ public class EmcValuesIMC {
|
|||
if (!preAssignedValueMap.containsKey(wrappedStack)) {
|
||||
preAssignedValueMap.put(wrappedStack, emcValue);
|
||||
}
|
||||
else {
|
||||
// TODO Log that we already have a value for that
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPostAssignedValued(CustomWrappedStack wrappedStack, EmcValue emcValue) {
|
||||
|
@ -39,5 +42,8 @@ public class EmcValuesIMC {
|
|||
if (!postAssignedValueMap.containsKey(wrappedStack)) {
|
||||
postAssignedValueMap.put(wrappedStack, emcValue);
|
||||
}
|
||||
else {
|
||||
// TODO Log that we already have a value for that
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,5 +13,7 @@ public class InterModComms {
|
|||
public static final String EMC_ASSIGN_VALUE_PRE = "emc-assign-value-pre";
|
||||
public static final String EMC_ASSIGN_VALUE_POST = "emc-assign-value-post";
|
||||
public static final String EMC_HAS_VALUE = "emc-has-value";
|
||||
public static final String EMC_RETURN_HAS_VALUE = "emc-return-has-value";
|
||||
public static final String EMC_GET_VALUE = "emc-get-value";
|
||||
public static final String EMC_RETURN_GET_VALUE = "emc-return-get-value";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue