use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.
the class FluidNetwork method refreshAcceptors.
public void refreshAcceptors() {
if (this.acceptors == null) {
this.acceptors = Maps.newHashMap();
} else {
this.acceptors.clear();
}
try {
Iterator<IBufferTransmitter<FluidStack>> it = this.pipes.iterator();
while (it.hasNext()) {
IBufferTransmitter<FluidStack> transmitter = it.next();
TileEntity tile = (TileEntity) transmitter;
if (transmitter == null || tile.isInvalid() || tile.getWorld() == null) {
it.remove();
continue;
}
if (!transmitter.canTransmit()) {
continue;
}
int i = 0;
for (TileEntity acceptor : transmitter.getAdjacentConnections()) {
if (!(acceptor instanceof IBufferTransmitter) && acceptor instanceof IFluidHandler) {
EnumFacing facing = EnumFacing.getFront(i).getOpposite();
BlockPos acceptorPos = tile.getPos().offset(facing.getOpposite());
EnumSet<EnumFacing> facingSet = this.acceptorDirections.get(acceptorPos);
if (facingSet != null) {
facingSet.add(facing);
} else {
facingSet = EnumSet.of(facing);
}
this.acceptors.put(acceptorPos, (IFluidHandler) acceptor);
this.acceptorDirections.put(acceptorPos, facingSet);
}
i++;
}
}
} catch (Exception e) {
FMLLog.severe("Failed to refresh liquid acceptors");
e.printStackTrace();
}
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.
the class FluidNetwork method refresh.
@Override
public void refresh() {
if (this.acceptors != null) {
this.acceptors.clear();
}
try {
Iterator<IBufferTransmitter<FluidStack>> it = this.pipes.iterator();
while (it.hasNext()) {
ITransmitter transmitter = it.next();
TileEntity tileTransmitter = (TileEntity) transmitter;
if (transmitter == null) {
it.remove();
continue;
}
transmitter.onNetworkChanged();
if (tileTransmitter.isInvalid() || tileTransmitter.getWorld() == null) {
it.remove();
continue;
} else {
if (this.worldObj == null) {
this.worldObj = tileTransmitter.getWorld();
}
transmitter.setNetwork(this);
}
}
updateCapacity();
clamp();
} catch (Exception e) {
FMLLog.severe("Failed to refresh liquid pipe network.");
e.printStackTrace();
}
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.
the class TileEntityFluidPipeRenderer method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntityFluidPipe pipe, double x, double y, double z, float partialTicks, int destroyStage) {
updateModels();
if (pipe.getBlockType() == GCBlocks.oxygenPipePull) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
RenderHelper.disableStandardItemLighting();
this.bindTexture(TextureMap.locationBlocksTexture);
if (Minecraft.isAmbientOcclusionEnabled()) {
GlStateManager.shadeModel(GL11.GL_SMOOTH);
} else {
GlStateManager.shadeModel(GL11.GL_FLAT);
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
TileEntity[] adj = OxygenUtil.getAdjacentFluidConnections(pipe);
for (EnumFacing facing : EnumFacing.VALUES) {
TileEntity sideTile = adj[facing.ordinal()];
if (sideTile != null && !(sideTile instanceof IBufferTransmitter)) {
GL11.glPushMatrix();
if (sideTile instanceof TileEntityFluidTank)
switch(facing) {
case SOUTH:
GL11.glTranslatef(0F, 0F, 1 / 16F);
break;
case NORTH:
GL11.glTranslatef(0F, 0F, -1 / 16F);
break;
case EAST:
GL11.glTranslatef(1 / 16F, 0F, 0F);
break;
case WEST:
GL11.glTranslatef(-1 / 16F, 0F, 0F);
break;
}
ClientUtil.drawBakedModel(pullConnectorModel[facing.ordinal()]);
GL11.glPopMatrix();
}
}
GL11.glPopMatrix();
}
float scale;
if (pipe.hasNetwork()) {
FluidNetwork network = (FluidNetwork) pipe.getNetwork();
scale = network.fluidScale;
} else {
scale = pipe.buffer.getFluidAmount() / (float) pipe.buffer.getCapacity();
}
Fluid fluid;
if (pipe.hasNetwork()) {
FluidNetwork network = (FluidNetwork) pipe.getNetwork();
fluid = network.refFluid;
} else {
fluid = pipe.getBuffer() == null ? null : pipe.getBuffer().getFluid();
}
if (fluid == null) {
return;
}
if (scale > 0.01) {
this.bindTexture(TextureMap.locationBlocksTexture);
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
GL11.glScalef(1.0F, -1.0F, -1.0F);
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
float opacity = 1.0F;
boolean gas = fluid.isGaseous();
if (gas) {
opacity = scale;
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, opacity);
TileEntity[] connections = OxygenUtil.getAdjacentFluidConnections(pipe);
for (EnumFacing side : EnumFacing.VALUES) {
TileEntity sideTile = connections[side.ordinal()];
if (sideTile != null) {
Integer[] displayLists = getListAndRender(side, fluid);
if (displayLists != null) {
if (!gas) {
Integer list = displayLists[Math.max(3, (int) (scale * (stages - 1)))];
GL11.glCallList(list);
} else {
Integer list = displayLists[stages - 1];
GL11.glCallList(list);
}
}
}
}
Integer[] displayLists = getListAndRender(null, fluid);
if (displayLists != null) {
if (!gas) {
Integer list = displayLists[Math.max(3, (int) (scale * (stages - 1)))];
GL11.glCallList(list);
} else {
Integer list = displayLists[stages - 1];
GL11.glCallList(list);
}
}
GlStateManager.enableLighting();
GlStateManager.disableBlend();
GL11.glPopMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.
the class PacketFluidNetworkUpdate method encodeInto.
@Override
public void encodeInto(ByteBuf buffer) {
super.encodeInto(buffer);
buffer.writeInt(this.pos.getX());
buffer.writeInt(this.pos.getY());
buffer.writeInt(this.pos.getZ());
buffer.writeInt(this.type.ordinal());
switch(this.type) {
case ADD_TRANSMITTER:
buffer.writeBoolean(this.newNetwork);
buffer.writeInt(this.transmittersAdded.size());
for (IBufferTransmitter transmitter : this.transmittersAdded) {
TileEntity tile = (TileEntity) transmitter;
buffer.writeInt(tile.getPos().getX());
buffer.writeInt(tile.getPos().getY());
buffer.writeInt(tile.getPos().getZ());
}
break;
case FLUID:
if (this.stack != null) {
buffer.writeBoolean(true);
ByteBufUtils.writeUTF8String(buffer, FluidRegistry.getFluidName(this.stack));
buffer.writeInt(this.stack.amount);
} else {
buffer.writeBoolean(false);
}
buffer.writeBoolean(this.didTransfer);
break;
}
}
use of micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter in project Galacticraft by micdoodle8.
the class PacketFluidNetworkUpdate method handleClientSide.
@Override
public void handleClientSide(EntityPlayer player) {
TileEntity tile = player.worldObj.getTileEntity(this.pos);
if (tile instanceof IBufferTransmitter) {
IBufferTransmitter<FluidStack> transmitter = (IBufferTransmitter<FluidStack>) tile;
switch(this.type) {
case ADD_TRANSMITTER:
{
FluidNetwork network = transmitter.hasNetwork() && !this.newNetwork ? (FluidNetwork) transmitter.getNetwork() : new FluidNetwork();
network.register();
transmitter.setNetwork(network);
for (BlockPos pos : this.transmittersCoords) {
TileEntity transmitterTile = player.worldObj.getTileEntity(pos);
if (transmitterTile instanceof IBufferTransmitter) {
((IBufferTransmitter) transmitterTile).setNetwork(network);
}
}
network.updateCapacity();
}
break;
case FLUID:
if (transmitter.getNetwork() != null) {
FluidNetwork network = (FluidNetwork) transmitter.getNetwork();
if (this.fluidType != null) {
network.refFluid = this.fluidType;
}
network.buffer = this.stack;
network.didTransfer = this.didTransfer;
}
break;
}
}
}
Aggregations