Misc cleanup, removed some comments on things I won't implement (for now)

This commit is contained in:
malte0811 2018-05-14 19:07:52 +02:00
parent a756de6ace
commit d5b537ea98
10 changed files with 79 additions and 46 deletions

View file

@ -28,11 +28,6 @@ import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
public interface IMBPartElectric {
/**
* If a section has more than one waveform (!=NONE) the generators are shorted (or worse), so it will:
* 1. Heat up the sources, possibly destroying them (TODO do I want to do that?)
* 2. Consume a lot of mechanical energy
*/
Waveform getProduced(MechEnergy state);
// All four in Joules
double getAvailableEEnergy();

View file

@ -81,11 +81,6 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
waveform = waveform.getCommutated(mechEnergy.getSpeed(), has4Phases());
wfToWorld = waveform;
bufferToWorld += given;
int available = (int) (Math.min(ConversionUtil.ifPerJoule() * bufferToWorld,
getMaxBuffer()/getEnergyConnections().size()));
if (available > 0 && wfToWorld.isAC()) {//The IC2 net will deal with DC by itself
bufferToWorld -= outputFE(world, available);
}//TODO move to mech!
}
@ -211,7 +206,12 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
}
@Override
public void insertMEnergy(double added) {}
public void insertMEnergy(double added) {int available = (int) (Math.min(ConversionUtil.ifPerJoule() * bufferToWorld,
getMaxBuffer()/getEnergyConnections().size()));
if (available > 0 && wfToWorld.isAC()) {//The IC2 net will deal with DC by itself
bufferToWorld -= outputFE(world, available);
}
}
@Override
public double getInertia() {
@ -227,16 +227,16 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
public void writeToNBT(NBTTagCompound out) {
out.setDouble(BUFFER_IN, bufferToMB);
out.setDouble(BUFFER_OUT, bufferToWorld);
out.setInteger(BUFFER_IN+WAVEFORM, wfToMB.getIndex());
out.setInteger(BUFFER_OUT+WAVEFORM, wfToWorld.getIndex());//TODO better way of doing this that doesn't break when I change anything
out.setString(BUFFER_IN+WAVEFORM, wfToMB.serializeToString());
out.setString(BUFFER_OUT+WAVEFORM, wfToWorld.serializeToString());
}
@Override
public void readFromNBT(NBTTagCompound in) {
bufferToMB = in.getDouble(BUFFER_IN);
bufferToWorld = in.getDouble(BUFFER_OUT);
wfToMB = Waveform.VALUES[in.getInteger(BUFFER_IN+WAVEFORM)];
wfToWorld = Waveform.VALUES[in.getInteger(BUFFER_OUT+WAVEFORM)];
wfToMB = Waveform.fromString(in.getString(BUFFER_IN+WAVEFORM));
wfToWorld = Waveform.fromString(in.getString(BUFFER_OUT+WAVEFORM));
}
@Override

View file

@ -42,7 +42,7 @@ public class MechPartShaft extends MechMBPart {
@Override
public double getInertia() {
return 5;//TODO
return 5;
}
@Override

View file

@ -75,7 +75,7 @@ public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
@Override
public void insertEEnergy(double given, Waveform waveform, MechEnergy energy) {
if (waveform.isDC()) {
bufferToMech = 0;//TODO something more spectacular
bufferToMech = 0;
} else {
bufferToMech += given;
}

View file

@ -101,7 +101,7 @@ public class MechPartSpeedometer extends MechMBPart implements IPlayerInteractio
@Override
public double getInertia() {
return 60;//TODO
return 60;
}
@Override

View file

@ -37,7 +37,10 @@ import java.util.Set;
import static blusunrize.immersiveengineering.common.IEContent.blockMetalDecoration0;
import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0.GENERATOR;
import static malte0811.industrialWires.converter.EUCapability.ENERGY_IC2;
import static malte0811.industrialWires.converter.Waveform.Phases.get;
import static malte0811.industrialWires.converter.Waveform.Speed.EXTERNAL;
import static malte0811.industrialWires.converter.Waveform.Type.DC;
import static malte0811.industrialWires.util.ConversionUtil.ifPerJoule;
import static malte0811.industrialWires.util.ConversionUtil.joulesPerIf;
import static malte0811.industrialWires.util.NBTKeys.*;
@ -114,17 +117,17 @@ public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric
@Override
public void writeToNBT(NBTTagCompound out) {
out.setDouble(BUFFER_IN, bufferToMB);
out.setInteger(BUFFER_IN+AC, wfToMB.getIndex());
out.setString(BUFFER_IN+AC, wfToMB.serializeToString());
out.setDouble(BUFFER_OUT, bufferToWorld);
out.setInteger(BUFFER_OUT+AC, wfToWorld.getIndex());
out.setString(BUFFER_OUT+AC, wfToWorld.serializeToString());
}
@Override
public void readFromNBT(NBTTagCompound in) {
bufferToMB = in.getDouble(BUFFER_IN);
wfToMB = Waveform.VALUES[in.getInteger(BUFFER_IN+AC)];
wfToMB = Waveform.fromString(in.getString(BUFFER_IN+AC));
bufferToWorld = in.getDouble(BUFFER_OUT);
wfToWorld = Waveform.VALUES[in.getInteger(BUFFER_OUT+AC)];
wfToWorld = Waveform.fromString(in.getString(BUFFER_OUT+AC));
}
@Override
@ -220,15 +223,20 @@ public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap==CapabilityEnergy.ENERGY)
return true;
//TODO return true for internal IC2 cap that doesn't exist yet
if (cap==ENERGY_IC2)
return true;
}
return super.hasCapability(cap, side, pos);
}
@Override
public <T> T getCapability(Capability<T> cap, EnumFacing side, BlockPos pos) {
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))&&cap== CapabilityEnergy.ENERGY)
return CapabilityEnergy.ENERGY.cast(energy);
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap == CapabilityEnergy.ENERGY)
return CapabilityEnergy.ENERGY.cast(energy);
if (cap==ENERGY_IC2)
return ENERGY_IC2.cast(capIc2);
}
return super.getCapability(cap, side, pos);
}
@ -244,4 +252,38 @@ public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
return new AxisAlignedBB(0, .375, 0, 1, 1, 1);
}
private final EUCapability.IC2EnergyHandler capIc2 = new EUCapability.IC2EnergyHandler() {
{
tier = 3;//TODO does this mean everything blows up?
}
@Override
public double injectEnergy(EnumFacing side, double amount, double voltage) {
double buffer = bufferToMB;
double input = amount * ConversionUtil.joulesPerEu();
if (!wfToMB.isDC()) {
buffer = 0;
}
input = Math.min(input, getMaxBuffer()-buffer);
buffer += input;
bufferToMB = buffer;
wfToMB = Waveform.forParameters(DC, get(has4Phases()), EXTERNAL);
return amount-ConversionUtil.euPerJoule()*input;
}
@Override
public double getOfferedEnergy() {
if (wfToWorld.isDC()) {
return Math.min(ConversionUtil.euPerJoule()*bufferToWorld,
ConversionUtil.euPerJoule()*getMaxBuffer())/getEnergyConnections().size()*2;
}
return 0;
}
@Override
public void drawEnergy(double amount) {
bufferToWorld -= ConversionUtil.joulesPerEu()*amount;
}
};
}

View file

@ -102,8 +102,20 @@ public class Waveform {
return this;
}
public int getIndex() {
return getIndex(type, phases, speed);
public String serializeToString() {
return type+":"+phases+":"+speed;
}
public static Waveform fromString(String in) {
String[] elements = in.split(":");
try {
Type t = Type.valueOf(elements[0]);
Phases p = Phases.valueOf(elements[1]);
Speed s = Speed.valueOf(elements[1]);
return forParameters(t, p, s);
} catch (Exception x) {
return forParameters(NONE, SINGLE, ROTATION);
}
}
public enum Type {

View file

@ -33,7 +33,6 @@ public class IC2ItemFactory implements IIngredientFactory {
String variant = json.get("variant").getAsString();
return IC2TRHelper.getStack(name, variant);
}
//TODO NBT sensitivity?
private class MyNBTIngredient extends IngredientNBT {
public MyNBTIngredient(ItemStack stack) {

View file

@ -14,7 +14,6 @@
*/
package malte0811.industrialWires.items;
import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.TargetingInfo;
@ -29,7 +28,6 @@ import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import blusunrize.immersiveengineering.common.util.Utils;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.entities.EntityBrokenPart;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
@ -246,22 +244,6 @@ public class ItemIC2Coil extends Item implements IWireCoil {
return EnumActionResult.PASS;
}
//TODO remove. This is for debugging
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
if (!worldIn.isRemote) {
EntityBrokenPart e = new EntityBrokenPart(worldIn);
e.setPositionAndRotation(playerIn.posX, playerIn.posY+2, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
Vec3d look = playerIn.getLookVec();
e.motionX = look.x;
e.motionY = look.y;
e.motionZ = look.z;
e.texture = new ResourceLocation(ImmersiveEngineering.MODID, "blocks/storage_steel");
worldIn.spawnEntity(e);
}
return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
public static void setLength(ItemStack i, int blocks) {
i.setTagInfo(lengthKey, new NBTTagInt(blocks));
}

View file

@ -21,11 +21,14 @@ import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
@SideOnly(Side.CLIENT)
public class CommandIWClient extends CommandBase {
@Nonnull
@Override