From 4c95d1853a871b89835201d0c282afb1a3d110d2 Mon Sep 17 00:00:00 2001 From: Boblet Date: Fri, 20 Aug 2021 14:20:24 +0200 Subject: [PATCH] start of basic IMC implementation for acidizers --- src/main/java/com/hbm/calc/EasyVector.java | 16 --- .../java/com/hbm/handler/HbmMaterials.java | 63 ++++++++++ .../com/hbm/handler/imc/IMCCrystallizer.java | 11 ++ .../java/com/hbm/handler/imc/IMCHandler.java | 20 +++ src/main/java/com/hbm/main/MainRegistry.java | 23 ++++ src/main/java/com/hbm/util/Tuple.java | 116 ++++++++++++++++++ 6 files changed, 233 insertions(+), 16 deletions(-) delete mode 100644 src/main/java/com/hbm/calc/EasyVector.java create mode 100644 src/main/java/com/hbm/handler/HbmMaterials.java create mode 100644 src/main/java/com/hbm/handler/imc/IMCCrystallizer.java create mode 100644 src/main/java/com/hbm/handler/imc/IMCHandler.java create mode 100644 src/main/java/com/hbm/util/Tuple.java diff --git a/src/main/java/com/hbm/calc/EasyVector.java b/src/main/java/com/hbm/calc/EasyVector.java deleted file mode 100644 index 5fa80d680..000000000 --- a/src/main/java/com/hbm/calc/EasyVector.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hbm.calc; - -public class EasyVector { - - public double a; - public double b; - - public EasyVector(double a, double b) { - this.a = a; - this.b = b; - } - - public double getResult() { - return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); - } -} diff --git a/src/main/java/com/hbm/handler/HbmMaterials.java b/src/main/java/com/hbm/handler/HbmMaterials.java new file mode 100644 index 000000000..33e6354e3 --- /dev/null +++ b/src/main/java/com/hbm/handler/HbmMaterials.java @@ -0,0 +1,63 @@ +package com.hbm.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import com.hbm.inventory.RecipesCommon.AStack; +import com.hbm.util.Tuple; + +import net.minecraft.item.ItemStack; + +/** + * Instead of registering all recycling recipes by hand like a bunch of morons, how about we assign some basic + * material values to basic items and then detect the rest based on recipes? + * @author hbm + * + */ +public class HbmMaterials { + + public static enum Mat { + IRON, + GOLD, + STEEL; + + private ItemStack recyclesInto; + + public void setRecycling(ItemStack recyclesInto) { + this.recyclesInto = recyclesInto; + } + + public ItemStack getRecycling() { + return recyclesInto.copy(); + } + } + + private static HashMap>> map = new HashMap(); //ACHIEVEMENT GET! Stack three generics inside of each other! + + /** + * Quickly adds our tuples to the map, or expands the list if it already exists + * @param stack + * @param tuples + */ + public static void registerItem(AStack stack, Tuple.Pair... tuples) { + + List> existing = map.get(stack); + + if(existing == null) + existing = new ArrayList(); + + existing.addAll(Arrays.asList(tuples)); + + map.put(stack, existing); + } + + /** + * Removes a tuple list from the map, to clear out unwanted auto-generated recipes + * @param stack + */ + public static void knockTuples(AStack stack) { + map.remove(stack); + } +} diff --git a/src/main/java/com/hbm/handler/imc/IMCCrystallizer.java b/src/main/java/com/hbm/handler/imc/IMCCrystallizer.java new file mode 100644 index 000000000..e925f5780 --- /dev/null +++ b/src/main/java/com/hbm/handler/imc/IMCCrystallizer.java @@ -0,0 +1,11 @@ +package com.hbm.handler.imc; + +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; + +public class IMCCrystallizer extends IMCHandler { + + @Override + public void process(IMCMessage message) { + //TODO + } +} diff --git a/src/main/java/com/hbm/handler/imc/IMCHandler.java b/src/main/java/com/hbm/handler/imc/IMCHandler.java new file mode 100644 index 000000000..e4892dee1 --- /dev/null +++ b/src/main/java/com/hbm/handler/imc/IMCHandler.java @@ -0,0 +1,20 @@ +package com.hbm.handler.imc; + +import java.util.HashMap; + +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; + +public abstract class IMCHandler { + + private static final HashMap handlers = new HashMap(); + + public static void registerHandler(String name, IMCHandler handler) { + handlers.put(name, handler); + } + + public static IMCHandler getHanlder(String name) { + return handlers.get(name); + } + + public abstract void process(IMCMessage message); +} \ No newline at end of file diff --git a/src/main/java/com/hbm/main/MainRegistry.java b/src/main/java/com/hbm/main/MainRegistry.java index a57b42dd9..49a593ed4 100644 --- a/src/main/java/com/hbm/main/MainRegistry.java +++ b/src/main/java/com/hbm/main/MainRegistry.java @@ -33,6 +33,7 @@ import java.util.Random; import org.apache.logging.log4j.Logger; +import com.google.common.collect.ImmutableList; import com.hbm.blocks.ModBlocks; import com.hbm.config.BombConfig; import com.hbm.config.GeneralConfig; @@ -56,6 +57,8 @@ import com.hbm.entity.particle.*; import com.hbm.entity.projectile.*; import com.hbm.handler.*; import com.hbm.handler.FluidTypeHandler.FluidType; +import com.hbm.handler.imc.IMCCrystallizer; +import com.hbm.handler.imc.IMCHandler; import com.hbm.handler.radiation.ChunkRadiationManager; import com.hbm.inventory.*; import com.hbm.items.ModItems; @@ -81,6 +84,8 @@ import com.hbm.world.generator.CellularDungeonFactory; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; @@ -1023,6 +1028,24 @@ public class MainRegistry { // MUST be initialized AFTER achievements!! BobmazonOfferFactory.init(); OreDictManager.registerOres(); + + IMCHandler.registerHandler("crystallizer", new IMCCrystallizer()); + } + + @EventHandler + public static void initIMC(IMCEvent event) { + + ImmutableList inbox = event.getMessages(); //tee-hee + + for(IMCMessage message : inbox) { + IMCHandler handler = IMCHandler.getHanlder(message.key); + + if(handler != null) { + handler.process(message); + } else { + MainRegistry.logger.error("Could not process unknown IMC type \"" + message.key + "\""); + } + } } @EventHandler diff --git a/src/main/java/com/hbm/util/Tuple.java b/src/main/java/com/hbm/util/Tuple.java new file mode 100644 index 000000000..d17185c15 --- /dev/null +++ b/src/main/java/com/hbm/util/Tuple.java @@ -0,0 +1,116 @@ +package com.hbm.util; + +public class Tuple { + + public static class Pair { + + X key; + Y value; + + public Pair(X x, Y y) { + this.key = x; + this.value = y; + } + + public X getKey() { + return this.key; + } + + public Y getValue() { + return this.value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(obj == null) + return false; + if(getClass() != obj.getClass()) + return false; + Pair other = (Pair) obj; + if(key == null) { + if(other.key != null) + return false; + } else if(!key.equals(other.key)) + return false; + if(value == null) { + if(other.value != null) + return false; + } else if(!value.equals(other.value)) + return false; + return true; + } + } + + public static class Triplet { + + X x; + Y y; + Z z; + + public Triplet(X x, Y y, Z z) { + this.x = x; + this.y = y; + this.z = z; + } + + public X getX() { + return this.x; + } + + public Y getY() { + return this.y; + } + + public Z getZ() { + return this.z; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((x == null) ? 0 : x.hashCode()); + result = prime * result + ((y == null) ? 0 : y.hashCode()); + result = prime * result + ((z == null) ? 0 : z.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) + return true; + if(obj == null) + return false; + if(getClass() != obj.getClass()) + return false; + Triplet other = (Triplet) obj; + if(x == null) { + if(other.x != null) + return false; + } else if(!x.equals(other.x)) + return false; + if(y == null) { + if(other.y != null) + return false; + } else if(!y.equals(other.y)) + return false; + if(z == null) { + if(other.z != null) + return false; + } else if(!z.equals(other.z)) + return false; + return true; + } + } +}