Adapted to the changes in wiring code for the next IE release
This commit is contained in:
parent
ff3c391ac5
commit
93fb75a0b0
|
@ -70,7 +70,7 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
deobfCompile 'net.industrial-craft:industrialcraft-2:2.8.+'
|
||||
deobfCompile "blusunrize:ImmersiveEngineering:0.12-+:deobf"
|
||||
//TODO readd when the wirechanges are on master deobfCompile "blusunrize:ImmersiveEngineering:0.12-+:deobf"
|
||||
compileOnly "TechReborn:TechReborn-1.12:2.6.+:dev"
|
||||
compileOnly "RebornCore:RebornCore-1.12:3.2.+:dev"
|
||||
deobfCompile 'com.elytradev:mirage:2.0.1-SNAPSHOT'
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
*/
|
||||
package malte0811.industrialWires;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface IIC2Connector {
|
||||
/**
|
||||
* @return leftover energy.
|
||||
*/
|
||||
double insertEnergy(double eu, boolean simulate);
|
||||
void addAvailableEnergy(double amount, Consumer<Double> consume);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package malte0811.industrialWires;
|
|||
|
||||
import blusunrize.immersiveengineering.ImmersiveEngineering;
|
||||
import blusunrize.immersiveengineering.api.MultiblockHandler;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.WireApi;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import malte0811.industrialWires.blocks.BlockIWBase;
|
||||
import malte0811.industrialWires.blocks.controlpanel.*;
|
||||
import malte0811.industrialWires.blocks.converter.BlockMechanicalConverter;
|
||||
|
@ -46,6 +48,7 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
@ -65,6 +68,9 @@ import org.apache.logging.log4j.Logger;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static malte0811.industrialWires.blocks.wire.BlockTypes_IC2_Connector.*;
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.*;
|
||||
|
||||
@Mod(modid = IndustrialWires.MODID, version = IndustrialWires.VERSION, dependencies = "required-after:immersiveengineering@[0.12-72,);after:ic2",
|
||||
certificateFingerprint = "7e11c175d1e24007afec7498a1616bef0000027d")
|
||||
@Mod.EventBusSubscriber
|
||||
|
@ -210,6 +216,34 @@ public class IndustrialWires {
|
|||
packetHandler.registerMessage(MessageGUIInteract.HandlerServer.class, MessageGUIInteract.class, 2, Side.SERVER);
|
||||
packetHandler.registerMessage(MessageItemSync.HandlerServer.class, MessageItemSync.class, 3, Side.SERVER);
|
||||
|
||||
if (hasIC2) {
|
||||
ResourceLocation tex = new ResourceLocation(MODID, "blocks/ic2_conn_tin");
|
||||
float[] uvs = {3, 4, 11, 12};
|
||||
WireApi.registerFeedthroughForWiretype(TIN, new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_tin"), tex, uvs, .5, .5,
|
||||
(state) -> state.getBlock() == ic2conn && state.getValue(BlockIC2Connector.TYPE) == TIN_CONN);
|
||||
|
||||
WireApi.registerFeedthroughForWiretype(COPPER_IC2, new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_copper"), tex, uvs, .5, .5,
|
||||
(state) -> state.getBlock() == ic2conn && state.getValue(BlockIC2Connector.TYPE) == COPPER_CONN);
|
||||
|
||||
WireApi.registerFeedthroughForWiretype(GOLD, new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_gold"), tex, uvs, .5625, .5625,
|
||||
(state) -> state.getBlock() == ic2conn && state.getValue(BlockIC2Connector.TYPE) == GOLD_CONN);
|
||||
|
||||
WireApi.registerFeedthroughForWiretype(HV, new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_hv"), tex, uvs, .75, .75,
|
||||
(state) -> state.getBlock() == ic2conn && state.getValue(BlockIC2Connector.TYPE) == HV_CONN);
|
||||
|
||||
WireApi.registerFeedthroughForWiretype(GLASS, new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_glass"), tex, uvs, .75, .75,
|
||||
(state) -> state.getBlock() == ic2conn && state.getValue(BlockIC2Connector.TYPE) == GLASS_CONN);
|
||||
}
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
IWPotions.init();
|
||||
Compat.init();
|
||||
|
|
|
@ -50,6 +50,8 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static blusunrize.immersiveengineering.api.energy.wires.WireType.REDSTONE_CATEGORY;
|
||||
|
||||
public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implements IRedstoneConnector, ITickable, INetGUI, IEBlockInterfaces.IDirectionalTile, IBlockBoundsIW {
|
||||
private byte[] out = new byte[16];
|
||||
private boolean dirty = true;
|
||||
|
@ -237,7 +239,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
|
|||
|
||||
@Override
|
||||
public boolean canConnectCable(WireType wire, TargetingInfo targetingInfo) {
|
||||
return wire == WireType.REDSTONE && !hasConn;
|
||||
return REDSTONE_CATEGORY.equals(wire.getCategory()) && !hasConn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -71,10 +71,13 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static blusunrize.immersiveengineering.api.energy.wires.WireType.REDSTONE_CATEGORY;
|
||||
import static malte0811.industrialWires.blocks.hv.TileEntityMarx.FiringState.FIRE;
|
||||
import static malte0811.industrialWires.util.MiscUtils.getOffset;
|
||||
import static malte0811.industrialWires.util.MiscUtils.offset;
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.IC2_HV_CAT;
|
||||
import static net.minecraft.item.EnumDyeColor.*;
|
||||
|
||||
/**
|
||||
|
@ -546,6 +549,11 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
//TODO
|
||||
@Override
|
||||
public void addAvailableEnergy(double amount, Consumer<Double> consume) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getConnectionMaster(@Nullable WireType cableType, TargetingInfo target) {
|
||||
|
@ -558,9 +566,9 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
|
|||
return false;
|
||||
}
|
||||
if (getRight()==0) {
|
||||
return cableType==WireType.REDSTONE;
|
||||
return REDSTONE_CATEGORY.equals(cableType.getCategory());
|
||||
} else {
|
||||
return cableType==WireType.STEEL||cableType== IC2Wiretype.IC2_TYPES[3];
|
||||
return WireType.HV_CATEGORY.equals(cableType.getCategory())|| IC2_HV_CAT.equals(cableType.getCategory());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -571,7 +579,7 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
|
|||
|
||||
@Override
|
||||
public WireType getCableLimiter(TargetingInfo target) {
|
||||
return getRight()==0?WireType.REDSTONE:IC2Wiretype.IC2_TYPES[3];
|
||||
return getRight()==0?WireType.REDSTONE:IC2Wiretype.HV;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,7 +47,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
||||
private static final PropertyEnum<BlockTypes_IC2_Connector> type = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
|
||||
public static final PropertyEnum<BlockTypes_IC2_Connector> TYPE = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
|
||||
public static final String NAME = "ic2_connector";
|
||||
|
||||
public BlockIC2Connector() {
|
||||
|
@ -71,7 +71,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
|||
|
||||
@Override
|
||||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
for (int i = 0; i < type.getAllowedValues().size(); i++) {
|
||||
for (int i = 0; i < TYPE.getAllowedValues().size(); i++) {
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
|||
|
||||
@Override
|
||||
protected IProperty<?>[] getProperties() {
|
||||
return new IProperty[]{type, IEProperties.FACING_ALL};
|
||||
return new IProperty[]{TYPE, IEProperties.FACING_ALL};
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -105,7 +105,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
|||
@Nonnull
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return super.getStateFromMeta(meta).withProperty(type, BlockTypes_IC2_Connector.values()[meta]);
|
||||
return super.getStateFromMeta(meta).withProperty(TYPE, BlockTypes_IC2_Connector.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,7 +120,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
|||
|
||||
@Override
|
||||
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
|
||||
switch (state.getValue(type)) {
|
||||
switch (state.getValue(TYPE)) {
|
||||
case TIN_CONN:
|
||||
return new TileEntityIC2ConnectorTin(false);
|
||||
case TIN_RELAY:
|
||||
|
@ -151,7 +151,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
|||
if (!stack.isEmpty() && stack.getMetadata() % 2 == 0) {
|
||||
int type = stack.getMetadata() / 2;
|
||||
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", type + 1));
|
||||
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", IC2Wiretype.IC2_TYPES[type].getTransferRate() / 8));
|
||||
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", IC2Wiretype.ALL[type].getTransferRate() / 8));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,6 +191,6 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
|
|||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(type).ordinal();
|
||||
return state.getValue(TYPE).ordinal();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ package malte0811.industrialWires.blocks.wire;
|
|||
import blusunrize.immersiveengineering.api.energy.wires.WireType;
|
||||
import malte0811.industrialWires.wires.IC2Wiretype;
|
||||
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.IC2_COPPER_CAT;
|
||||
|
||||
public class TileEntityIC2ConnectorCopper extends TileEntityIC2ConnectorTin {
|
||||
|
||||
public TileEntityIC2ConnectorCopper(boolean rel) {
|
||||
|
@ -31,12 +33,12 @@ public class TileEntityIC2ConnectorCopper extends TileEntityIC2ConnectorTin {
|
|||
|
||||
{
|
||||
tier = 2;
|
||||
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate() / 8;
|
||||
maxStored = IC2Wiretype.COPPER_IC2.getTransferRate() / 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(WireType t) {
|
||||
return t == IC2Wiretype.IC2_TYPES[1];
|
||||
return IC2_COPPER_CAT.equals(t.getCategory());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ package malte0811.industrialWires.blocks.wire;
|
|||
import blusunrize.immersiveengineering.api.energy.wires.WireType;
|
||||
import malte0811.industrialWires.wires.IC2Wiretype;
|
||||
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.IC2_GLASS_CAT;
|
||||
|
||||
public class TileEntityIC2ConnectorGlass extends TileEntityIC2ConnectorHV {
|
||||
public TileEntityIC2ConnectorGlass(boolean rel) {
|
||||
super(rel);
|
||||
|
@ -30,11 +32,11 @@ public class TileEntityIC2ConnectorGlass extends TileEntityIC2ConnectorHV {
|
|||
|
||||
{
|
||||
tier = 5;
|
||||
maxStored = IC2Wiretype.IC2_TYPES[4].getTransferRate() / 8;
|
||||
maxStored = IC2Wiretype.GLASS.getTransferRate() / 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(WireType t) {
|
||||
return t == IC2Wiretype.IC2_TYPES[4];
|
||||
return IC2_GLASS_CAT.equals(t.getCategory());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ import malte0811.industrialWires.wires.IC2Wiretype;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.IC2_GOLD_CAT;
|
||||
|
||||
public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
|
||||
|
||||
public TileEntityIC2ConnectorGold(boolean rel) {
|
||||
|
@ -35,12 +37,12 @@ public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
|
|||
|
||||
{
|
||||
tier = 3;
|
||||
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate() / 8;
|
||||
maxStored = IC2Wiretype.GOLD.getTransferRate() / 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(WireType t) {
|
||||
return t == IC2Wiretype.IC2_TYPES[2];
|
||||
return IC2_GOLD_CAT.equals(t.getCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,8 @@ import malte0811.industrialWires.wires.IC2Wiretype;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.IC2_HV_CAT;
|
||||
|
||||
public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
|
||||
|
||||
public TileEntityIC2ConnectorHV(boolean rel) {
|
||||
|
@ -35,12 +37,12 @@ public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
|
|||
|
||||
{
|
||||
tier = 4;
|
||||
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate() / 8;
|
||||
maxStored = IC2Wiretype.HV.getTransferRate() / 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(WireType t) {
|
||||
return t == IC2Wiretype.IC2_TYPES[3];
|
||||
return IC2_HV_CAT.equals(t.getCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,14 +19,10 @@ package malte0811.industrialWires.blocks.wire;
|
|||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.api.TargetingInfo;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.*;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.WireType;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
|
||||
import blusunrize.immersiveengineering.common.util.Utils;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
|
@ -37,24 +33,25 @@ import malte0811.industrialWires.IIC2Connector;
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.IBlockBoundsIW;
|
||||
import malte0811.industrialWires.wires.IC2Wiretype;
|
||||
import net.minecraft.entity.Entity;
|
||||
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.AxisAlignedBB;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static malte0811.industrialWires.wires.IC2Wiretype.IC2_TIN_CAT;
|
||||
|
||||
@Optional.InterfaceList({
|
||||
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = "ic2"),
|
||||
|
@ -71,7 +68,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
|||
//IE net to IC2 net buffer
|
||||
double outBuffer = 0;
|
||||
double maxToMachine = 0;
|
||||
double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate() / 8;
|
||||
double maxStored = IC2Wiretype.TIN.getTransferRate() / 8;
|
||||
int tier = 1;
|
||||
|
||||
TileEntityIC2ConnectorTin(boolean rel) {
|
||||
|
@ -86,32 +83,24 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
|||
if (first) {
|
||||
if (!world.isRemote&& IndustrialWires.hasIC2)
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
ImmersiveNetHandler.INSTANCE.onTEValidated(this);
|
||||
first = false;
|
||||
}
|
||||
if (!world.isRemote) {
|
||||
if (inBuffer > .1) {
|
||||
transferPower();
|
||||
}
|
||||
if (outBuffer>.1&&IndustrialWires.hasTechReborn) {
|
||||
TileEntity output = Utils.getExistingTileEntity(world, pos.offset(facing));
|
||||
if (output instanceof IEnergyInterfaceTile) {
|
||||
IEnergyInterfaceTile out = (IEnergyInterfaceTile) output;
|
||||
if (out.canAcceptEnergy(facing.getOpposite())) {
|
||||
outBuffer -= out.addEnergy(Math.min(outBuffer, maxToMachine));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void transferPower() {
|
||||
Set<AbstractConnection> conns = new HashSet<>(ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, world));
|
||||
Set<AbstractConnection> conns = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, world, true);
|
||||
Map<AbstractConnection, Pair<IIC2Connector, Double>> maxOutputs = new HashMap<>();
|
||||
double outputMax = Math.min(inBuffer, maxToNet);
|
||||
double sum = 0;
|
||||
for (AbstractConnection c : conns) {
|
||||
IImmersiveConnectable iic = ApiUtils.toIIC(c.end, world);
|
||||
if (iic instanceof IIC2Connector) {
|
||||
if (iic instanceof IIC2Connector&&iic.isEnergyOutput()) {
|
||||
double tmp = outputMax - ((IIC2Connector) iic).insertEnergy(outputMax, true);
|
||||
if (tmp > .00000001) {
|
||||
maxOutputs.put(c, new ImmutablePair<>((IIC2Connector) iic, tmp));
|
||||
|
@ -119,32 +108,40 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
|||
}
|
||||
}
|
||||
}
|
||||
if (sum < .0001) {
|
||||
return;
|
||||
}
|
||||
final double oldInBuf = outputMax;
|
||||
HashMap<Connection, Integer> transferedPerConn = ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension());
|
||||
for (AbstractConnection c : maxOutputs.keySet()) {
|
||||
Pair<IIC2Connector, Double> p = maxOutputs.get(c);
|
||||
double out = oldInBuf * p.getRight() / sum;
|
||||
double loss = getAverageLossRate(c);
|
||||
double inserted = out - p.getLeft().insertEnergy(out - loss, false);
|
||||
inBuffer -= inserted;
|
||||
float intermediaryLoss = 0;
|
||||
HashSet<IImmersiveConnectable> passedConnectors = new HashSet<>();
|
||||
double energyAtConn = inserted + loss;
|
||||
for (Connection sub : c.subConnections) {
|
||||
int transferredPerCon = transferedPerConn.getOrDefault(sub, 0);
|
||||
energyAtConn -= sub.cableType.getLossRatio() * sub.length;
|
||||
ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension()).put(sub, (int) (transferredPerCon + energyAtConn));
|
||||
IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, world);
|
||||
IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, world);
|
||||
if (subStart != null && passedConnectors.add(subStart))
|
||||
subStart.onEnergyPassthrough((int) (inserted - inserted * intermediaryLoss));
|
||||
if (subEnd != null && passedConnectors.add(subEnd))
|
||||
subEnd.onEnergyPassthrough((int) (inserted - inserted * intermediaryLoss));
|
||||
if (sum > .0001) {
|
||||
final double oldInBuf = outputMax;
|
||||
HashMap<Connection, Integer> transferedPerConn = ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension());
|
||||
for (Map.Entry<AbstractConnection, Pair<IIC2Connector, Double>> entry : maxOutputs.entrySet()) {
|
||||
Pair<IIC2Connector, Double> p = entry.getValue();
|
||||
AbstractConnection c = entry.getKey();
|
||||
double out = oldInBuf * p.getRight() / sum;
|
||||
double loss = getAverageLossRate(c);
|
||||
double inserted = out - p.getLeft().insertEnergy(out - loss, false);
|
||||
inBuffer -= inserted;
|
||||
float intermediaryLoss = 0;
|
||||
HashSet<IImmersiveConnectable> passedConnectors = new HashSet<>();
|
||||
double energyAtConn = inserted + loss;
|
||||
for (Connection sub : c.subConnections) {
|
||||
int transferredPerCon = transferedPerConn.getOrDefault(sub, 0);
|
||||
energyAtConn -= sub.cableType.getLossRatio() * sub.length;
|
||||
ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension()).put(sub, (int) (transferredPerCon + energyAtConn));
|
||||
IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, world);
|
||||
IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, world);
|
||||
if (subStart != null && passedConnectors.add(subStart))
|
||||
subStart.onEnergyPassthrough((int) (inserted - inserted * intermediaryLoss));
|
||||
if (subEnd != null && passedConnectors.add(subEnd))
|
||||
subEnd.onEnergyPassthrough((int) (inserted - inserted * intermediaryLoss));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inBuffer>0) {
|
||||
conns.stream().map((ac)->ApiUtils.toIIC(ac.end, world)).forEach((iic)-> {
|
||||
if (iic instanceof IIC2Connector) {
|
||||
((IIC2Connector) iic).addAvailableEnergy(inBuffer, (d)->inBuffer-=d);
|
||||
}
|
||||
});
|
||||
addAvailableEnergy(0D, null);
|
||||
}
|
||||
}
|
||||
|
||||
private double getAverageLossRate(AbstractConnection conn) {
|
||||
|
@ -189,12 +186,6 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
|||
first = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
|
||||
EnumFacing side = facing.getOpposite();
|
||||
return new Vec3d(.5 + side.getFrontOffsetX() * .0625, .5 + side.getFrontOffsetY() * .0625, .5 + side.getFrontOffsetZ() * .0625);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getConnectionOffset(Connection con) {
|
||||
EnumFacing side = facing.getOpposite();
|
||||
|
@ -213,12 +204,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectCable(WireType cableType, TargetingInfo target) {
|
||||
return (limitType == null || (this.isRelay() && limitType == cableType)) && canConnect(cableType);
|
||||
public boolean canConnectCable(WireType cableType, TargetingInfo target, Vec3i offset) {
|
||||
return (limitType == null || (this.isRelay() && WireApi.canMix(cableType, limitType))) && canConnect(cableType);
|
||||
}
|
||||
|
||||
public boolean canConnect(WireType t) {
|
||||
return t == IC2Wiretype.IC2_TYPES[0];
|
||||
return IC2_TIN_CAT.equals(t.getCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -277,6 +268,50 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
|
|||
markDirty();
|
||||
}
|
||||
|
||||
|
||||
private List<Pair<Double, Consumer<Double>>> sources = new ArrayList<>();
|
||||
private long lastSourceUpdate = 0;
|
||||
@Override
|
||||
public void addAvailableEnergy(double amount, Consumer<Double> consume) {
|
||||
long currentTime = world.getTotalWorldTime();
|
||||
if (lastSourceUpdate!=currentTime)
|
||||
{
|
||||
sources.clear();
|
||||
Pair<Double, Consumer<Double>> own = getOwnEnergyIC2();
|
||||
if (own!=null)
|
||||
sources.add(own);
|
||||
lastSourceUpdate = currentTime;
|
||||
}
|
||||
if (amount>0&&consume!=null)
|
||||
sources.add(new ImmutablePair<>(amount, consume));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Pair<Double,Consumer<Double>> getOwnEnergyIC2()
|
||||
{
|
||||
if (isRelay())
|
||||
return null;
|
||||
return new ImmutablePair<>(inBuffer, (d)->inBuffer -= d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamageAmount(Entity e, Connection c)
|
||||
{
|
||||
float max = getMaxDamage(c);
|
||||
if (max==0||world.getTotalWorldTime()-lastSourceUpdate>1)
|
||||
return 0;
|
||||
float energy = 0;
|
||||
for (int i = 0;i<sources.size()&&energy<max;i++) {
|
||||
energy += Math.min(sources.get(i).getLeft(), max-energy);
|
||||
}
|
||||
return (float) Math.ceil(energy/64);//Same as IC2 uses
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMaxDamage(Connection c) {
|
||||
return c.cableType.getTransferRate()/8;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid="ic2")
|
||||
public int getSourceTier() {
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ClientEventHandler {
|
|||
if (!player.getHeldItem(hand).isEmpty()) {
|
||||
ItemStack equipped = player.getHeldItem(hand);
|
||||
if (OreDictionary.itemMatches(new ItemStack(IndustrialWires.coil, 1, OreDictionary.WILDCARD_VALUE), equipped, false)) {
|
||||
IC2Wiretype type = IC2Wiretype.IC2_TYPES[equipped.getItemDamage()];
|
||||
IC2Wiretype type = IC2Wiretype.ALL[equipped.getItemDamage()];
|
||||
int color = type.getColour(null);
|
||||
String s = I18n.format(IndustrialWires.MODID + ".desc.wireLength", ItemIC2Coil.getLength(equipped));
|
||||
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 40, color, true);
|
||||
|
|
|
@ -19,8 +19,8 @@ package malte0811.industrialWires.client;
|
|||
|
||||
import blusunrize.immersiveengineering.api.ManualHelper;
|
||||
import blusunrize.immersiveengineering.api.ManualPageMultiblock;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.WireApi;
|
||||
import blusunrize.immersiveengineering.client.ClientUtils;
|
||||
import blusunrize.immersiveengineering.client.models.smart.ConnLoader;
|
||||
import blusunrize.immersiveengineering.common.Config;
|
||||
import blusunrize.immersiveengineering.common.util.Utils;
|
||||
import blusunrize.lib.manual.ManualInstance;
|
||||
|
@ -84,42 +84,42 @@ public class ClientProxy extends CommonProxy {
|
|||
public void preInit() {
|
||||
super.preInit();
|
||||
if (IndustrialWires.hasIC2) {
|
||||
ConnLoader.baseModels.put("ic2_conn_tin", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_conn_tin", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
WireApi.registerConnectorForRender("ic2_conn_tin", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_tin"));
|
||||
ConnLoader.baseModels.put("ic2_relay_tin", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_relay_tin", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
WireApi.registerConnectorForRender("ic2_relay_tin", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_relay_tin"));
|
||||
|
||||
ConnLoader.baseModels.put("ic2_conn_copper", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_conn_copper", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
WireApi.registerConnectorForRender("ic2_conn_copper", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_copper"));
|
||||
ConnLoader.baseModels.put("ic2_relay_copper", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_relay_copper", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
WireApi.registerConnectorForRender("ic2_relay_copper", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_relay_copper"));
|
||||
|
||||
ConnLoader.baseModels.put("ic2_conn_gold", new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_conn_gold", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
|
||||
WireApi.registerConnectorForRender("ic2_conn_gold", new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_gold"));
|
||||
ConnLoader.baseModels.put("ic2_relay_gold", new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_relay_gold", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
|
||||
WireApi.registerConnectorForRender("ic2_relay_gold", new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_relay_gold"));
|
||||
|
||||
ConnLoader.baseModels.put("ic2_conn_hv", new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_conn_hv", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
|
||||
WireApi.registerConnectorForRender("ic2_conn_hv", new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_hv"));
|
||||
ConnLoader.baseModels.put("ic2_relay_hv", new ResourceLocation("immersiveengineering:block/connector/relay_hv.obj"));
|
||||
WireApi.registerConnectorForRender("ic2_relay_hv", new ResourceLocation("immersiveengineering:block/connector/relay_hv.obj"), null);
|
||||
|
||||
ConnLoader.baseModels.put("ic2_conn_glass", new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_conn_glass", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
|
||||
WireApi.registerConnectorForRender("ic2_conn_glass", new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_conn_glass"));
|
||||
ConnLoader.baseModels.put("ic2_relay_glass", new ResourceLocation("immersiveengineering:block/connector/relay_hv.obj"));
|
||||
ConnLoader.textureReplacements.put("ic2_relay_glass", ImmutableMap.of("#immersiveengineering:blocks/connector_relay_hv",
|
||||
WireApi.registerConnectorForRender("ic2_relay_glass", new ResourceLocation("immersiveengineering:block/connector/relay_hv.obj"),
|
||||
ImmutableMap.of("#immersiveengineering:blocks/connector_relay_hv",
|
||||
IndustrialWires.MODID + ":blocks/ic2_relay_glass"));
|
||||
}
|
||||
ConnLoader.baseModels.put("rs_panel_conn", new ResourceLocation("industrialwires:block/rs_panel_conn.obj"));
|
||||
WireApi.registerConnectorForRender("rs_panel_conn", new ResourceLocation("industrialwires:block/rs_panel_conn.obj"), null);
|
||||
|
||||
ConnLoader.baseModels.put("empty", new ResourceLocation("builtin/generated"));
|
||||
WireApi.registerConnectorForRender("empty", new ResourceLocation("builtin/generated"), null);
|
||||
|
||||
OBJLoader.INSTANCE.addDomain(IndustrialWires.MODID);
|
||||
ModelLoaderRegistry.registerLoader(new PanelModelLoader());
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package malte0811.industrialWires.items;
|
||||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.api.Lib;
|
||||
import blusunrize.immersiveengineering.api.TargetingInfo;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
|
||||
|
@ -37,11 +38,13 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -85,14 +88,14 @@ public class ItemIC2Coil extends Item implements IWireCoil {
|
|||
|
||||
@Override
|
||||
public WireType getWireType(ItemStack stack) {
|
||||
return IC2Wiretype.IC2_TYPES[stack.getMetadata()];
|
||||
return IC2Wiretype.ALL[stack.getMetadata()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
|
||||
|
||||
tooltip.add(I18n.format(IndustrialWires.MODID + ".desc.wireLength", getLength(stack)));
|
||||
int transferRate = IC2Wiretype.IC2_TYPES[stack.getMetadata()].getTransferRate();
|
||||
int transferRate = IC2Wiretype.ALL[stack.getMetadata()].getTransferRate();
|
||||
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.transfer_rate", transferRate));
|
||||
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.input_rate", transferRate / 8));
|
||||
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("linkingPos")) {
|
||||
|
@ -109,7 +112,7 @@ public class ItemIC2Coil extends Item implements IWireCoil {
|
|||
@Override
|
||||
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
if (!world.isRemote && !stack.isEmpty()) {
|
||||
if (!stack.isEmpty()) {
|
||||
if (stack.getCount() > 1) {
|
||||
player.sendMessage(new TextComponentTranslation(IndustrialWires.MODID + ".chat.stackSize"));
|
||||
return EnumActionResult.FAIL;
|
||||
|
@ -119,97 +122,115 @@ public class ItemIC2Coil extends Item implements IWireCoil {
|
|||
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
|
||||
WireType wire = getWireType(stack);
|
||||
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
|
||||
Vec3i offset = pos.subtract(masterPos);
|
||||
tileEntity = world.getTileEntity(masterPos);
|
||||
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect()) {
|
||||
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
|
||||
if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target, offset)) {
|
||||
if (!world.isRemote)
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
|
||||
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ()});
|
||||
target.writeToNBT(stack.getTagCompound());
|
||||
} else {
|
||||
WireType type = getWireType(stack);
|
||||
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
|
||||
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
|
||||
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
|
||||
int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
|
||||
if (array[0] != world.provider.getDimension()) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
|
||||
} else if (linkPos.equals(masterPos)) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
|
||||
} else if (distanceSq > (type.getMaxLength() * type.getMaxLength())) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
|
||||
} else if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(type, TargetingInfo.readFromNBT(stack.getTagCompound()))) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
|
||||
if (!world.isRemote)
|
||||
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
|
||||
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ(),
|
||||
offset.getX(), offset.getY(), offset.getZ()});
|
||||
NBTTagCompound targetNbt = new NBTTagCompound();
|
||||
target.writeToNBT(targetNbt);
|
||||
ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
|
||||
} else {
|
||||
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
|
||||
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
|
||||
boolean connectionExists = false;
|
||||
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
|
||||
if (outputs != null) {
|
||||
for (Connection con : outputs) {
|
||||
if (con.end.equals(Utils.toCC(nodeLink))) {
|
||||
connectionExists = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (connectionExists) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
|
||||
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
|
||||
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
|
||||
Vec3i offsetLink = BlockPos.NULL_VECTOR;
|
||||
if (array.length == 7)
|
||||
offsetLink = new Vec3i(array[4], array[5], array[6]);
|
||||
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
|
||||
int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
|
||||
if (array[0] != world.provider.getDimension()) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
|
||||
} else if (linkPos.equals(masterPos)) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
|
||||
} else if (distanceSq > (wire.getMaxLength() * wire.getMaxLength())) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
|
||||
} else {
|
||||
Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
|
||||
Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
|
||||
Set<BlockPos> ignore = new HashSet<>();
|
||||
ignore.addAll(nodeHere.getIgnored(nodeLink));
|
||||
ignore.addAll(nodeLink.getIgnored(nodeHere));
|
||||
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
|
||||
if (canSee) {
|
||||
int lengthOnStack = getLength(stack);
|
||||
int length = (int) Math.sqrt(distanceSq);
|
||||
if (length <= lengthOnStack) {
|
||||
TargetingInfo targetLink = TargetingInfo.readFromNBT(stack.getTagCompound());
|
||||
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), length, type);
|
||||
|
||||
nodeHere.connectCable(type, target, nodeLink);
|
||||
nodeLink.connectCable(type, targetLink, nodeHere);
|
||||
IESaveData.setDirty(world.provider.getDimension());
|
||||
Utils.unlockIEAdvancement(player, "main/connect_wire");
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
if (length < lengthOnStack) {
|
||||
setLength(stack, lengthOnStack - length);
|
||||
} else {
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
|
||||
if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink, offset)) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
|
||||
} else {
|
||||
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
|
||||
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
|
||||
boolean connectionExists = false;
|
||||
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
|
||||
if (outputs != null) {
|
||||
for (Connection con : outputs) {
|
||||
if (con.end.equals(Utils.toCC(nodeLink))) {
|
||||
connectionExists = true;
|
||||
}
|
||||
}
|
||||
((TileEntity) nodeHere).markDirty();
|
||||
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
|
||||
IBlockState state = world.getBlockState(masterPos);
|
||||
world.notifyBlockUpdate(masterPos, state, state, 3);
|
||||
((TileEntity) nodeLink).markDirty();
|
||||
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
|
||||
state = world.getBlockState(linkPos);
|
||||
world.notifyBlockUpdate(linkPos, state, state, 3);
|
||||
} else {
|
||||
player.sendMessage(new TextComponentTranslation(IndustrialWires.MODID + ".chat.tooLong"));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
|
||||
if (connectionExists) {
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
|
||||
} else {
|
||||
Set<BlockPos> ignore = new HashSet<>();
|
||||
ignore.addAll(nodeHere.getIgnored(nodeLink));
|
||||
ignore.addAll(nodeLink.getIgnored(nodeHere));
|
||||
Connection tmpConn = new Connection(Utils.toCC(nodeHere), Utils.toCC(nodeLink), wire,
|
||||
(int) Math.sqrt(distanceSq));
|
||||
Vec3d start = nodeHere.getConnectionOffset(tmpConn, target, pos.subtract(masterPos)).addVector(tileEntity.getPos().getX(),
|
||||
tileEntity.getPos().getY(), tileEntity.getPos().getZ());
|
||||
Vec3d end = nodeLink.getConnectionOffset(tmpConn, targetLink, offsetLink).addVector(tileEntityLinkingPos.getPos().getX(),
|
||||
tileEntityLinkingPos.getPos().getY(), tileEntityLinkingPos.getPos().getZ());
|
||||
boolean canSee = ApiUtils.raytraceAlongCatenary(tmpConn, (p) -> {
|
||||
if (ignore.contains(p.getLeft())) {
|
||||
return false;
|
||||
}
|
||||
IBlockState state = world.getBlockState(p.getLeft());
|
||||
return ApiUtils.preventsConnection(world, p.getLeft(), state, p.getMiddle(), p.getRight());
|
||||
}, (p) -> {
|
||||
}, start, end);
|
||||
if (canSee) {
|
||||
int lengthOnStack = getLength(stack);
|
||||
int length = (int) Math.sqrt(distanceSq);
|
||||
if (length <= lengthOnStack) {
|
||||
Connection conn = ImmersiveNetHandler.INSTANCE.addAndGetConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink),
|
||||
(int) Math.sqrt(distanceSq), wire);
|
||||
|
||||
|
||||
nodeHere.connectCable(wire, target, nodeLink, offset);
|
||||
nodeLink.connectCable(wire, targetLink, nodeHere, offsetLink);
|
||||
ImmersiveNetHandler.INSTANCE.addBlockData(world, conn);
|
||||
IESaveData.setDirty(world.provider.getDimension());
|
||||
Utils.unlockIEAdvancement(player, "main/connect_wire");
|
||||
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
if (length < lengthOnStack) {
|
||||
setLength(stack, lengthOnStack - length);
|
||||
} else {
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
((TileEntity) nodeHere).markDirty();
|
||||
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
|
||||
IBlockState state = world.getBlockState(masterPos);
|
||||
world.notifyBlockUpdate(masterPos, state, state, 3);
|
||||
((TileEntity) nodeLink).markDirty();
|
||||
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
|
||||
state = world.getBlockState(linkPos);
|
||||
world.notifyBlockUpdate(linkPos, state, state, 3);
|
||||
} else
|
||||
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemNBTHelper.remove(stack, "linkingPos");
|
||||
ItemNBTHelper.remove(stack, "targettingInfo");
|
||||
}
|
||||
ItemNBTHelper.remove(stack, "linkingPos");
|
||||
ItemNBTHelper.remove(stack, "side");
|
||||
ItemNBTHelper.remove(stack, "hitX");
|
||||
ItemNBTHelper.remove(stack, "hitY");
|
||||
ItemNBTHelper.remove(stack, "hitZ");
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
@ -222,7 +243,7 @@ public class ItemIC2Coil extends Item implements IWireCoil {
|
|||
if (i.getTagCompound() == null) {
|
||||
setLength(i, 4);
|
||||
}
|
||||
return i.getTagCompound().getInteger(lengthKey)*i.getCount();
|
||||
return ItemNBTHelper.getInt(i, lengthKey)*i.getCount();
|
||||
}
|
||||
|
||||
public static int getMaxWireLength(ItemStack i) {
|
||||
|
|
|
@ -19,6 +19,7 @@ package malte0811.industrialWires.wires;
|
|||
|
||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.WireApi;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.WireType;
|
||||
import malte0811.industrialWires.IWConfig;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
|
@ -28,18 +29,34 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class IC2Wiretype extends WireType {
|
||||
public static final String IC2_TIN_CAT = "IC_TIN";
|
||||
public static final String IC2_COPPER_CAT = "IC_COPPER";
|
||||
public static final String IC2_GOLD_CAT = "IC_GOLD";
|
||||
public static final String IC2_HV_CAT = "IC_HV";
|
||||
public static final String IC2_GLASS_CAT = "IC_GLASS";
|
||||
private final int type;
|
||||
private final int[] ic2Rates = {32 * 8, 128 * 8, 512 * 8, 2048 * 8, 8192 * 8};
|
||||
private final int[] ic2Colors = {0xa5bcc7, 0xbc7945, 0xfeff73, 0xb9d6d9, 0xf1f1f1};
|
||||
private final String[] ic2Names = {"ic2Tin", "ic2Copper", "ic2Gold", "ic2Hv", "ic2Glass"};
|
||||
private final double[] lossPerBlock = {.2, .2, .4, .8, .025};
|
||||
private final double[] ic2RenderDiameter = {.03125, .03125, .046875, .0625, .75 * .03125};
|
||||
public static final IC2Wiretype[] IC2_TYPES = {new IC2Wiretype(0), new IC2Wiretype(1), new IC2Wiretype(2), new IC2Wiretype(3), new IC2Wiretype(4)};
|
||||
|
||||
public static final IC2Wiretype TIN = new IC2Wiretype(0);
|
||||
public static final IC2Wiretype COPPER_IC2 = new IC2Wiretype(1);
|
||||
public static final IC2Wiretype GOLD = new IC2Wiretype(2);
|
||||
public static final IC2Wiretype HV = new IC2Wiretype(3);
|
||||
public static final IC2Wiretype GLASS = new IC2Wiretype(4);
|
||||
public static final IC2Wiretype[] ALL = {
|
||||
TIN, COPPER_IC2, GOLD, HV, GLASS
|
||||
};
|
||||
|
||||
public IC2Wiretype(int ordinal) {
|
||||
super();
|
||||
this.type = ordinal;
|
||||
WireApi.registerWireType(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,4 +119,35 @@ public class IC2Wiretype extends WireType {
|
|||
public boolean isEnergyWire() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCauseDamage() {
|
||||
return type<4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDamageRadius() {
|
||||
if (type>=4) {
|
||||
return 0;
|
||||
}
|
||||
return .3/4*(type+1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getCategory() {
|
||||
switch (type) {
|
||||
case 0:
|
||||
return IC2_TIN_CAT;
|
||||
case 1:
|
||||
return IC2_COPPER_CAT;
|
||||
case 2:
|
||||
return IC2_GOLD_CAT;
|
||||
case 3:
|
||||
return IC2_HV_CAT;
|
||||
case 4:
|
||||
return IC2_GLASS_CAT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue