Add CraftTweaker support for the Marx generator
This commit is contained in:
parent
e200185235
commit
96aa3ec96a
|
@ -49,12 +49,18 @@ repositories {
|
|||
maven { // Albedo Lights
|
||||
url 'https://repo.elytradev.com/'
|
||||
}
|
||||
maven { // JEI & Tinkers
|
||||
name 'DVS1 Maven FS'
|
||||
url 'http://dvs1.progwml6.com/files/maven'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "net.industrial-craft:industrialcraft-2:2.8.+"
|
||||
deobfCompile "blusunrize:ImmersiveEngineering:0.12-+:deobf"
|
||||
deobfCompile 'elucent:albedo:2.0-SNAPSHOT'
|
||||
deobfCompile "mezz.jei:jei_1.12:4.+"
|
||||
deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package malte0811.industrialWires;
|
||||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.api.tool.ToolboxHandler;
|
||||
import ic2.api.item.IBoxable;
|
||||
import ic2.api.item.IC2Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ExtraIC2Compat {
|
||||
public static void addToolConmpat() {
|
||||
Item tinnedFood = IC2Items.getItem("filled_tin_can").getItem();
|
||||
ItemStack emptyMug = IC2Items.getItem("mug", "empty");
|
||||
ToolboxHandler.addFoodType((s)->s.getItem()==tinnedFood);
|
||||
ToolboxHandler.addFoodType((s)->
|
||||
s.getItem()==emptyMug.getItem()&&!ItemStack.areItemStacksEqual(emptyMug, ApiUtils.copyStackWithAmount(s, 1))
|
||||
);
|
||||
Item cable = IC2Items.getItem("cable", "type:copper,insulation:0").getItem();
|
||||
ToolboxHandler.addWiringType((s, w)->s.getItem()==cable);
|
||||
ToolboxHandler.addToolType((s)-> {
|
||||
Item a = s.getItem();
|
||||
return a instanceof IBoxable && ((IBoxable) a).canBeStoredInToolbox(s);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -26,8 +26,10 @@ import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE;
|
|||
import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
|
||||
import malte0811.industrialWires.blocks.hv.*;
|
||||
import malte0811.industrialWires.blocks.wire.*;
|
||||
import malte0811.industrialWires.compat.Compat;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import malte0811.industrialWires.crafting.Recipes;
|
||||
import malte0811.industrialWires.hv.MarxOreHandler;
|
||||
import malte0811.industrialWires.items.ItemIC2Coil;
|
||||
import malte0811.industrialWires.items.ItemKey;
|
||||
import malte0811.industrialWires.items.ItemPanelComponent;
|
||||
|
@ -40,7 +42,6 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
|
@ -128,6 +129,7 @@ public class IndustrialWires {
|
|||
MultiblockHandler.registerMultiblock(new MultiblockMarx());
|
||||
|
||||
proxy.preInit();
|
||||
Compat.preInit();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
@ -154,8 +156,7 @@ public class IndustrialWires {
|
|||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent e) {
|
||||
|
||||
ExtraIC2Compat.addToolConmpat();
|
||||
MarxOreHandler.init();
|
||||
|
||||
packetHandler.registerMessage(MessageTileSyncIW.HandlerClient.class, MessageTileSyncIW.class, 0, Side.CLIENT);
|
||||
packetHandler.registerMessage(MessagePanelInteract.HandlerServer.class, MessagePanelInteract.class, 1, Side.SERVER);
|
||||
|
|
|
@ -326,17 +326,14 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
|
|||
continue;
|
||||
}
|
||||
if (!world.isAirBlock(here)) {
|
||||
ItemStack input = state.getBlock().getPickBlock(state, null, world, here, null);
|
||||
if (!input.isEmpty()) {
|
||||
ItemStack[] out = MarxOreHandler.getYield(input, energyPerOre);
|
||||
for (ItemStack stack : out) {
|
||||
EntityItem item = new EntityItem(world, here.getX() + .5, here.getY() + .5, here.getZ() + .5, stack);
|
||||
final double maxMotion = .3;
|
||||
item.motionX = 2*maxMotion*(Utils.RAND.nextDouble()-.5);
|
||||
item.motionY = 2*maxMotion*(Utils.RAND.nextDouble()-.5);
|
||||
item.motionZ = 2*maxMotion*(Utils.RAND.nextDouble()-.5);
|
||||
world.spawnEntity(item);
|
||||
}
|
||||
ItemStack[] out = MarxOreHandler.getYield(world, here, energyPerOre);
|
||||
for (ItemStack stack : out) {
|
||||
EntityItem item = new EntityItem(world, here.getX() + .5, here.getY() + .5, here.getZ() + .5, stack);
|
||||
final double maxMotion = .3;
|
||||
item.motionX = 2 * maxMotion * (Utils.RAND.nextDouble() - .5);
|
||||
item.motionY = 2 * maxMotion * (Utils.RAND.nextDouble() - .5);
|
||||
item.motionZ = 2 * maxMotion * (Utils.RAND.nextDouble() - .5);
|
||||
world.spawnEntity(item);
|
||||
}
|
||||
world.setBlockToAir(here);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package malte0811.industrialWires.compat;
|
||||
|
||||
import crafttweaker.CraftTweakerAPI;
|
||||
import crafttweaker.IAction;
|
||||
import crafttweaker.api.block.IBlock;
|
||||
import crafttweaker.api.item.IItemStack;
|
||||
import crafttweaker.api.minecraft.CraftTweakerMC;
|
||||
import malte0811.industrialWires.hv.MarxOreHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ZenClass("mods.industrialwires.MarxGenerator")
|
||||
public class CTMarxGenerator {
|
||||
@ZenMethod
|
||||
public static void addRecipe(IBlock in, double avgRelEnergy, double maxMain, IItemStack outMain, @Optional int smallLargeRatio, @Optional IItemStack outSmall) {
|
||||
IBlock properIn;
|
||||
if (in instanceof IItemStack)
|
||||
properIn = ((IItemStack) in).asBlock();
|
||||
else
|
||||
properIn = in;
|
||||
if (!(properIn instanceof IBlock)) {
|
||||
throw new IllegalArgumentException("What did you pass to MarxGenerator.addRecipe?"+properIn);
|
||||
}
|
||||
Supplier<ItemStack> out = ()->CraftTweakerMC.getItemStack(outMain);
|
||||
Supplier<ItemStack> supSmall = ()->CraftTweakerMC.getItemStack(outSmall);
|
||||
CraftTweakerAPI.apply(new Add((world, pos)-> CraftTweakerMC.getBlock(world, pos.getX(), pos.getY(), pos.getZ()).matches(properIn),
|
||||
new MarxOreHandler.OreInfo(avgRelEnergy, maxMain, out, supSmall, smallLargeRatio)));
|
||||
}
|
||||
|
||||
private static class Add implements IAction {
|
||||
private final BiPredicate<World, BlockPos> isValid;
|
||||
private final MarxOreHandler.OreInfo output;
|
||||
|
||||
public Add(BiPredicate<World, BlockPos> isValid, MarxOreHandler.OreInfo output) {
|
||||
this.isValid = isValid;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
MarxOreHandler.put(isValid, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Adding Marx Generator Recipe for "+output.output.get();
|
||||
}
|
||||
}
|
||||
}
|
51
src/main/java/malte0811/industrialWires/compat/Compat.java
Normal file
51
src/main/java/malte0811/industrialWires/compat/Compat.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package malte0811.industrialWires.compat;
|
||||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.api.tool.ToolboxHandler;
|
||||
import crafttweaker.CraftTweakerAPI;
|
||||
import ic2.api.item.IBoxable;
|
||||
import ic2.api.item.IC2Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class Compat {
|
||||
private static final Compat INSTANCE = new Compat();
|
||||
|
||||
public static void preInit() {
|
||||
Method[] methods = Compat.class.getDeclaredMethods();
|
||||
for (Method m : methods) {
|
||||
if (m.getReturnType() == void.class && m.getParameterCount() == 0&&!m.getName().equals("preInit")) {
|
||||
try {
|
||||
m.invoke(INSTANCE);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "ic2")
|
||||
private void initIC2() {
|
||||
Item tinnedFood = IC2Items.getItem("filled_tin_can").getItem();
|
||||
ItemStack emptyMug = IC2Items.getItem("mug", "empty");
|
||||
ToolboxHandler.addFoodType((s) -> s.getItem() == tinnedFood);
|
||||
ToolboxHandler.addFoodType((s) ->
|
||||
s.getItem() == emptyMug.getItem() && !ItemStack.areItemStacksEqual(emptyMug, ApiUtils.copyStackWithAmount(s, 1))
|
||||
);
|
||||
Item cable = IC2Items.getItem("cable", "type:copper,insulation:0").getItem();
|
||||
ToolboxHandler.addWiringType((s, w) -> s.getItem() == cable);
|
||||
ToolboxHandler.addToolType((s) -> {
|
||||
Item a = s.getItem();
|
||||
return a instanceof IBoxable && ((IBoxable) a).canBeStoredInToolbox(s);
|
||||
});
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "crafttweaker")
|
||||
private void initCraftTweaker() {
|
||||
CraftTweakerAPI.registerClass(CTMarxGenerator.class);
|
||||
}
|
||||
}
|
|
@ -22,56 +22,80 @@ import blusunrize.immersiveengineering.api.ApiUtils;
|
|||
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
|
||||
import blusunrize.immersiveengineering.common.util.Utils;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MarxOreHandler {
|
||||
private static final Map<String, OreInfo> oreData = new HashMap<>();
|
||||
private static final List<Pair<BiPredicate<World, BlockPos>, OreInfo>> oreData = new ArrayList<>();
|
||||
private static double defaultEnergy = 100_000;
|
||||
public static double modifier;
|
||||
|
||||
private static void init() {
|
||||
public static void init() {
|
||||
// Vanilla ores
|
||||
oreData.put("oreIron", new OreInfo(.5, 4, "dustIron", "nuggetIron"));
|
||||
oreData.put("oreGold", new OreInfo(1, 4, "dustGold", "nuggetGold"));
|
||||
oreData.put("oreDiamond", new OreInfo(2, 4, "gemDiamond"));
|
||||
oreData.put("oreEmerald", new OreInfo(3, 4, "gemEmerald"));
|
||||
oreData.put("oreLapis", new OreInfo(.75, 10, "gemLapis"));
|
||||
oreData.put("oreCoal", new OreInfo(.75, 8, Items.COAL, 0));
|
||||
oreData.put("oreRedstone", new OreInfo(1, 12, "dustRedstone"));
|
||||
oreData.put("oreQuartz", new OreInfo(1, 6, "gemQuartz"));
|
||||
putOre("oreIron", new OreInfo(.5, 4, "dustIron", "nuggetIron"));
|
||||
putOre("oreGold", new OreInfo(1, 4, "dustGold", "nuggetGold"));
|
||||
putOre("oreDiamond", new OreInfo(2, 4, "gemDiamond"));
|
||||
putOre("oreEmerald", new OreInfo(3, 4, "gemEmerald"));
|
||||
putOre("oreLapis", new OreInfo(.75, 10, "gemLapis"));
|
||||
putOre("oreCoal", new OreInfo(.75, 8, Items.COAL, 0));
|
||||
putOre("oreRedstone", new OreInfo(1, 12, "dustRedstone"));
|
||||
putOre("oreQuartz", new OreInfo(1, 6, "gemQuartz"));
|
||||
// IE ores
|
||||
String[] ores = {"Copper", "Aluminum", "Lead", "Silver", "Nickel", "Tin"};
|
||||
for (String ore : ores) {
|
||||
oreData.put("ore" + ore, new OreInfo(.75, 4, "ingot" + ore, "nugget" + ore));
|
||||
putOre("ore" + ore, new OreInfo(.75, 4, "ingot" + ore, "nugget" + ore));
|
||||
}
|
||||
oreData.put("oreUranium", new OreInfo(1.25, 4, "crushedUranium", "nuggetUranium"));
|
||||
putOre("oreUranium", new OreInfo(1.25, 4, "crushedUranium", "nuggetUranium"));
|
||||
}
|
||||
|
||||
public static void putOre(String oreName, OreInfo info) {
|
||||
put((world, here)->{
|
||||
IBlockState state = world.getBlockState(here);
|
||||
ItemStack input = state.getBlock().getPickBlock(state, null, world, here, null);
|
||||
int[] ores = OreDictionary.getOreIDs(input);
|
||||
for (int id : ores) {
|
||||
String name = OreDictionary.getOreName(id);
|
||||
if (name.equals(oreName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}, info);
|
||||
}
|
||||
|
||||
public static void put(BiPredicate<World, BlockPos> isValid, MarxOreHandler.OreInfo output) {
|
||||
oreData.add(new ImmutablePair<>(isValid, output));
|
||||
}
|
||||
|
||||
public static void resetModifier() {
|
||||
modifier = MathHelper.clamp(Utils.RAND.nextGaussian()*.1+1, .9, 1.1);
|
||||
}
|
||||
|
||||
public static ItemStack[] getYield(ItemStack in, double energy) {
|
||||
if (oreData.isEmpty()) {
|
||||
init();
|
||||
}
|
||||
public static ItemStack[] getYield(World world, BlockPos pos, double energy) {
|
||||
if (modifier<.89||modifier>1.11) {
|
||||
IndustrialWires.logger.error("The energy-modifier for Marx generators wasn't loaded correctly. It will be reset.");
|
||||
resetModifier();
|
||||
}
|
||||
int[] ores = OreDictionary.getOreIDs(in);
|
||||
for (int id : ores) {
|
||||
String name = OreDictionary.getOreName(id);
|
||||
if (oreData.containsKey(name)) {
|
||||
OreInfo info = oreData.get(name);
|
||||
for (Pair<BiPredicate<World, BlockPos>, OreInfo> ore:oreData) {
|
||||
if (ore.getLeft().test(world, pos)) {
|
||||
OreInfo info = ore.getRight();
|
||||
double idealE = modifier * info.avgEnergy * defaultEnergy;
|
||||
if (energy >= .75 * idealE) {
|
||||
double sigma = idealE / 9;
|
||||
|
@ -79,23 +103,23 @@ public class MarxOreHandler {
|
|||
double out = dist * info.maxYield;
|
||||
int yield = (int) Math.floor(out);
|
||||
out -= yield;
|
||||
int yieldNuggets = (int) Math.round(out * 9);
|
||||
if (yieldNuggets >= 9 || (info.outputSmall == null && yieldNuggets >= 5)) {
|
||||
int yieldNuggets = (int) Math.round(out * info.smallMax);
|
||||
if (yieldNuggets >= info.smallMax || (info.outputSmall == null && yieldNuggets >= info.smallMax/2F)) {
|
||||
yield++;
|
||||
yieldNuggets = 0;
|
||||
}
|
||||
if (yield > 0 && yieldNuggets > 0 && info.outputSmall != null) {
|
||||
return new ItemStack[]{
|
||||
ApiUtils.copyStackWithAmount(info.output.getExampleStack(), yield),
|
||||
ApiUtils.copyStackWithAmount(info.outputSmall.getExampleStack(), yieldNuggets)
|
||||
ApiUtils.copyStackWithAmount(info.output.get(), yield),
|
||||
ApiUtils.copyStackWithAmount(info.outputSmall.get(), yieldNuggets)
|
||||
};
|
||||
} else if (yield > 0) {
|
||||
return new ItemStack[]{
|
||||
ApiUtils.copyStackWithAmount(info.output.getExampleStack(), yield)
|
||||
ApiUtils.copyStackWithAmount(info.output.get(), yield)
|
||||
};
|
||||
} else if (yieldNuggets > 0 && info.outputSmall != null) {
|
||||
return new ItemStack[]{
|
||||
ApiUtils.copyStackWithAmount(info.outputSmall.getExampleStack(), yieldNuggets)
|
||||
ApiUtils.copyStackWithAmount(info.outputSmall.get(), yieldNuggets)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -111,15 +135,25 @@ public class MarxOreHandler {
|
|||
public static class OreInfo {
|
||||
public final double avgEnergy;
|
||||
public final double maxYield;
|
||||
public final IngredientStack output;
|
||||
public final Supplier<ItemStack> output;
|
||||
@Nullable
|
||||
public final IngredientStack outputSmall;//1/9 of output
|
||||
public final Supplier<ItemStack> outputSmall;//1/9 of output
|
||||
public final int smallMax;
|
||||
|
||||
public OreInfo(double avg, double maxYield, Supplier<ItemStack> out, @Nullable Supplier<ItemStack> outSmall, int smallCount) {
|
||||
avgEnergy = avg;
|
||||
this.maxYield = maxYield;
|
||||
output = out;
|
||||
outputSmall = outSmall;
|
||||
smallMax = smallCount;
|
||||
}
|
||||
|
||||
public OreInfo(double avgEnergy, double maxYield, Item iOut, int mOut, @Nullable Item iOutSmall, int mOutSmall) {
|
||||
this.avgEnergy = avgEnergy;
|
||||
this.maxYield = maxYield;
|
||||
this.output = new IngredientStack(new ItemStack(iOut, 1, mOut));
|
||||
this.outputSmall = iOutSmall == null ? null : new IngredientStack(new ItemStack(iOutSmall, 1, mOutSmall));
|
||||
this.output = new IngredientStack(new ItemStack(iOut, 1, mOut))::getExampleStack;
|
||||
this.outputSmall = iOutSmall == null ? null : new IngredientStack(new ItemStack(iOutSmall, 1, mOutSmall))::getExampleStack;
|
||||
smallMax = 9;
|
||||
}
|
||||
|
||||
public OreInfo(double avgEnergy, double maxYield, Item iOut, int mOut) {
|
||||
|
@ -129,8 +163,9 @@ public class MarxOreHandler {
|
|||
public OreInfo(double avgEnergy, double maxYield, String oreOut, @Nullable String oreSmall) {
|
||||
this.avgEnergy = avgEnergy;
|
||||
this.maxYield = maxYield;
|
||||
this.output = new IngredientStack(oreOut);
|
||||
this.outputSmall = oreSmall == null ? null : new IngredientStack(oreSmall);
|
||||
this.output = new IngredientStack(oreOut)::getExampleStack;
|
||||
this.outputSmall = oreSmall == null ? null : new IngredientStack(oreSmall)::getExampleStack;
|
||||
smallMax = 9;
|
||||
}
|
||||
|
||||
public OreInfo(double avgEnergy, double maxYield, String oreOut) {
|
||||
|
|
Loading…
Reference in a new issue