use of blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable in project ImmersiveEngineering by BluSunrize.
the class EventHandler method onWorldTick.
// @SubscribeEvent
// public void onEntityInteract(EntityInteractEvent event)
// {
// if(event.target instanceof EntityLivingBase && OreDictionary.itemMatches(new ItemStack(IEContent.itemRevolver,1,OreDictionary.WILDCARD_VALUE), event.entityPlayer.getCurrentEquippedItem(), false))
// event.setCanceled(true);
// }
@SubscribeEvent
public void onWorldTick(WorldTickEvent event) {
if (event.phase == TickEvent.Phase.START && validateConnsNextTick && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
boolean validateConnections = IEConfig.validateConnections;
int invalidConnectionsDropped = 0;
for (int dim : ImmersiveNetHandler.INSTANCE.getRelevantDimensions()) {
if (!validateConnections) {
continue;
}
World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dim);
if (world == null) {
ImmersiveNetHandler.INSTANCE.directConnections.remove(dim);
continue;
}
for (Connection con : ImmersiveNetHandler.INSTANCE.getAllConnections(world)) {
if (!(world.getTileEntity(con.start) instanceof IImmersiveConnectable && world.getTileEntity(con.end) instanceof IImmersiveConnectable)) {
ImmersiveNetHandler.INSTANCE.removeConnection(world, con);
invalidConnectionsDropped++;
}
}
IELogger.info("removed " + invalidConnectionsDropped + " invalid connections from world");
}
int invalidProxies = 0;
Set<DimensionBlockPos> toRemove = new HashSet<>();
for (Entry<DimensionBlockPos, IICProxy> e : ImmersiveNetHandler.INSTANCE.proxies.entrySet()) {
if (!validateConnections) {
continue;
}
DimensionBlockPos p = e.getKey();
World w = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(p.dimension);
if (w != null && w.isBlockLoaded(p))
toRemove.add(p);
if (validateConnections && w == null) {
invalidProxies++;
toRemove.add(p);
continue;
}
if (validateConnections && !(w.getTileEntity(p) instanceof IImmersiveConnectable)) {
invalidProxies++;
toRemove.add(p);
}
}
if (invalidProxies > 0)
IELogger.info("Removed " + invalidProxies + " invalid connector proxies (used to transfer power through unloaded chunks)");
validateConnsNextTick = false;
}
if (event.phase == TickEvent.Phase.END && ArcRecyclingThreadHandler.recipesToAdd != null) {
ArcFurnaceRecipe.recipeList.addAll(ArcRecyclingThreadHandler.recipesToAdd);
ArcRecyclingThreadHandler.recipesToAdd = null;
}
if (event.phase == TickEvent.Phase.END && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
for (Entry<Connection, Integer> e : ImmersiveNetHandler.INSTANCE.getTransferedRates(event.world.provider.getDimension()).entrySet()) if (e.getValue() > e.getKey().cableType.getTransferRate()) {
if (event.world instanceof WorldServer)
for (Vec3d vec : e.getKey().getSubVertices(event.world)) ((WorldServer) event.world).spawnParticle(EnumParticleTypes.FLAME, false, vec.xCoord, vec.yCoord, vec.zCoord, 0, 0, .02, 0, 1, new int[0]);
ImmersiveNetHandler.INSTANCE.removeConnection(event.world, e.getKey());
}
ImmersiveNetHandler.INSTANCE.getTransferedRates(event.world.provider.getDimension()).clear();
}
if (event.phase == TickEvent.Phase.START) {
if (!currentExplosions.isEmpty()) {
Iterator<IEExplosion> itExplosion = currentExplosions.iterator();
while (itExplosion.hasNext()) {
IEExplosion ex = itExplosion.next();
ex.doExplosionTick();
if (ex.isExplosionFinished)
itExplosion.remove();
}
}
synchronized (requestedBlockUpdates) {
while (!requestedBlockUpdates.isEmpty()) {
Pair<Integer, BlockPos> curr = requestedBlockUpdates.poll();
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
World w = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(curr.getLeft());
if (w != null) {
IBlockState state = w.getBlockState(curr.getRight());
w.notifyBlockUpdate(curr.getRight(), state, state, 3);
}
}
}
}
}
}
use of blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable in project ImmersiveEngineering by BluSunrize.
the class TileRenderImmersiveConnectable method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) {
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
// tes.draw();
if (te instanceof IImmersiveConnectable && te.getWorld() != null) {
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(te.getWorld(), Utils.toCC(te));
if (outputs != null) {
VertexBuffer worldrenderer = ClientUtils.tes().getBuffer();
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
// GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0F);
// GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0F);
GlStateManager.disableLighting();
GlStateManager.disableCull();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Iterator<Connection> itCon = outputs.iterator();
while (itCon.hasNext()) {
Connection con = itCon.next();
TileEntity tileEnd = te.getWorld().getTileEntity(con.end);
if (tileEnd instanceof IImmersiveConnectable) {
ClientUtils.tessellateConnection(con, (IImmersiveConnectable) te, ApiUtils.toIIC(tileEnd, te.getWorld()), con.cableType.getIcon(con));
}
}
GlStateManager.enableLighting();
GlStateManager.enableTexture2D();
ClientUtils.tes().draw();
}
}
GlStateManager.popMatrix();
}
use of blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable in project ImmersiveEngineering by BluSunrize.
the class ItemWireCoil method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
WireType wire = getWireType(stack);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
tileEntity = world.getTileEntity(masterPos);
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
return EnumActionResult.PASS;
if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
player.addChatMessage(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() });
NBTTagCompound targetNbt = new NBTTagCompound();
target.writeToNBT(targetNbt);
ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
} 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.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
else if (linkPos.equals(masterPos))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
else {
TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
player.addChatMessage(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;
}
if (connectionExists)
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
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) {
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
nodeHere.connectCable(type, target, nodeLink);
nodeLink.connectCable(type, targetLink, nodeHere);
IESaveData.setDirty(world.provider.getDimension());
player.addStat(IEAchievements.connectWire);
if (!player.capabilities.isCreativeMode)
stack.stackSize--;
((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.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
}
}
}
ItemNBTHelper.remove(stack, "linkingPos");
ItemNBTHelper.remove(stack, "targettingInfo");
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
use of blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable in project ImmersiveEngineering by BluSunrize.
the class SkylineHelper method spawnHook.
public static EntitySkylineHook spawnHook(EntityPlayer player, TileEntity start, Connection connection) {
BlockPos cc0 = connection.end == Utils.toCC(start) ? connection.start : connection.end;
BlockPos cc1 = connection.end == Utils.toCC(start) ? connection.end : connection.start;
IImmersiveConnectable iicStart = ApiUtils.toIIC(cc1, player.worldObj);
IImmersiveConnectable iicEnd = ApiUtils.toIIC(cc0, player.worldObj);
Vec3d vStart = new Vec3d(cc1);
Vec3d vEnd = new Vec3d(cc0);
if (iicStart != null)
vStart = Utils.addVectors(vStart, iicStart.getConnectionOffset(connection));
if (iicEnd != null)
vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
Vec3d[] steps = getConnectionCatenary(connection, vStart, vEnd);
double dx = (steps[0].xCoord - vStart.xCoord);
double dy = (steps[0].yCoord - vStart.yCoord);
double dz = (steps[0].zCoord - vStart.zCoord);
//connection.length;
double d = 1;
// Math.sqrt(dx*dx+dz*dz+dy*dy);
// Vec3 moveVec = Vec3.createVectorHelper(dx,dy,dz);
// Vec3 moveVec = Vec3.createVectorHelper(dx/d,dy/d,dz/d);
EntitySkylineHook hook = new EntitySkylineHook(player.worldObj, vStart.xCoord, vStart.yCoord, vStart.zCoord, connection, cc0, steps);
float speed = 1;
if (player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
Vec3d moveVec = getSubMovementVector(vStart, steps[0], speed);
//*speed;
hook.motionX = moveVec.xCoord;
//*speed;
hook.motionY = moveVec.yCoord;
//*speed;
hook.motionZ = moveVec.zCoord;
if (!player.worldObj.isRemote)
player.worldObj.spawnEntityInWorld(hook);
ItemSkyhook.existingHooks.put(player.getName(), hook);
player.startRiding(hook);
return hook;
}
use of blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable in project ImmersiveEngineering by BluSunrize.
the class SkylineHelper method getTargetConnection.
public static Connection getTargetConnection(World world, BlockPos pos, EntityLivingBase living, Connection invalidCon) {
if (!(world.getTileEntity(pos) instanceof IImmersiveConnectable))
return null;
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, pos);
if (outputs != null && outputs.size() > 0) {
Vec3d vec = living.getLookVec();
vec = vec.normalize();
Connection line = null;
for (Connection c : outputs) if (c != null && !c.hasSameConnectors(invalidCon)) {
if (line == null)
line = c;
else {
Vec3d lineVec = new Vec3d(line.end.getX() - line.start.getX(), line.end.getY() - line.start.getY(), line.end.getZ() - line.start.getZ()).normalize();
Vec3d conVec = new Vec3d(c.end.getX() - c.start.getX(), c.end.getY() - c.start.getY(), c.end.getZ() - c.start.getZ()).normalize();
if (conVec.distanceTo(vec) < lineVec.distanceTo(vec))
line = c;
}
}
return line;
}
return null;
}
Aggregations