Some cleanup, fixed another issue along the lines of #28

This commit is contained in:
malte0811 2018-06-15 16:15:06 +02:00
parent e377b77819
commit 375c30d139
28 changed files with 493 additions and 678 deletions

View file

@ -23,7 +23,7 @@ import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.containers.ContainerPanelCreator;
import malte0811.industrialWires.containers.ContainerRSPanelConn;
import malte0811.industrialWires.containers.ContainerRenameKey;
import malte0811.industrialWires.converter.MechEnergy;
import malte0811.industrialWires.mech_mb.MechEnergy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;

View file

@ -26,9 +26,6 @@ package malte0811.industrialWires;
import malte0811.industrialWires.compat.Compat;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.converter.EUCapability;
import malte0811.industrialWires.converter.MechMBPart;
import malte0811.industrialWires.converter.MultiblockMechMB;
import malte0811.industrialWires.crafting.Recipes;
import malte0811.industrialWires.entities.EntityBrokenPart;
import malte0811.industrialWires.hv.MarxOreHandler;
@ -36,6 +33,9 @@ package malte0811.industrialWires;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.mech_mb.EUCapability;
import malte0811.industrialWires.mech_mb.MechMBPart;
import malte0811.industrialWires.mech_mb.MultiblockMechMB;
import malte0811.industrialWires.network.MessageGUIInteract;
import malte0811.industrialWires.network.MessageItemSync;
import malte0811.industrialWires.network.MessagePanelInteract;
@ -73,9 +73,9 @@ package malte0811.industrialWires;
import java.util.List;
import static malte0811.industrialWires.blocks.wire.BlockTypes_IC2_Connector.*;
import static malte0811.industrialWires.converter.MechMBPart.EXAMPLE_MECHMB_LOC;
import static malte0811.industrialWires.entities.EntityBrokenPart.MARKER_TEXTURE;
import static malte0811.industrialWires.entities.EntityBrokenPart.RES_LOC_SERIALIZER;
import static malte0811.industrialWires.mech_mb.MechMBPart.EXAMPLE_MECHMB_LOC;
import static malte0811.industrialWires.wires.IC2Wiretype.*;
@Mod(modid = IndustrialWires.MODID, version = IndustrialWires.VERSION, dependencies = "required-after:immersiveengineering@[0.12-77,);after:ic2",

View file

@ -29,7 +29,7 @@ import malte0811.industrialWires.blocks.IBlockBoundsIW.IBlockBoundsDirectional;
import malte0811.industrialWires.blocks.ISyncReceiver;
import malte0811.industrialWires.blocks.TileEntityIWMultiblock;
import malte0811.industrialWires.compat.Compat;
import malte0811.industrialWires.converter.*;
import malte0811.industrialWires.mech_mb.*;
import malte0811.industrialWires.network.MessageTileSyncIW;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.block.Block;
@ -45,6 +45,7 @@ import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.Optional;
@ -57,7 +58,7 @@ import java.util.*;
import static blusunrize.immersiveengineering.common.IEContent.blockMetalDecoration0;
import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0.HEAVY_ENGINEERING;
import static malte0811.industrialWires.converter.EUCapability.ENERGY_IC2;
import static malte0811.industrialWires.mech_mb.EUCapability.ENERGY_IC2;
import static malte0811.industrialWires.util.MiscUtils.getOffset;
import static malte0811.industrialWires.util.MiscUtils.offset;
import static malte0811.industrialWires.util.NBTKeys.*;
@ -112,14 +113,6 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
if (world.isRemote) {
return;
}
if (shouldInitWorld) {
int offset = 1;
for (MechMBPart part : mechanical) {
part.world.setWorld(world);
part.world.setOrigin(offset(pos, facing, mirrored, 0, -offset, 0));
offset += part.getLength();
}
}
// Mechanical
for (MechMBPart part : mechanical) {
part.createMEnergy(energyState);
@ -221,6 +214,19 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
}
}
@Override
public void setWorld(@Nonnull World worldIn) {
super.setWorld(worldIn);
if (!isLogicDummy()) {
int offset = 1;
for (MechMBPart part : mechanical) {
part.world.setWorld(world);
part.world.setOrigin(offset(pos, facing, mirrored, 0, -offset, 0));
offset += part.getLength();
}
}
}
//return value is maximized to choose the waveform to use
private double transferElectric(int[] section, double[] available, Waveform[] availableWf, Waveform waveform,
double[] requested, boolean simulate) {

View file

@ -20,8 +20,8 @@ public final class DummyTEs {
@Override
public void update() {
TileEntityIC2ConnectorTin newTe = getRaw();
newTe.inBuffer = inBuffer;
newTe.outBuffer = outBuffer;
newTe.bufferToNet = bufferToNet;
newTe.bufferToMachine = bufferToMachine;
newTe.maxToNet = maxToNet;
newTe.maxToMachine = maxToMachine;
newTe.relay = relay;

View file

@ -64,11 +64,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
boolean relay;
private boolean first = true;
//IC2 net to IE net buffer
double inBuffer = 0;
double bufferToNet = 0;
private double ieInputInTick = 0;
double maxToNet = 0;
private double inputInTick = 0;
//IE net to IC2 net buffer
double outBuffer = 0;
double bufferToMachine = 0;
private double ic2inputInTick = 0;
double maxToMachine = 0;
double maxStored = TIN.getTransferRate() / TIN.getFactor();
int tier = 1;
@ -88,20 +89,28 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
ImmersiveNetHandler.INSTANCE.onTEValidated(this);
first = false;
}
if (inBuffer < maxToNet) {
maxToNet = inBuffer;
if (bufferToNet < maxToNet) {
maxToNet = bufferToNet;
}
if (inputInTick>maxToNet) {
maxToNet = inputInTick;
if (ic2inputInTick >maxToNet) {
maxToNet = ic2inputInTick;
}
inputInTick = 0;
ic2inputInTick = 0;
if (bufferToMachine < maxToMachine) {
maxToMachine = bufferToMachine;
}
if (ieInputInTick >maxToMachine) {
maxToMachine = ieInputInTick;
}
ieInputInTick = 0;
if (!world.isRemote) {
if (inBuffer > EPS) {
if (bufferToNet > EPS) {
transferPower();
}
if (inBuffer>EPS) {
notifyAvailableEnergy(inBuffer);
if (bufferToNet >EPS) {
notifyAvailableEnergy(bufferToNet);
}
}
}
@ -109,7 +118,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
private void transferPower() {
Set<AbstractConnection> conns = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, world, true);
Map<AbstractConnection, Pair<IIC2Connector, Double>> maxOutputs = new HashMap<>();
double outputMax = Math.min(inBuffer, maxToNet);
double outputMax = Math.min(bufferToNet, maxToNet);
double sum = 0;
for (AbstractConnection c : conns) {
if (c.isEnergyOutput) {
@ -131,12 +140,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
AbstractConnection c = entry.getKey();
double out = outputMax * p.getRight() / sum;
double loss = getAverageLossRate(c);
out = Math.min(out, inBuffer-loss);
out = Math.min(out, bufferToNet -loss);
if (out<=0)
continue;
double inserted = out - p.getLeft().insertEnergy(out, false);
double energyAtConn = inserted + loss;
inBuffer -= energyAtConn;
bufferToNet -= energyAtConn;
float intermediaryLoss = 0;
HashSet<IImmersiveConnectable> passedConnectors = new HashSet<>();
for (Connection sub : c.subConnections) {
@ -174,7 +183,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
float loss = c!=null?c.getAverageLossRate():0;
float max = (float) (storedNew-loss);
Consumer<Float> extract = (energy)->{
inBuffer -= energy+loss;
bufferToNet -= energy+loss;
};
return new ImmutablePair<>(max, extract);
}
@ -195,17 +204,10 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
//Input through the net
@Override
public double insertEnergy(double eu, boolean simulate) {
final double insert = Math.min(maxStored - outBuffer, eu);
if (insert > 0) {
if (outBuffer < maxToMachine) {
maxToMachine = outBuffer;
}
if (eu > maxToMachine) {
maxToMachine = eu;
}
}
final double insert = Math.min(maxStored - bufferToMachine, eu);
if (!simulate) {
outBuffer += insert;
bufferToMachine += insert;
ieInputInTick += insert;
}
return eu - insert;
}
@ -272,7 +274,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
@Optional.Method(modid="ic2")
public double getDemandedEnergy() {
double ret = maxStored + .5 - inBuffer;
double ret = maxStored + .5 - bufferToNet;
if (ret < .1)
ret = 0;
return ret;
@ -287,7 +289,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
@Optional.Method(modid="ic2")
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
if (inBuffer < maxStored) {
if (bufferToNet < maxStored) {
addToIn(amount);
markDirty();
return 0;
@ -298,13 +300,13 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
@Optional.Method(modid="ic2")
public double getOfferedEnergy() {
return Math.min(maxToMachine, outBuffer);
return Math.min(maxToMachine, bufferToMachine);
}
@Override
@Optional.Method(modid="ic2")
public void drawEnergy(double amount) {
outBuffer -= amount;
bufferToMachine -= amount;
markDirty();
}
@ -313,7 +315,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
{
if (isRelay())
return null;
return new ImmutablePair<>((float)inBuffer, (d)->inBuffer -= d);
return new ImmutablePair<>((float) bufferToNet, (d)-> bufferToNet -= d);
}
@Override
protected float getBaseDamage(ImmersiveNetHandler.Connection c) {
@ -327,8 +329,8 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
private void addToIn(double amount) {
inBuffer += amount;
inputInTick += amount;
bufferToNet += amount;
ic2inputInTick += amount;
notifyAvailableEnergy(amount);
}
@ -337,17 +339,17 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
super.readCustomNBT(nbt, descPacket);
facing = EnumFacing.getFront(nbt.getInteger("facing"));
relay = nbt.getBoolean("relay");
inBuffer = nbt.getDouble("inBuffer");
outBuffer = nbt.getDouble("outBuffer");
bufferToNet = nbt.getDouble("inBuffer");
bufferToMachine = nbt.getDouble("outBuffer");
if (nbt.hasKey("maxToNet")) {
maxToNet = nbt.getDouble("maxToNet");
} else {
maxToNet = inBuffer;
maxToNet = bufferToNet;
}
if (nbt.hasKey("maxToMachine")) {
maxToMachine = nbt.getDouble("maxToMachine");
} else {
maxToMachine = outBuffer;
maxToMachine = bufferToMachine;
}
}
@ -356,8 +358,8 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
super.writeCustomNBT(nbt, descPacket);
nbt.setInteger("facing", facing.getIndex());
nbt.setBoolean("relay", relay);
nbt.setDouble("inBuffer", inBuffer);
nbt.setDouble("outBuffer", outBuffer);
nbt.setDouble("inBuffer", bufferToNet);
nbt.setDouble("outBuffer", bufferToMachine);
nbt.setDouble("maxToNet", maxToNet);
nbt.setDouble("maxToMachine", maxToMachine);
}

View file

@ -26,10 +26,10 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.blocks.hv.BlockHVMultiblocks;
import malte0811.industrialWires.client.panelmodel.PanelModel;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.converter.MechMBPart;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.mech_mb.MechMBPart;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;

View file

@ -45,13 +45,13 @@ import malte0811.industrialWires.client.manual.TextSplitter;
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
import malte0811.industrialWires.client.render.*;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.converter.*;
import malte0811.industrialWires.crafting.IC2TRHelper;
import malte0811.industrialWires.entities.EntityBrokenPart;
import malte0811.industrialWires.hv.MarxOreHandler;
import malte0811.industrialWires.hv.MultiblockMarx;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.mech_mb.*;
import malte0811.industrialWires.util.CommandIWClient;
import malte0811.industrialWires.util.ConversionUtil;
import malte0811.industrialWires.util.MiscUtils;
@ -468,6 +468,8 @@ public class ClientProxy extends CommonProxy {
@Override
public void stopAllSoundsExcept(BlockPos pos, Set<?> excluded) {
IndustrialWires.logger.info("Stopping all except {} at {} (playing {})",
excluded, pos, playingSounds.get(pos));
if (playingSounds.containsKey(pos)) {
SoundHandler manager = Minecraft.getMinecraft().getSoundHandler();
List<ISound> sounds = playingSounds.get(pos);

View file

@ -21,7 +21,7 @@ import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
import malte0811.industrialWires.client.ClientUtilsIW;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.converter.MechMBPart;
import malte0811.industrialWires.mech_mb.MechMBPart;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
@ -43,7 +43,7 @@ import javax.annotation.Nonnull;
import java.util.*;
import static malte0811.industrialWires.blocks.converter.TileEntityMechMB.TICK_ANGLE_PER_SPEED;
import static malte0811.industrialWires.converter.MechMBPart.SHAFT_KEY;
import static malte0811.industrialWires.mech_mb.MechMBPart.SHAFT_KEY;
public class TileRenderMechMB extends TileEntitySpecialRenderer<TileEntityMechMB> implements IResourceManagerReloadListener {
public static final Map<ResourceLocation, IBakedModel> BASE_MODELS = new HashMap<>();

View file

@ -25,8 +25,8 @@ import ic2.api.energy.tile.IEnergyTile;
import ic2.api.item.IBoxable;
import ic2.api.item.IC2Items;
import ic2.core.block.TileEntityBlock;
import malte0811.industrialWires.converter.MechPartCommutator;
import malte0811.industrialWires.hv.MarxOreHandler;
import malte0811.industrialWires.mech_mb.MechPartCommutator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

View file

@ -1,81 +0,0 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.util.ConversionUtil;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
public interface IMBPartElectric {
Waveform getProduced(MechEnergy state);
// All four in Joules
double getAvailableEEnergy();
void extractEEnergy(double energy);
double requestEEnergy(Waveform waveform, MechEnergy energy);
void insertEEnergy(double given, Waveform waveform, MechEnergy energy);
void setLastIOState(IOState state);
IOState getLastIOState();
default Set<Pair<BlockPos, EnumFacing>> getEnergyConnections() {
return ImmutableSet.of();
}
default double outputFE(LocalSidedWorld world, int available) {
if (!getLastIOState().canSwitchToOutput())
return 0;
double extracted = 0;
for (Pair<BlockPos, EnumFacing> output : getEnergyConnections()) {
if (output.getRight()==null)
continue;
BlockPos outTE = output.getLeft().offset(output.getRight());
TileEntity te = world.getTileEntity(outTE);
EnumFacing sideReal = world.transformedToReal(output.getRight()).getOpposite();
if (te != null && te.hasCapability(CapabilityEnergy.ENERGY, sideReal)) {
IEnergyStorage energy = te.getCapability(CapabilityEnergy.ENERGY, sideReal);
if (energy != null && energy.canReceive()) {
int received = energy.receiveEnergy(available, false);
available -= received;
extracted += ConversionUtil.joulesPerIf() * received;
}
}
}
if (extracted>0) {
setLastIOState(IOState.OUTPUT);
}
return extracted;
}
enum IOState {
NO_TRANSFER,
OUTPUT,
INPUT;
boolean canSwitchToOutput() {
return NO_TRANSFER ==this||OUTPUT==this;
}
boolean canSwitchToInput() {
return NO_TRANSFER ==this||INPUT==this;
}
}
}

View file

@ -1,330 +0,0 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.util.ConversionUtil;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
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.IMBPartElectric.IOState.*;
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.*;
import static net.minecraft.util.EnumFacing.UP;
import static net.minecraft.util.math.BlockPos.ORIGIN;
public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric {
private double bufferToMB;
private Waveform wfToMB = Waveform.forParameters(Waveform.Type.NONE, get(has4Phases()), Waveform.Speed.EXTERNAL);
private double bufferToWorld;
private Waveform wfToWorld = Waveform.forParameters(Waveform.Type.NONE, get(has4Phases()), Waveform.Speed.ROTATION);
private IOState lastIO = NO_TRANSFER;
private long lastStateChange = Long.MIN_VALUE;
{
original.put(ORIGIN, blockMetalDecoration0.getDefaultState().withProperty(
blockMetalDecoration0.property, GENERATOR));
}
@Override
public Waveform getProduced(MechEnergy state) {
return wfToMB;
}
@Override
public double getAvailableEEnergy() {
return bufferToMB;
}
@Override
public void extractEEnergy(double energy) {
bufferToMB -= energy;
}
@Override
public double requestEEnergy(Waveform waveform, MechEnergy energy) {
if (waveform.isSinglePhase()^has4Phases()) {
return getMaxBuffer()-bufferToWorld;
}
return 0;
}
@Override
public void insertEEnergy(double given, Waveform waveform, MechEnergy energy) {
bufferToWorld += given;
wfToWorld = waveform;
}
@Override
public void setLastIOState(IOState state) {
lastIO = state;
lastStateChange = world.getWorld().getTotalWorldTime();
}
@Override
public IOState getLastIOState() {
return lastIO;
}
@Override
public void createMEnergy(MechEnergy e) {}
@Override
public double requestMEnergy(MechEnergy e) {
return 0;
}
@Override
public void insertMEnergy(double added) {
if (world.getWorld().getTotalWorldTime()>lastStateChange+1) {
setLastIOState(NO_TRANSFER);
}
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() {
return 50;
}
@Override
public double getMaxSpeed() {
return IWConfig.MechConversion.allowMBFE()?200:-1;
}
@Override
public void writeToNBT(NBTTagCompound out) {
out.setDouble(BUFFER_IN, bufferToMB);
out.setString(BUFFER_IN+AC, wfToMB.serializeToString());
out.setDouble(BUFFER_OUT, bufferToWorld);
out.setString(BUFFER_OUT+AC, wfToWorld.serializeToString());
}
@Override
public void readFromNBT(NBTTagCompound in) {
bufferToMB = in.getDouble(BUFFER_IN);
wfToMB = Waveform.fromString(in.getString(BUFFER_IN+AC));
bufferToWorld = in.getDouble(BUFFER_OUT);
wfToWorld = Waveform.fromString(in.getString(BUFFER_OUT+AC));
}
@Override
public ResourceLocation getRotatingBaseModel() {
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/shaft2.obj");
}
@Override
public boolean canForm(LocalSidedWorld w) {
if (!IWConfig.MechConversion.allowMBFE()) {
return false;
}
IBlockState state = w.getBlockState(ORIGIN);
return state.getBlock()== blockMetalDecoration0 &&
state.getValue(blockMetalDecoration0.property)== GENERATOR;
}
@Override
public short getFormPattern(int offset) {
return 0b000_010_000;
}
@Override
public void breakOnFailure(MechEnergy energy) {
//NOP
}
@Override
public MechanicalMBBlockType getType() {
return MechanicalMBBlockType.SHAFT_1_PHASE;
}
private static final ImmutableSet<Pair<BlockPos, EnumFacing>> outputs = ImmutableSet.of(
new ImmutablePair<>(ORIGIN, UP)
);
public Set<Pair<BlockPos, EnumFacing>> getEnergyConnections() {
return outputs;
}
private IEnergyStorage energy = new IEnergyStorage() {
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
if (!getLastIOState().canSwitchToInput()) {
return 0;
}
double joules = joulesPerIf()*maxReceive;
double insert = Math.min(Math.min(joules, getMaxBuffer()-bufferToMB),
getMaxBuffer()/getEnergyConnections().size());
if (!simulate) {
if (!wfToMB.isAC()) {
bufferToMB = 0;
wfToMB = Waveform.forParameters(Waveform.Type.AC, get(has4Phases()), Waveform.Speed.EXTERNAL);
}
if (insert>0) {
setLastIOState(INPUT);
}
bufferToMB += insert;
}
return (int) Math.ceil(insert* ifPerJoule());
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
if (!getLastIOState().canSwitchToOutput()) {
return 0;
}
if (wfToWorld.isAC()) {
double joules = joulesPerIf() * maxExtract;
double extract = Math.min(Math.min(joules, bufferToWorld), getMaxBuffer()/getEnergyConnections().size());
if (!simulate) {
bufferToWorld -= extract;
if (extract>0) {
setLastIOState(OUTPUT);
}
}
return (int) Math.floor(extract * ifPerJoule());
} else {
return 0;
}
}
@Override
public int getEnergyStored() {
return (int) Math.round((bufferToMB+bufferToWorld)* ifPerJoule());
}
@Override
public int getMaxEnergyStored() {
return (int) Math.round(getMaxBuffer()*2* ifPerJoule());
}
@Override
public boolean canExtract() {
return true;
}
@Override
public boolean canReceive() {
return true;
}
};
@Override
public <T> boolean hasCapability(Capability<T> cap, EnumFacing side, BlockPos pos) {
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap==CapabilityEnergy.ENERGY)
return true;
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))) {
if (cap == CapabilityEnergy.ENERGY)
return CapabilityEnergy.ENERGY.cast(energy);
if (cap==ENERGY_IC2)
return ENERGY_IC2.cast(capIc2);
}
return super.getCapability(cap, side, pos);
}
protected double getMaxBuffer() {
return 10e3;//200kW
}
protected boolean has4Phases() {
return false;
}
@Override
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);
setLastIOState(INPUT);
return amount-ConversionUtil.euPerJoule()*input;
}
@Override
public double getOfferedEnergy() {
if (wfToWorld.isDC() && getLastIOState().canSwitchToOutput()) {
return Math.min(ConversionUtil.euPerJoule()*bufferToWorld,
ConversionUtil.euPerJoule()*getMaxBuffer())/getEnergyConnections().size()*2;
}
return 0;
}
@Override
public double getDemandedEnergy() {
if (getLastIOState().canSwitchToInput()) {
return Math.min(ConversionUtil.euPerJoule()*(getMaxBuffer()-bufferToMB),
ConversionUtil.euPerJoule()*getMaxBuffer()/getEnergyConnections().size()*2);
}
return 0;
}
@Override
public void drawEnergy(double amount) {
bufferToWorld -= ConversionUtil.joulesPerEu()*amount;
setLastIOState(OUTPUT);
}
};
}

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import net.minecraft.nbt.NBTBase;
import net.minecraft.util.EnumFacing;

View file

@ -0,0 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.mech_mb;
public interface IMBPartElectric {
Waveform getProduced(MechEnergy state);
// All four in Joules
double getAvailableEEnergy();
void extractEEnergy(double energy);
double requestEEnergy(Waveform waveform, MechEnergy energy);
void insertEEnergy(double given, Waveform waveform, MechEnergy energy);
}

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.common.util.Utils;

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import net.minecraft.util.math.MathHelper;

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import blusunrize.immersiveengineering.api.MultiblockHandler;
import blusunrize.immersiveengineering.common.IEContent;

View file

@ -0,0 +1,127 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.mech_mb;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
import static net.minecraft.util.EnumFacing.UP;
import static net.minecraft.util.math.BlockPos.ORIGIN;
public class MechPartCommutator extends MechPartEnergyIO {
public static ItemStack originalStack = ItemStack.EMPTY;
@Override
protected Waveform transform(Waveform wf, MechEnergy e) {
return wf.getCommutated(e.getSpeed(), has4Phases());
}
@Override
public double getInertia() {
return 50;
}
@Override
public double getMaxSpeed() {
return IWConfig.MechConversion.allowMBEU()?100:-1;
}
@Override
public ResourceLocation getRotatingBaseModel() {
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/shaft_comm.obj");
}
private static final ResourceLocation KINETIC_GEN_KEY =
new ResourceLocation("ic2", "kinetic_generator");
@Override
public boolean canForm(LocalSidedWorld w) {
if (!IWConfig.MechConversion.allowMBEU()) {
return false;
}
//Center is an IC2 kinetic generator
TileEntity te = w.getTileEntity(BlockPos.ORIGIN);
if (te!=null) {
ResourceLocation loc = TileEntity.getKey(te.getClass());
return loc != null && loc.equals(KINETIC_GEN_KEY);
}
return false;
}
@Override
public short getFormPattern(int offset) {
return 0b000_010_000;
}
@Override
public void breakOnFailure(MechEnergy energy) {
//NOP
}
@Override
public ItemStack getOriginalItem(BlockPos pos) {
return pos.equals(ORIGIN)?originalStack:super.getOriginalItem(pos);
}
@Override
public void disassemble() {
super.disassemble();
if (IndustrialWires.ic2TeBlock!=null) {
NBTTagCompound dummyNbt = new NBTTagCompound();
dummyNbt.setString("id", KINETIC_GEN_KEY.toString());
world.setBlockState(BlockPos.ORIGIN, IndustrialWires.ic2TeBlock.getDefaultState());
world.setTileEntity(BlockPos.ORIGIN, TileEntity.create(world.getWorld(), dummyNbt));
}
}
@Override
public MechanicalMBBlockType getType() {
return MechanicalMBBlockType.SHAFT_COMMUTATOR;
}
protected double getMaxBuffer() {
return 2.5e3;
}
protected boolean has4Phases() {
return false;
}
private static final ImmutableSet<Pair<BlockPos, EnumFacing>> outputs = ImmutableSet.of(
new ImmutablePair<>(ORIGIN, UP), new ImmutablePair<>(ORIGIN, null)
);
public Set<Pair<BlockPos, EnumFacing>> getEnergyConnections() {
return outputs;
}
@Override
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
return new AxisAlignedBB(0, .375-1/32D, 0, 1, 1, 1);
}
}

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IWConfig;

View file

@ -13,53 +13,50 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.converter.EUCapability.IC2EnergyHandler;
import malte0811.industrialWires.mech_mb.EUCapability.IC2EnergyHandler;
import malte0811.industrialWires.util.ConversionUtil;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
import static malte0811.industrialWires.converter.EUCapability.ENERGY_IC2;
import static malte0811.industrialWires.converter.IMBPartElectric.IOState.*;
import static malte0811.industrialWires.converter.Waveform.Phases.get;
import static malte0811.industrialWires.converter.Waveform.Speed.EXTERNAL;
import static malte0811.industrialWires.converter.Waveform.Speed.ROTATION;
import static malte0811.industrialWires.converter.Waveform.Type.DC;
import static malte0811.industrialWires.converter.Waveform.Type.NONE;
import static malte0811.industrialWires.mech_mb.EUCapability.ENERGY_IC2;
import static malte0811.industrialWires.mech_mb.MechPartEnergyIO.IOState.*;
import static malte0811.industrialWires.mech_mb.Waveform.Phases.get;
import static malte0811.industrialWires.mech_mb.Waveform.Speed.EXTERNAL;
import static malte0811.industrialWires.mech_mb.Waveform.Speed.ROTATION;
import static malte0811.industrialWires.mech_mb.Waveform.Type.DC;
import static malte0811.industrialWires.mech_mb.Waveform.Type.NONE;
import static malte0811.industrialWires.util.NBTKeys.*;
import static net.minecraft.util.EnumFacing.UP;
import static net.minecraft.util.math.BlockPos.ORIGIN;
import static net.minecraftforge.energy.CapabilityEnergy.ENERGY;
public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
public static ItemStack originalStack = ItemStack.EMPTY;
public abstract class MechPartEnergyIO extends MechMBPart implements IMBPartElectric {
private double bufferToMB;
private Waveform wfToMB = Waveform.forParameters(NONE, get(has4Phases()), ROTATION);
private double bufferToWorld;
private Waveform wfToWorld = Waveform.forParameters(NONE, get(has4Phases()), ROTATION);
private final IEnergyStorage capForge = new EnergyStorageMMB();
private final IC2EnergyHandler capIc2 = new IC2EHandlerMB();
private IOState lastIOState = NO_TRANSFER;
private long lastStateChange = Long.MIN_VALUE;
@Override
public Waveform getProduced(MechEnergy state) {
return wfToMB.getCommutated(state.getSpeed(), has4Phases());
return transform(wfToMB, state);
}
protected Waveform transform(Waveform wf, MechEnergy e) {
return wf;
}
@Override
@ -82,24 +79,126 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
@Override
public void insertEEnergy(double given, Waveform waveform, MechEnergy mechEnergy) {
waveform = waveform.getCommutated(mechEnergy.getSpeed(), has4Phases());
waveform = transform(waveform, mechEnergy);
wfToWorld = waveform;
bufferToWorld += given;
}
@Override
public void setLastIOState(IOState state) {
lastIOState = state;
lastStateChange = world.getWorld().getTotalWorldTime();
if (lastIOState.canSwitchTo(state)) {
lastIOState = state;
lastStateChange = world.getWorld().getTotalWorldTime();
}
}
@Override
public IOState getLastIOState() {
return lastIOState;
}
@Override
public <T> T getCapability(Capability<T> cap, EnumFacing side, BlockPos pos) {
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap == ENERGY_IC2) {
return ENERGY_IC2.cast(capIc2);
}
if (cap == ENERGY) {
return ENERGY.cast(capForge);
}
}
return super.getCapability(cap, side, pos);
}
private final IC2EnergyHandler capIc2 = new IC2EnergyHandler() {
@Override
public <T> boolean hasCapability(Capability<T> cap, EnumFacing side, BlockPos pos) {
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap == ENERGY_IC2) {
return true;
}
if (cap == ENERGY) {
return true;
}
}
return super.hasCapability(cap, side, pos);
}
@Override
public void createMEnergy(MechEnergy e) {}
@Override
public double requestMEnergy(MechEnergy e) {
return 0;
}
@Override
public void insertMEnergy(double added) {
if (world.getWorld().getTotalWorldTime()>lastStateChange+1) {
setLastIOState(NO_TRANSFER);
}
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(available);
}
}
@Override
public double getInertia() {
return 50;
}
@Override
public double getMaxSpeed() {
return IWConfig.MechConversion.allowMBEU()?100:-1;
}
@Override
public void writeToNBT(NBTTagCompound out) {
out.setDouble(BUFFER_IN, bufferToMB);
out.setDouble(BUFFER_OUT, bufferToWorld);
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.fromString(in.getString(BUFFER_IN+WAVEFORM));
wfToWorld = Waveform.fromString(in.getString(BUFFER_OUT+WAVEFORM));
}
protected abstract double getMaxBuffer();
protected abstract boolean has4Phases();
public abstract Set<Pair<BlockPos, EnumFacing>> getEnergyConnections();
private double outputFE(int available) {
if (!getLastIOState().canSwitchToOutput())
return 0;
double extracted = 0;
for (Pair<BlockPos, EnumFacing> output : getEnergyConnections()) {
if (output.getRight()==null)
continue;
BlockPos outTE = output.getLeft().offset(output.getRight());
TileEntity te = world.getTileEntity(outTE);
EnumFacing sideReal = world.transformedToReal(output.getRight()).getOpposite();
if (te != null && te.hasCapability(CapabilityEnergy.ENERGY, sideReal)) {
IEnergyStorage energy = te.getCapability(CapabilityEnergy.ENERGY, sideReal);
if (energy != null && energy.canReceive()) {
int received = energy.receiveEnergy(available, false);
available -= received;
extracted += ConversionUtil.joulesPerIf() * received;
}
}
}
if (extracted>0) {
setLastIOState(IOState.OUTPUT);
}
return extracted;
}
class IC2EHandlerMB extends IC2EnergyHandler {
{
tier = 3;//TODO does this mean everything blows up?
}
@ -144,27 +243,27 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
}
};
private IEnergyStorage capForge = new IEnergyStorage() {
class EnergyStorageMMB implements IEnergyStorage {
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
if (!getLastIOState().canSwitchToInput()) {
return 0;
}
double buffer = bufferToMB;
double input = maxReceive* ConversionUtil.joulesPerIf();
double input = maxReceive * ConversionUtil.joulesPerIf();
if (!wfToMB.isAC()) {
buffer = 0;
}
input = Math.min(input, getMaxBuffer()-buffer);
input = Math.min(input, getMaxBuffer() - buffer);
buffer += input;
if (!simulate) {
bufferToMB = buffer;
wfToMB = Waveform.forParameters(Waveform.Type.AC, get(has4Phases()), EXTERNAL);
if (input>0) {
if (input > 0) {
setLastIOState(INPUT);
}
}
return (int) (ConversionUtil.ifPerJoule()*input);
return (int) (ConversionUtil.ifPerJoule() * input);
}
@Override
@ -173,26 +272,26 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
return 0;
}
double buffer = bufferToWorld;
double output = maxExtract* ConversionUtil.joulesPerIf();
double output = maxExtract * ConversionUtil.joulesPerIf();
output = Math.min(output, buffer);
buffer -= output;
if (!simulate) {
bufferToWorld = buffer;
if (output>0) {
if (output > 0) {
setLastIOState(OUTPUT);
}
}
return (int) (ConversionUtil.ifPerJoule()*output);
return (int) (ConversionUtil.ifPerJoule() * output);
}
@Override
public int getEnergyStored() {
return (int) (ConversionUtil.ifPerJoule()*(bufferToWorld+bufferToMB));
return (int) (ConversionUtil.ifPerJoule() * (bufferToWorld + bufferToMB));
}
@Override
public int getMaxEnergyStored() {
return (int)(2*ConversionUtil.ifPerJoule()*getMaxBuffer());
return (int) (2 * ConversionUtil.ifPerJoule() * getMaxBuffer());
}
@Override
@ -204,149 +303,31 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
public boolean canReceive() {
return true;
}
};
}
@Override
public <T> T getCapability(Capability<T> cap, EnumFacing side, BlockPos pos) {
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap == ENERGY_IC2) {
return ENERGY_IC2.cast(capIc2);
}
if (cap == ENERGY) {
return ENERGY.cast(capForge);
enum IOState {
NO_TRANSFER,
OUTPUT,
INPUT;
boolean canSwitchToOutput() {
return NO_TRANSFER ==this||OUTPUT==this;
}
boolean canSwitchToInput() {
return NO_TRANSFER ==this||INPUT==this;
}
public boolean canSwitchTo(IOState state) {
switch (state) {
case NO_TRANSFER:
return true;
case OUTPUT:
return canSwitchToOutput();
case INPUT:
return canSwitchToInput();
}
return true;
}
return super.getCapability(cap, side, pos);
}
@Override
public <T> boolean hasCapability(Capability<T> cap, EnumFacing side, BlockPos pos) {
if (getEnergyConnections().contains(new ImmutablePair<>(pos, side))) {
if (cap == ENERGY_IC2) {
return true;
}
if (cap == ENERGY) {
return true;
}
}
return super.hasCapability(cap, side, pos);
}
@Override
public void createMEnergy(MechEnergy e) {}
@Override
public double requestMEnergy(MechEnergy e) {
return 0;
}
@Override
public void insertMEnergy(double added) {
if (world.getWorld().getTotalWorldTime()>lastStateChange+1) {
setLastIOState(NO_TRANSFER);
}
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() {
return 50;
}
@Override
public double getMaxSpeed() {
return IWConfig.MechConversion.allowMBEU()?100:-1;
}
@Override
public void writeToNBT(NBTTagCompound out) {
out.setDouble(BUFFER_IN, bufferToMB);
out.setDouble(BUFFER_OUT, bufferToWorld);
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.fromString(in.getString(BUFFER_IN+WAVEFORM));
wfToWorld = Waveform.fromString(in.getString(BUFFER_OUT+WAVEFORM));
}
@Override
public ResourceLocation getRotatingBaseModel() {
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/shaft_comm.obj");
}
private static final ResourceLocation KINETIC_GEN_KEY =
new ResourceLocation("ic2", "kinetic_generator");
@Override
public boolean canForm(LocalSidedWorld w) {
if (!IWConfig.MechConversion.allowMBEU()) {
return false;
}
//Center is an IC2 kinetic generator
TileEntity te = w.getTileEntity(BlockPos.ORIGIN);
if (te!=null) {
ResourceLocation loc = TileEntity.getKey(te.getClass());
return loc != null && loc.equals(KINETIC_GEN_KEY);
}
return false;
}
@Override
public short getFormPattern(int offset) {
return 0b000_010_000;
}
@Override
public void breakOnFailure(MechEnergy energy) {
//NOP
}
@Override
public ItemStack getOriginalItem(BlockPos pos) {
return pos.equals(ORIGIN)?originalStack:super.getOriginalItem(pos);
}
@Override
public void disassemble() {
super.disassemble();
if (IndustrialWires.ic2TeBlock!=null) {
NBTTagCompound dummyNbt = new NBTTagCompound();
dummyNbt.setString("id", KINETIC_GEN_KEY.toString());
world.setBlockState(BlockPos.ORIGIN, IndustrialWires.ic2TeBlock.getDefaultState());
world.setTileEntity(BlockPos.ORIGIN, TileEntity.create(world.getWorld(), dummyNbt));
}
}
@Override
public MechanicalMBBlockType getType() {
return MechanicalMBBlockType.SHAFT_COMMUTATOR;
}
protected double getMaxBuffer() {
return 2.5e3;
}
protected boolean has4Phases() {
return false;
}
private static final ImmutableSet<Pair<BlockPos, EnumFacing>> outputs = ImmutableSet.of(
new ImmutablePair<>(ORIGIN, UP), new ImmutablePair<>(ORIGIN, null)
);
public Set<Pair<BlockPos, EnumFacing>> getEnergyConnections() {
return outputs;
}
@Override
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
return new AxisAlignedBB(0, .375-1/32D, 0, 1, 1, 1);
}
}

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IWConfig;

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
@ -29,7 +29,7 @@ import net.minecraft.util.math.BlockPos;
import static blusunrize.immersiveengineering.common.IEContent.blockMetalDecoration0;
import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0.COIL_LV;
import static malte0811.industrialWires.converter.Waveform.Phases.get;
import static malte0811.industrialWires.mech_mb.Waveform.Phases.get;
import static malte0811.industrialWires.util.NBTKeys.BUFFER_IN;
import static malte0811.industrialWires.util.NBTKeys.BUFFER_OUT;
import static net.minecraft.util.math.BlockPos.ORIGIN;
@ -81,17 +81,6 @@ public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
}
}
//TODO clean this up once I know whether it works
@Override
public void setLastIOState(IOState state) {
}
@Override
public IOState getLastIOState() {
return IOState.NO_TRANSFER;
}
@Override
public void createMEnergy(MechEnergy e) {
e.addEnergy(bufferToMech);

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction;

View file

@ -0,0 +1,94 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.mech_mb;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Set;
import static blusunrize.immersiveengineering.common.IEContent.blockMetalDecoration0;
import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0.GENERATOR;
import static net.minecraft.util.EnumFacing.UP;
import static net.minecraft.util.math.BlockPos.ORIGIN;
public class MechPartTwoElectrodes extends MechPartEnergyIO {
{
original.put(ORIGIN, blockMetalDecoration0.getDefaultState().withProperty(
blockMetalDecoration0.property, GENERATOR));
}
@Override
public ResourceLocation getRotatingBaseModel() {
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/shaft2.obj");
}
@Override
public boolean canForm(LocalSidedWorld w) {
if (!IWConfig.MechConversion.allowMBFE()) {
return false;
}
IBlockState state = w.getBlockState(ORIGIN);
return state.getBlock()== blockMetalDecoration0 &&
state.getValue(blockMetalDecoration0.property)== GENERATOR;
}
@Override
public short getFormPattern(int offset) {
return 0b000_010_000;
}
@Override
public void breakOnFailure(MechEnergy energy) {
//NOP
}
@Override
public MechanicalMBBlockType getType() {
return MechanicalMBBlockType.SHAFT_1_PHASE;
}
private static final ImmutableSet<Pair<BlockPos, EnumFacing>> outputs = ImmutableSet.of(
new ImmutablePair<>(ORIGIN, UP)
);
public Set<Pair<BlockPos, EnumFacing>> getEnergyConnections() {
return outputs;
}
protected double getMaxBuffer() {
return 10e3;//200kW
}
protected boolean has4Phases() {
return false;
}
@Override
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
return new AxisAlignedBB(0, .375, 0, 1, 1, 1);
}
}

View file

@ -13,7 +13,7 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import blusunrize.immersiveengineering.api.MultiblockHandler;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;

View file

@ -13,12 +13,12 @@
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.converter;
package malte0811.industrialWires.mech_mb;
import static malte0811.industrialWires.converter.Waveform.Phases.SINGLE;
import static malte0811.industrialWires.converter.Waveform.Speed.EXTERNAL;
import static malte0811.industrialWires.converter.Waveform.Speed.ROTATION;
import static malte0811.industrialWires.converter.Waveform.Type.*;
import static malte0811.industrialWires.mech_mb.Waveform.Phases.SINGLE;
import static malte0811.industrialWires.mech_mb.Waveform.Speed.EXTERNAL;
import static malte0811.industrialWires.mech_mb.Waveform.Speed.ROTATION;
import static malte0811.industrialWires.mech_mb.Waveform.Type.*;
public class Waveform {
public static final double EXTERNAL_SPEED = 20;