Skip to content

Commit

Permalink
#161 Immersive Engineering integration
Browse files Browse the repository at this point in the history
Re-connects Immersive Engineering wires if one connector moves.
Correctly handles one and both connectors being on a carriage package,
but not if the connectors are moved simultaneously on different carriage
packages.
  • Loading branch information
planetguy32 committed Aug 2, 2015
1 parent c9c749a commit 0569890
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.planetguy.remaininmotion.core.interop.mod.ChickenChunks;
import me.planetguy.remaininmotion.core.interop.mod.EnderIO;
import me.planetguy.remaininmotion.core.interop.mod.ForgeMultipart;
import me.planetguy.remaininmotion.core.interop.mod.ImmersiveEngineering;
import me.planetguy.remaininmotion.core.interop.mod.QmunityMultipart;
import me.planetguy.remaininmotion.drive.TileEntityCarriageController;
import me.planetguy.remaininmotion.util.general.Computers;
Expand Down Expand Up @@ -61,6 +62,10 @@ public static void Establish() {
EventManager.registerEventHandler(new CarpentersBlocks());
}

if(true) { //for debugging - I've had to change IE's modID Loader.isModLoaded("ImmersiveEngineering")) {
EventManager.registerEventHandler(new ImmersiveEngineering());
}

Wrenches.init();

Computers.setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package me.planetguy.remaininmotion.core.interop.mod;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChunkCoordinates;
import blusunrize.immersiveengineering.api.energy.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.WireType;
import blusunrize.immersiveengineering.api.energy.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.common.blocks.metal.TileEntityConnectorLV;
import blusunrize.immersiveengineering.common.util.Utils;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import me.planetguy.remaininmotion.api.event.BlockPreMoveEvent;
import me.planetguy.remaininmotion.api.event.TEPostPlaceEvent;
import me.planetguy.remaininmotion.util.position.BlockRecord;

public class ImmersiveEngineering {

@SubscribeEvent
public void onBlockPreMoveEvent(BlockPreMoveEvent e) {
if(e.location.entity() instanceof IImmersiveConnectable) {
ChunkCoordinates teLoc=Utils.toCC(e.location.entity());
NBTTagList ls=new NBTTagList();
e.location.entityTag().setTag("RemIM_links", ls);
for(Connection c:ImmersiveNetHandler.INSTANCE
.getConnections(
e.location.entity().getWorldObj(),
teLoc)) {
NBTTagCompound t=new NBTTagCompound();
ls.appendTag(t);
t.setString("wire", c.cableType.getUniqueName());
t.setDouble("distance", c.length);
if(c.start.equals(teLoc)) {
//relative to TE
if(e.blocks.contains(new BlockRecord(c.end.posX, c.end.posY, c.end.posZ))) {
t.setBoolean("absolute", false);
t.setInteger("x", c.end.posX-teLoc.posX);
t.setInteger("y", c.end.posY-teLoc.posY);
t.setInteger("z", c.end.posZ-teLoc.posZ);
} else {
t.setBoolean("absolute", true);
t.setInteger("x", c.end.posX);
t.setInteger("y", c.end.posY);
t.setInteger("z", c.end.posZ);
}
} else if(c.end.equals(teLoc)) {
if(e.blocks.contains(new BlockRecord(c.start.posX, c.start.posY, c.start.posZ))) {
t.setBoolean("absolute", false);
t.setInteger("x", c.start.posX-teLoc.posX);
t.setInteger("y", c.start.posY-teLoc.posY);
t.setInteger("z", c.start.posZ-teLoc.posZ);
} else {
t.setBoolean("absolute", true);
t.setInteger("x", c.start.posX);
t.setInteger("y", c.start.posY);
t.setInteger("z", c.start.posZ);
}
}
}
}
}

@SubscribeEvent
public void onTEPostPlaceEvent(TEPostPlaceEvent e) {
if(e.location.entity() instanceof IImmersiveConnectable) {
ChunkCoordinates teLoc=Utils.toCC(e.location.entity());
NBTTagList tag=e.location.entityTag().getTagList("RemIM_links", 10);
for(int i=0; i<tag.tagCount(); i++) {
NBTTagCompound conn=tag.getCompoundTagAt(i);
int x, y, z;
if(conn.getBoolean("absolute")) {
x=conn.getInteger("x");
y=conn.getInteger("y");
z=conn.getInteger("z");
}else {
x=conn.getInteger("x") + teLoc.posX;
y=conn.getInteger("y") + teLoc.posY;
z=conn.getInteger("z") + teLoc.posZ;
}
if(e.location.world().getTileEntity(x,y,z)
instanceof IImmersiveConnectable) {
WireType type=WireType.getValue(conn.getString("wire"));
ChunkCoordinates newPos=new ChunkCoordinates(x,y,z);
int distance=(int) Math.ceil(Math.sqrt(newPos.getDistanceSquaredToChunkCoordinates(teLoc)));
if(distance<=type.getMaxLength())
ImmersiveNetHandler.INSTANCE.addConnection(e.location.world(), teLoc, newPos, distance, type);
}
}
}
}

}

0 comments on commit 0569890

Please sign in to comment.