start of basic IMC implementation for acidizers

This commit is contained in:
Boblet 2021-08-20 14:20:24 +02:00
parent 7cbc863e39
commit 4c95d1853a
6 changed files with 233 additions and 16 deletions

View File

@ -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));
}
}

View File

@ -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<AStack, List<Tuple.Pair<Mat, Double>>> 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<Mat, Double>... tuples) {
List<Tuple.Pair<Mat, Double>> 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);
}
}

View File

@ -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
}
}

View File

@ -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<String, IMCHandler> 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);
}

View File

@ -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<IMCMessage> 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

View File

@ -0,0 +1,116 @@
package com.hbm.util;
public class Tuple {
public static class Pair<X,Y> {
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,Y,Z> {
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;
}
}
}