cleanup, add recipe removal APIs and IMC messages

This commit is contained in:
asiekierka 2014-10-18 09:11:08 +02:00
parent c04224d466
commit b3e908d1ac
9 changed files with 59 additions and 32 deletions

View file

@ -85,13 +85,11 @@ public class GuiRequester extends GuiAdvancedInterface {
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
protected void slotClicked(AdvancedSlot slot, int mouseButton) {
super.slotClicked(slot, mouseButton);
RequestSlot slot = (RequestSlot) getSlotAtLocation(mouseX, mouseY);
if (slot != null) {
slot.setItem(mc.thePlayer.inventory.getItemStack());
if (slot instanceof RequestSlot) {
((RequestSlot) slot).setItem(mc.thePlayer.inventory.getItemStack());
}
}

View file

@ -53,20 +53,32 @@ public final class InterModComms {
} else if (m.key.equals("oil-gen-exclude")) {
processOilGenExcludeIMC(event, m);
} else if (m.key.equals("add-assembly-recipe")) {
processAssemblyRecipeIMC(event, m);
processAssemblyRecipeAddIMC(event, m);
} else if (m.key.equals("add-refinery-recipe")) {
processRefineryRecipeIMC(event, m);
processRefineryRecipeAddIMC(event, m);
} else if (m.key.equals("remove-assembly-recipe")) {
//TODO
processAssemblyRecipeRemoveIMC(event, m);
} else if (m.key.equals("remove-refinery-recipe")) {
//TODO
processRefineryRecipeRemoveIMC(event, m);
} else {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Received IMC message with unknown key('%s') from %s!", new Object[]{m.key, m.getSender()});
}
}
}
public static void processAssemblyRecipeIMC(IMCEvent event, IMCMessage msg) {
public static void processAssemblyRecipeRemoveIMC(IMCEvent event, IMCMessage msg) {
if (msg.isStringMessage()) {
AssemblyRecipeManager.INSTANCE.removeRecipe(msg.getStringValue());
}
}
public static void processRefineryRecipeRemoveIMC(IMCEvent event, IMCMessage msg) {
if (msg.isStringMessage()) {
RefineryRecipeManager.INSTANCE.removeRecipe(msg.getStringValue());
}
}
public static void processAssemblyRecipeAddIMC(IMCEvent event, IMCMessage msg) {
boolean failed = false;
if (!msg.isNBTMessage()) {
failed = true;
@ -98,7 +110,7 @@ public final class InterModComms {
}
}
public static void processRefineryRecipeIMC(IMCEvent event, IMCMessage msg) {
public static void processRefineryRecipeAddIMC(IMCEvent event, IMCMessage msg) {
boolean failed = false;
if (!msg.isNBTMessage()) {
failed = true;

View file

@ -128,7 +128,7 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft {
AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY);
if (slot != null && slot.isDefined()) {
slotClicked(slot);
slotClicked(slot, mouseButton);
}
}
@ -141,7 +141,7 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft {
}
// TODO: Use this for all children of this class
protected void slotClicked(AdvancedSlot slot) {
protected void slotClicked(AdvancedSlot slot, int mouseButton) {
}
}

View file

@ -14,7 +14,6 @@ import java.util.Map;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import buildcraft.BuildCraftCore;
import buildcraft.api.recipes.IAssemblyRecipeManager;
import buildcraft.api.recipes.IFlexibleRecipe;
@ -56,4 +55,14 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
public IFlexibleRecipe getRecipe(String id) {
return assemblyRecipes.get(id);
}
@Override
public void removeRecipe(IFlexibleRecipe<ItemStack> recipe) {
removeRecipe(recipe.getId());
}
@Override
public void removeRecipe(String id) {
assemblyRecipes.remove(id);
}
}

View file

@ -12,8 +12,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.BuildCraftCore;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.api.recipes.IRefineryRecipeManager;
@ -62,4 +62,14 @@ public final class RefineryRecipeManager implements IRefineryRecipeManager {
public IFlexibleRecipe<FluidStack> getRecipe(String id) {
return recipes.get(id);
}
@Override
public void removeRecipe(IFlexibleRecipe<FluidStack> recipe) {
removeRecipe(recipe.getId());
}
@Override
public void removeRecipe(String id) {
recipes.remove(id);
}
}

View file

@ -278,8 +278,8 @@ public class GuiScienceBook extends GuiAdvancedInterface {
}
@Override
protected void slotClicked(AdvancedSlot slot) {
super.slotClicked(slot);
protected void slotClicked(AdvancedSlot slot, int mouseButton) {
super.slotClicked(slot, mouseButton);
if (slot instanceof TechnologySlot) {
setFocus(((TechnologySlot) slot).techno);

View file

@ -23,7 +23,6 @@ public class GuiHopper extends GuiContainer {
public GuiHopper(InventoryPlayer inventory, TileHopper tile) {
super(new ContainerHopper(inventory, tile));
// TODO Auto-generated constructor stub
}
@Override

View file

@ -157,12 +157,12 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
protected void slotClicked(AdvancedSlot aslot, int mouseButton) {
super.slotClicked(aslot, mouseButton);
RecipeSlot slot = (RecipeSlot) getSlotAtLocation(i, j);
if (aslot instanceof RecipeSlot) {
RecipeSlot slot = (RecipeSlot) aslot;
if (slot != null) {
if (slot.crafting == null) {
return;
}

View file

@ -364,13 +364,12 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
@Override
protected void mouseClicked(int i, int j, int k) {
protected void slotClicked(AdvancedSlot slot, int mouseButton) {
if (gate == null) {
return;
}
super.mouseClicked(i, j, k);
AdvancedSlot slot = getSlotAtLocation(i, j);
super.slotClicked(slot, mouseButton);
if (slot instanceof TriggerSlot && container.hasTriggers()) {
TriggerSlot triggerSlot = (TriggerSlot) slot;
@ -379,14 +378,14 @@ public class GuiGateInterface extends GuiAdvancedInterface {
if (triggerSlot.getStatement() == null) {
if (k == 0) {
if (mouseButton == 0) {
changed = container.getFirstTrigger();
} else {
changed = container.getLastTrigger();
}
} else {
Iterator<ITrigger> it = container.getTriggerIterator(k != 0);
Iterator<ITrigger> it = container.getTriggerIterator(mouseButton != 0);
for (; it.hasNext();) {
ITrigger trigger = it.next();
@ -418,14 +417,14 @@ public class GuiGateInterface extends GuiAdvancedInterface {
IAction changed = null;
if (actionSlot.getStatement() == null) {
if (k == 0) {
if (mouseButton == 0) {
changed = container.getFirstAction();
} else {
changed = container.getLastAction();
}
} else {
Iterator<IAction> it = container.getActionIterator(k != 0);
Iterator<IAction> it = container.getActionIterator(mouseButton != 0);
for (; it.hasNext();) {
IAction action = it.next();