Work on miner!

This commit is contained in:
Aidan Brady 2013-11-18 22:15:03 -05:00
parent 995207bcab
commit ba66b6fc9f
5 changed files with 250 additions and 32 deletions

View file

@ -133,7 +133,7 @@ public class Mekanism
public static Mekanism instance;
/** Mekanism hooks instance */
public static MekanismHooks hooks;
public static MekanismHooks hooks = new MekanismHooks();
/** Mekanism configuration instance */
public static Configuration configuration;
@ -1061,6 +1061,8 @@ public class Mekanism
System.out.println("[Mekanism] Detected Tekkit in root directory - hello, fellow user!");
}
MinecraftForge.EVENT_BUS.register(hooks);
//Register infuses
InfuseRegistry.registerInfuseType(new InfuseType("CARBON", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 0, 0));
InfuseRegistry.registerInfuseType(new InfuseType("TIN", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 4, 0));
@ -1070,7 +1072,6 @@ public class Mekanism
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
hooks = new MekanismHooks();
hooks.hook();
addIntegratedItems();

View file

@ -14,9 +14,11 @@ import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import thermalexpansion.api.crafting.CraftingManagers;
import thermalexpansion.api.crafting.IPulverizerRecipe;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
/**
* Hooks for Mekanism. Use to grab items or blocks out of different mods.
@ -120,31 +122,17 @@ public final class MekanismHooks
{
System.out.println("[Mekanism] Hooked into BuildCraft successfully.");
}
}
public void addPulverizerRecipe(ItemStack input, ItemStack output, int energy)
{
NBTTagCompound nbtTags = new NBTTagCompound();
if(TELoaded)
{
/*for(IPulverizerRecipe recipe : CraftingManagers.pulverizerManager.getRecipeList())
{
if(recipe.getSecondaryOutput() == null)
{
if(MekanismUtils.getName(recipe.getInput()).startsWith("ore"))
{
if(!Recipe.ENRICHMENT_CHAMBER.containsRecipe(recipe.getInput()))
{
RecipeHandler.addEnrichmentChamberRecipe(recipe.getInput(), recipe.getPrimaryOutput());
}
}
else if(MekanismUtils.getName(recipe.getInput()).startsWith("ingot"))
{
if(!Recipe.CRUSHER.containsRecipe(recipe.getInput()))
{
RecipeHandler.addCrusherRecipe(recipe.getInput(), recipe.getPrimaryOutput());
}
}
}
}*/
//TODO recipe integration
}
nbtTags.setInteger("energy", energy);
nbtTags.setCompoundTag("input", input.writeToNBT(new NBTTagCompound()));
nbtTags.setCompoundTag("primaryOutput", output.writeToNBT(new NBTTagCompound()));
FMLInterModComms.sendMessage("mekanism", "PulverizerRecipe", nbtTags);
}
public ItemStack getBuildCraftItem(String name)
@ -194,4 +182,40 @@ public final class MekanismHooks
return null;
}
}
@EventHandler
public void handleIMC(IMCEvent event)
{
for(IMCMessage message : event.getMessages())
{
try {
if(message.isNBTMessage())
{
if(message.key.equalsIgnoreCase("PulverizerRecipe") && !message.getNBTValue().hasKey("secondaryChance") && !message.getNBTValue().hasKey("secondaryOutput"))
{
ItemStack input = ItemStack.loadItemStackFromNBT(message.getNBTValue().getCompoundTag("input"));
ItemStack output = ItemStack.loadItemStackFromNBT(message.getNBTValue().getCompoundTag("output"));
if(input != null && output != null)
{
if(MekanismUtils.getName(input).startsWith("ore"))
{
if(!Recipe.ENRICHMENT_CHAMBER.containsRecipe(input))
{
RecipeHandler.addEnrichmentChamberRecipe(input, output);
}
}
else if(MekanismUtils.getName(input).startsWith("ingot"))
{
if(!Recipe.CRUSHER.containsRecipe(input))
{
RecipeHandler.addCrusherRecipe(input, output);
}
}
}
}
}
} catch(Exception e) {}
}
}
}

View file

@ -39,7 +39,6 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import codechicken.lib.raytracer.RayTracer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

View file

@ -1,11 +1,204 @@
package mekanism.common.tileentity;
import mekanism.common.block.BlockMachine.MachineType;
import ic2.api.energy.tile.IEnergySink;
public class TileEntityDigitalMiner extends TileEntityElectricBlock
import java.util.ArrayList;
import mekanism.api.Object3D;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.TileComponentUpgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityDigitalMiner extends TileEntityElectricBlock implements IEnergySink, IStrictEnergyAcceptor, IUpgradeTile, IRedstoneControl
{
public int radius;
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 28);
public TileEntityDigitalMiner()
{
super("Digital Miner", MachineType.DIGITAL_MINER.baseEnergy);
inventory = new ItemStack[29];
radius = 10;
}
@Override
public void onUpdate()
{
super.onUpdate();
if(!worldObj.isRemote)
{
ChargeUtils.discharge(27, this);
}
}
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
radius = nbtTags.getInteger("radius");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
}
@Override
public void writeToNBT(NBTTagCompound nbtTags)
{
super.writeToNBT(nbtTags);
nbtTags.setInteger("radius", radius);
nbtTags.setInteger("controlType", controlType.ordinal());
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
super.handlePacketData(dataStream);
radius = dataStream.readInt();
controlType = RedstoneControl.values()[dataStream.readInt()];
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
data.add(radius);
data.add(controlType.ordinal());
return data;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
return true;
}
public double demandedEnergyUnits()
{
return (getMaxEnergy() - getEnergy())*Mekanism.TO_IC2;
}
@Override
public double injectEnergyUnits(ForgeDirection direction, double amount)
{
if(Object3D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof TileEntityUniversalCable)
{
return amount;
}
double givenEnergy = amount*Mekanism.FROM_IC2;
double rejects = 0;
double neededEnergy = getMaxEnergy()-getEnergy();
if(givenEnergy < neededEnergy)
{
electricityStored += givenEnergy;
}
else if(givenEnergy > neededEnergy)
{
electricityStored += neededEnergy;
rejects = givenEnergy-neededEnergy;
}
return rejects*Mekanism.TO_IC2;
}
@Override
public int getMaxSafeInput()
{
return 2048;
}
@Override
public double transferEnergyToAcceptor(double amount)
{
double rejects = 0;
double neededGas = getMaxEnergy()-getEnergy();
if(amount <= neededGas)
{
electricityStored += amount;
}
else {
electricityStored += neededGas;
rejects = amount-neededGas;
}
return rejects;
}
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{
return true;
}
@Override
public RedstoneControl getControlType()
{
return controlType;
}
@Override
public void setControlType(RedstoneControl type)
{
controlType = type;
MekanismUtils.saveChunk(this);
}
@Override
public TileComponentUpgrade getComponent()
{
return upgradeComponent;
}
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
MekanismUtils.saveChunk(this);
}
@Override
public boolean supportsUpgrades(Object... data)
{
return true;
}
}

View file

@ -12,6 +12,7 @@ import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.Teleporter;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketPortalFX;
import mekanism.common.util.ChargeUtils;
import net.minecraft.entity.Entity;
@ -39,7 +40,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
public TileEntityTeleporter()
{
super("Teleporter", 1000000);
super("Teleporter", MachineType.TELEPORTER.baseEnergy);
inventory = new ItemStack[1];
code = new Teleporter.Code(0, 0, 0, 0);
}