Added basic (low efficiency, low power) conversion methods between RF and EU by making conversion between IE rotational energy and IC2 kinetic energy possible
TODO: -textures+blockstate JSON's -recipes -manual entry including an explanation of rotational energy -ask Blu about making inputRotation return a double of leftover energy
This commit is contained in:
parent
3bd6c14266
commit
ac390872b1
|
@ -1,3 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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;
|
||||
|
||||
import net.minecraftforge.common.config.Config;
|
||||
|
@ -9,4 +26,31 @@ public class IWConfig {
|
|||
public static int[] maxLengthPerConn = {16, 16, 16, 32, 32};
|
||||
@Comment({"The maximum length of wire a coil item.", "Order: Tin, Copper, Gold, HV, Glass Fiber (as above)"})
|
||||
public static int[] maxLengthOnCoil = {1024, 1024, 1024, 2048, 2048};
|
||||
|
||||
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
|
||||
public static boolean enableConversion = true;
|
||||
|
||||
public static MechConversion mc = new MechConversion();
|
||||
public static class MechConversion {
|
||||
@Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 4)"})
|
||||
public static double euPerIf = 4;
|
||||
@Comment({"The amount of IC2 kinetic energy that an ideal converter produces from 1 EU"})
|
||||
public static double kinPerEu = 4;
|
||||
|
||||
@Comment({"The maximum amount of IF that can be converted to rotational energy", "by one motor in one tick (default: 100)"})
|
||||
public static int maxIfToMech = 100;
|
||||
@Comment({"The efficiency of the IF motor. The default value of 0.9 means that 10% of the energy are lost in the conversion."})
|
||||
public static double ifMotorEfficiency = .9;
|
||||
|
||||
@Comment({"The maximum amount of IE rotational energy that can be converted into IC2 kinetic energy", "by one converter in one tick"})
|
||||
public static double maxRotToKin = 50;
|
||||
@Comment({"The efficiency of the conversion from IE rotational energy to IC2 kinetic energy"})
|
||||
public static double rotToKinEfficiency = .7;
|
||||
|
||||
@Comment({"The maximum amount of IC2 kinetic energy that can be converted into IE rotational energy", "by one converter in one tick"})
|
||||
public static int maxKinToRot = 50;
|
||||
@Comment({"The efficiency of the conversion from IC2 kinetic energy to IE rotational energy"})
|
||||
public static double kinToRotEfficiency = .8;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@ import blusunrize.immersiveengineering.api.tool.AssemblerHandler.RecipeQuery;
|
|||
import blusunrize.immersiveengineering.common.IEContent;
|
||||
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration;
|
||||
import ic2.api.item.IC2Items;
|
||||
import malte0811.industrialWires.blocks.converter.BlockMechanicalConverter;
|
||||
import malte0811.industrialWires.blocks.converter.TileEntityIEMotor;
|
||||
import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE;
|
||||
import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
|
||||
import malte0811.industrialWires.blocks.wire.BlockIC2Connector;
|
||||
import malte0811.industrialWires.blocks.wire.TileEntityIC2ConnectorCopper;
|
||||
import malte0811.industrialWires.blocks.wire.TileEntityIC2ConnectorGlass;
|
||||
|
@ -53,6 +57,7 @@ public class IndustrialWires {
|
|||
public static final String MODID = "industrialwires";
|
||||
public static final String VERSION = "${version}";
|
||||
public static BlockIC2Connector ic2conn;
|
||||
public static BlockMechanicalConverter mechConv;
|
||||
public static ItemIC2Coil coil;
|
||||
public static CreativeTabs creativeTab = new CreativeTabs(MODID) {
|
||||
|
||||
|
@ -69,13 +74,18 @@ public class IndustrialWires {
|
|||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
new IWConfig();
|
||||
ic2conn = new BlockIC2Connector();
|
||||
mechConv = new BlockMechanicalConverter();
|
||||
coil = new ItemIC2Coil();
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorTin.class, "ic2ConnectorTin");
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorCopper.class, "ic2ConnectorCopper");
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorGold.class, "ic2ConnectorGold");
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorHV.class, "ic2ConnectorHV");
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorGlass.class, "ic2ConnectorGlass");
|
||||
GameRegistry.registerTileEntity(TileEntityIEMotor.class, MODID+":ieMotor");
|
||||
GameRegistry.registerTileEntity(TileEntityMechICtoIE.class, MODID+":mechIcToIe");
|
||||
GameRegistry.registerTileEntity(TileEntityMechIEtoIC.class, MODID+":mechIeToIc");
|
||||
if (IC2Wiretype.IC2_TYPES==null) {
|
||||
throw new IllegalStateException("No IC2 wires registered");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks;
|
||||
|
||||
public interface IMetaEnum {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemBlockIW extends ItemBlock {
|
||||
Object[] values;
|
||||
public ItemBlockIW(Block b) {
|
||||
super(b);
|
||||
assert b instanceof IMetaEnum;
|
||||
values = ((IMetaEnum)b).getValues();
|
||||
hasSubtypes = true;
|
||||
}
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
int meta = stack.getMetadata();
|
||||
return block.getUnlocalizedName()+"."+values[meta].toString().toLowerCase();
|
||||
}
|
||||
@Override
|
||||
public int getMetadata(int damage) {
|
||||
return damage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public abstract class TileEntityIWBase extends TileEntity {
|
||||
protected static final String ENERGY_TAG = "energy";
|
||||
protected static final String BUFFER_TAG = "buffer";
|
||||
protected static final String DIR_TAG = "dir";
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
NBTTagCompound nbt = super.getUpdateTag();
|
||||
writeNBT(nbt, true);
|
||||
return nbt;
|
||||
}
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket() {
|
||||
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), getUpdateTag());
|
||||
}
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
writeNBT(compound, false);
|
||||
return super.writeToNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
readNBT(compound, false);
|
||||
super.readFromNBT(compound);
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
super.onDataPacket(net, pkt);
|
||||
readNBT(pkt.getNbtCompound(), true);
|
||||
}
|
||||
public abstract void writeNBT(NBTTagCompound out, boolean updatePacket);
|
||||
public abstract void readNBT(NBTTagCompound in, boolean updatePacket);
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks.converter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import blusunrize.immersiveengineering.api.IEProperties;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.IMetaEnum;
|
||||
import malte0811.industrialWires.blocks.ItemBlockIW;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
public class BlockMechanicalConverter extends Block implements IMetaEnum, ITileEntityProvider {
|
||||
PropertyEnum<MechanicalBlockType> type;
|
||||
public BlockMechanicalConverter() {
|
||||
super(Material.IRON);
|
||||
setHardness(3.0F);
|
||||
setResistance(15.0F);
|
||||
String name = "mechanicalConverter";
|
||||
GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name));
|
||||
GameRegistry.register(new ItemBlockIW(this), new ResourceLocation(IndustrialWires.MODID, name));
|
||||
setUnlocalizedName(name);
|
||||
setCreativeTab(IndustrialWires.creativeTab);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
|
||||
for (int i = 0;i<3;i++) {
|
||||
list.add(new ItemStack(itemIn, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
type = PropertyEnum.create("type", MechanicalBlockType.class);
|
||||
BlockStateContainer container = new BlockStateContainer(this,
|
||||
new IProperty[]{
|
||||
type,
|
||||
IEProperties.FACING_ALL
|
||||
});
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
|
||||
return getExtendedState(state, worldIn, pos);
|
||||
}
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
IBlockState ret = super.getExtendedState(state, world, pos);
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof IDirectionalTile) {
|
||||
ret = ret.withProperty(IEProperties.FACING_ALL, ((IDirectionalTile) te).getFacing());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(type, MechanicalBlockType.values[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getValues() {
|
||||
return MechanicalBlockType.values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
switch (MechanicalBlockType.values[meta]) {
|
||||
case IE_MOTOR:
|
||||
return new TileEntityIEMotor();
|
||||
case IE_TO_IC2:
|
||||
return new TileEntityMechIEtoIC();
|
||||
case IC2_TO_IE:
|
||||
return new TileEntityMechICtoIE();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(type).ordinal();
|
||||
}
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
|
||||
float hitZ, int meta, EntityLivingBase placer, ItemStack stack) {
|
||||
IBlockState base = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, stack);
|
||||
base = base.withProperty(type, MechanicalBlockType.values[meta]);
|
||||
return base.withProperty(IEProperties.FACING_ALL, facing.getOpposite());
|
||||
}
|
||||
@Override
|
||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
||||
ItemStack stack) {
|
||||
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
if (te instanceof IDirectionalTile) {
|
||||
((IDirectionalTile)te).setFacing(state.getValue(IEProperties.FACING_ALL));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return state.getValue(type).ordinal();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
|
||||
EntityPlayer player) {
|
||||
return new ItemStack(this, 1, damageDropped(state));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks.converter;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum MechanicalBlockType implements IStringSerializable {
|
||||
IE_MOTOR,
|
||||
IE_TO_IC2,
|
||||
IC2_TO_IE;
|
||||
public static final MechanicalBlockType[] values = values();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks.converter;
|
||||
|
||||
import blusunrize.immersiveengineering.api.energy.IRotationAcceptor;
|
||||
import blusunrize.immersiveengineering.api.energy.immersiveflux.FluxStorage;
|
||||
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import malte0811.industrialWires.IWConfig.MechConversion;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWBase;
|
||||
import malte0811.industrialWires.util.ConversionUtil;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IFluxReceiver, IDirectionalTile {
|
||||
public static final double bufferMax = 2*MechConversion.maxIfToMech*ConversionUtil.rotPerIf();
|
||||
|
||||
private double rotBuffer = 0;
|
||||
private FluxStorage energy = new FluxStorage(20*MechConversion.maxIfToMech, 2*MechConversion.maxIfToMech);
|
||||
private EnumFacing dir = EnumFacing.DOWN;
|
||||
private BlockPos receiver;
|
||||
@Override
|
||||
public void update() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (receiver==null) {
|
||||
receiver = pos.offset(dir);
|
||||
}
|
||||
int max = MechConversion.maxIfToMech;
|
||||
boolean dirty = false;
|
||||
if (rotBuffer<bufferMax&&energy.extractEnergy(max, true)>0) {
|
||||
int extracted = energy.extractEnergy(max, false);
|
||||
rotBuffer += extracted*ConversionUtil.rotPerIf()*MechConversion.ifMotorEfficiency;
|
||||
dirty = true;
|
||||
}
|
||||
TileEntity te = worldObj.getTileEntity(receiver);
|
||||
if (te instanceof IRotationAcceptor) {
|
||||
//TODO maybe get inputRotation changed to return a double? Would make this more user-friendly
|
||||
((IRotationAcceptor)te).inputRotation(rotBuffer, dir);
|
||||
rotBuffer = 0;
|
||||
dirty = true;
|
||||
}
|
||||
if (dirty) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void readNBT(NBTTagCompound in, boolean updatePacket) {
|
||||
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
|
||||
energy.readFromNBT(in.getCompoundTag(ENERGY_TAG));
|
||||
receiver = null;
|
||||
rotBuffer = in.getDouble(BUFFER_TAG);
|
||||
}
|
||||
@Override
|
||||
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
|
||||
out.setByte(DIR_TAG, (byte) dir.getIndex());
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
energy.writeToNBT(nbt);
|
||||
out.setTag(ENERGY_TAG, nbt);
|
||||
out.setDouble(BUFFER_TAG, rotBuffer);
|
||||
}
|
||||
|
||||
// Flux energy
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
return from==dir.getOpposite();
|
||||
}
|
||||
@Override
|
||||
public int receiveEnergy(EnumFacing from, int energyIn, boolean simulate) {
|
||||
if (from!=dir) {
|
||||
int ret = energy.receiveEnergy(energyIn, simulate);
|
||||
markDirty();
|
||||
return ret;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
return energy.getEnergyStored();
|
||||
}
|
||||
@Override
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
return energy.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
// Directional
|
||||
@Override
|
||||
public EnumFacing getFacing() {
|
||||
return dir;
|
||||
}
|
||||
@Override
|
||||
public void setFacing(EnumFacing facing) {
|
||||
dir = facing;
|
||||
receiver = null;
|
||||
markDirty();
|
||||
}
|
||||
@Override
|
||||
public int getFacingLimitation() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks.converter;
|
||||
|
||||
import blusunrize.immersiveengineering.api.energy.IRotationAcceptor;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import ic2.api.energy.tile.IKineticSource;
|
||||
import malte0811.industrialWires.IWConfig.MechConversion;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWBase;
|
||||
import malte0811.industrialWires.util.ConversionUtil;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirectionalTile, ITickable {
|
||||
EnumFacing dir = EnumFacing.DOWN;
|
||||
int kinBuffer = 0;
|
||||
private static final int kinBufMax = 2*MechConversion.maxKinToRot;
|
||||
private static final double maxInsert = ConversionUtil.rotPerKin()*MechConversion.maxKinToRot;
|
||||
BlockPos to;
|
||||
BlockPos from;
|
||||
@Override
|
||||
public void update() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (to==null) {
|
||||
to = pos.offset(dir);
|
||||
}
|
||||
if (from==null) {
|
||||
from = pos.offset(dir, -1);
|
||||
}
|
||||
TileEntity teFrom = worldObj.getTileEntity(from);
|
||||
if (teFrom instanceof IKineticSource) {
|
||||
int sourceMax = ((IKineticSource) teFrom).maxrequestkineticenergyTick(dir);
|
||||
int draw = Math.min(kinBufMax-kinBuffer, sourceMax);
|
||||
if (draw>0) {
|
||||
kinBuffer += ((IKineticSource) teFrom).requestkineticenergy(dir, draw)*MechConversion.kinToRotEfficiency;
|
||||
}
|
||||
}
|
||||
TileEntity teTo = worldObj.getTileEntity(to);
|
||||
if (kinBuffer>0&&teTo instanceof IRotationAcceptor) {
|
||||
double out = Math.min(maxInsert, ConversionUtil.rotPerKin()*kinBuffer);
|
||||
((IRotationAcceptor) teTo).inputRotation(out, dir);
|
||||
kinBuffer -= out*ConversionUtil.kinPerRot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
|
||||
out.setByte(DIR_TAG, (byte) dir.getIndex());
|
||||
out.setInteger(BUFFER_TAG, kinBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(NBTTagCompound in, boolean updatePacket) {
|
||||
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
|
||||
kinBuffer = in.getInteger(BUFFER_TAG);
|
||||
to = null;
|
||||
from = null;
|
||||
}
|
||||
// Directional
|
||||
@Override
|
||||
public EnumFacing getFacing() {
|
||||
return dir;
|
||||
}
|
||||
@Override
|
||||
public void setFacing(EnumFacing facing) {
|
||||
dir = facing;
|
||||
to = null;
|
||||
from = null;
|
||||
markDirty();
|
||||
}
|
||||
@Override
|
||||
public int getFacingLimitation() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.blocks.converter;
|
||||
|
||||
import blusunrize.immersiveengineering.api.energy.IRotationAcceptor;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import ic2.api.energy.tile.IKineticSource;
|
||||
import malte0811.industrialWires.IWConfig.MechConversion;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWBase;
|
||||
import malte0811.industrialWires.util.ConversionUtil;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirectionalTile, IRotationAcceptor, IKineticSource {
|
||||
EnumFacing dir = EnumFacing.DOWN;
|
||||
double rotBuffer = 0;
|
||||
private static final double rotBufMax = 2*MechConversion.maxRotToKin;
|
||||
private static final int maxOutput = (int)(ConversionUtil.kinPerRot()*MechConversion.maxRotToKin);
|
||||
|
||||
@Override
|
||||
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
|
||||
out.setByte(DIR_TAG, (byte) dir.getIndex());
|
||||
out.setDouble(BUFFER_TAG, rotBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(NBTTagCompound in, boolean updatePacket) {
|
||||
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
|
||||
rotBuffer = in.getDouble(BUFFER_TAG);
|
||||
}
|
||||
// Directional
|
||||
@Override
|
||||
public EnumFacing getFacing() {
|
||||
return dir;
|
||||
}
|
||||
@Override
|
||||
public void setFacing(EnumFacing facing) {
|
||||
dir = facing;
|
||||
markDirty();
|
||||
}
|
||||
@Override
|
||||
public int getFacingLimitation() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
|
||||
return true;
|
||||
}
|
||||
//IC2 kinetic
|
||||
@Override
|
||||
public int maxrequestkineticenergyTick(EnumFacing f) {
|
||||
if (f==dir) {
|
||||
return maxOutput;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int requestkineticenergy(EnumFacing f, int requested) {
|
||||
if (f==dir) {
|
||||
int stored = (int) (ConversionUtil.kinPerRot()*rotBuffer);
|
||||
int out = Math.min(maxOutput, stored);
|
||||
out = Math.min(requested, out);
|
||||
rotBuffer -= out*ConversionUtil.rotPerKin();
|
||||
return (int)(out*MechConversion.rotToKinEfficiency);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//IE rotation
|
||||
@Override
|
||||
public void inputRotation(double rotation, EnumFacing side) {
|
||||
if (side==dir) {
|
||||
rotBuffer = Math.min(rotBufMax, rotBuffer+rotation);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016 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.util;
|
||||
|
||||
import blusunrize.immersiveengineering.common.Config;
|
||||
import malte0811.industrialWires.IWConfig.MechConversion;
|
||||
|
||||
public class ConversionUtil {
|
||||
private ConversionUtil() {}
|
||||
public static double rotPerIf() {
|
||||
return 1/Config.IEConfig.Machines.dynamo_output;
|
||||
}
|
||||
public static double ifPerRot() {
|
||||
return Config.IEConfig.Machines.dynamo_output;
|
||||
}
|
||||
public static double euPerIfIdeal() {
|
||||
return MechConversion.euPerIf;
|
||||
}
|
||||
public static double ifPerEuIdeal() {
|
||||
return 1/MechConversion.euPerIf;
|
||||
}
|
||||
public static double euPerKin() {
|
||||
return MechConversion.kinPerEu;
|
||||
}
|
||||
public static double kinPerEu() {
|
||||
return 1/euPerKin();
|
||||
}
|
||||
public static double kinPerRot() {
|
||||
return kinPerEu()*euPerIfIdeal()*ifPerRot();
|
||||
}
|
||||
public static double rotPerKin() {
|
||||
return 1/kinPerRot();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue