Search in sources :

Example 1 with IConduitBundle

use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.

the class AbstractConduitNetwork method addConduit.

@Override
public void addConduit(@Nonnull I newConduit) {
    if (conduits.isEmpty()) {
        ServerTickHandler.addListener(this);
    }
    BlockPos newPos = null;
    boolean error = false;
    // Step 1: Is the new conduit attached to a TE that is valid?
    final IConduitBundle newBundle = newConduit.getBundle();
    final TileEntity newte = newBundle.getEntity();
    if (!newte.hasWorld()) {
        Log.info("Tried to add invalid (no world) conduit to network: ", newConduit);
        error = true;
    }
    if (newte.isInvalid()) {
        Log.info("Tried to add invalid (invalidated) conduit to network: ", newConduit);
        error = true;
    }
    newPos = newte.getPos();
    final World newworld = newte.getWorld();
    if (!newworld.isBlockLoaded(newPos)) {
        Log.info("Tried to add invalid (unloaded) conduit to network: ", newConduit);
        error = true;
    }
    if (newworld.getTileEntity(newte.getPos()) != newte) {
        Log.info("Tried to add invalid (world disagrees) conduit to network: ", newConduit);
        error = true;
    }
    if (error) {
        new Exception("trace for message above").printStackTrace();
        return;
    }
    // Step 2: Check for duplicates and other errors
    List<I> old = new ArrayList<I>(conduits);
    conduits.clear();
    boolean newConduitIsBad = false;
    for (I oldConduit : old) {
        // Step 2.1: Fast skip if we have a real dupe
        if (newConduit == oldConduit) {
            continue;
        }
        // Step 2.2: Check if the old conduit's TE is valid
        final IConduitBundle oldBundle = oldConduit.getBundle();
        final TileEntity oldTe = oldBundle.getEntity();
        if (oldTe.isInvalid() || !oldTe.hasWorld()) {
            oldConduit.clearNetwork();
            // bad conduit, skip it
            continue;
        }
        // Step 2.2b: Check if the target position is loaded
        final World oldWorld = oldBundle.getBundleworld();
        final BlockPos oldPos = oldTe.getPos();
        if (!oldWorld.isBlockLoaded(oldPos)) {
            Log.info("Removed unloaded but valid conduit from network: " + oldConduit);
            oldConduit.clearNetwork();
            // bad conduit, skip it
            continue;
        }
        // Step 2.3: Check if the old conduit's TE matches what its world has
        if (oldWorld.getTileEntity(oldPos) != oldTe) {
            oldConduit.clearNetwork();
            // bad conduit, skip it
            continue;
        }
        // world and the old conduit already was checked against the world...
        if (newPos.equals(oldPos)) {
            Log.info("Tried to add invalid conduit to network! Old conduit: ", oldConduit, "/", oldBundle, " New conduit: ", newConduit, "/", oldBundle, " World says: ", oldWorld.getTileEntity(newPos));
            newConduitIsBad = true;
        }
        // Step 2.5: Old conduit is good and can stay
        conduits.add(oldConduit);
    }
    // Step 3: Add the new conduit
    if (!newConduitIsBad) {
        conduits.add(newConduit);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) World(net.minecraft.world.World)

Example 2 with IConduitBundle

use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method getSelectedBoundingBox.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public AxisAlignedBB getSelectedBoundingBox(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos) {
    TileConduitBundle te = getTileEntity(world, pos);
    EntityPlayer player = Minecraft.getMinecraft().player;
    if (te == null) {
        // FIXME is this valid?
        return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
    }
    IConduitBundle con = te;
    BoundingBox minBB = null;
    if (!YetaUtil.isSolidFacadeRendered(con, player)) {
        List<RaytraceResult> results = doRayTraceAll(world, pos, player);
        Iterator<RaytraceResult> iter = results.iterator();
        while (iter.hasNext()) {
            CollidableComponent component = iter.next().component;
            if (component != null && component.conduitType == null && component.data != ConduitConnectorType.EXTERNAL) {
                iter.remove();
            }
        }
        // This is an ugly special case, TODO fix this
        for (RaytraceResult hit : results) {
            IRedstoneConduit cond = con.getConduit(IRedstoneConduit.class);
            CollidableComponent component = hit.component;
            EnumFacing dir = component == null ? null : component.dir;
            if (cond != null && component != null && dir != null && cond.getExternalConnections().contains(dir) && component.data == InsulatedRedstoneConduit.COLOR_CONTROLLER_ID) {
                minBB = component.bound;
            }
        }
        if (minBB == null) {
            RaytraceResult hit = RaytraceResult.getClosestHit(Util.getEyePosition(player), results);
            CollidableComponent component = hit == null ? null : hit.component;
            if (component != null) {
                EnumFacing dir = component.dir;
                minBB = component.bound;
                if (dir != null && component.conduitType == null) {
                    dir = dir.getOpposite();
                    float trans = 0.0125f;
                    minBB = minBB.translate(dir.getFrontOffsetX() * trans, dir.getFrontOffsetY() * trans, dir.getFrontOffsetZ() * trans);
                    float scale = 0.7f;
                    minBB = minBB.scale(1 + Math.abs(dir.getFrontOffsetX()) * scale, 1 + Math.abs(dir.getFrontOffsetY()) * scale, 1 + Math.abs(dir.getFrontOffsetZ()) * scale);
                } else {
                    minBB = minBB.scale(1.09, 1.09, 1.09);
                }
            }
        }
    } else {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    if (minBB == null) {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    return new AxisAlignedBB(pos.getX() + minBB.minX, pos.getY() + minBB.minY, pos.getZ() + minBB.minZ, pos.getX() + minBB.maxX, pos.getY() + minBB.maxY, pos.getZ() + minBB.maxZ);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) BoundingBox(com.enderio.core.client.render.BoundingBox) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IRedstoneConduit(crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IConduitBundle

use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method breakBlock.

@Override
public void breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
    IConduitBundle te = getTileEntity(world, pos);
    if (te == null) {
        return;
    }
    te.onBlockRemoved();
    world.removeTileEntity(pos);
}
Also used : IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle)

Example 4 with IConduitBundle

use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method addCollisionBoxToList.

@Deprecated
@Override
public void addCollisionBoxToList(@Nonnull IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB axisalignedbb, @Nonnull List<AxisAlignedBB> arraylist, @Nullable Entity par7Entity, boolean b) {
    IConduitBundle con = getTileEntity(world, pos);
    if (con == null) {
        return;
    }
    if (con.hasFacade()) {
        setBlockBounds(0, 0, 0, 1, 1, 1);
        super.addCollisionBoxToList(state, world, pos, axisalignedbb, arraylist, par7Entity, b);
    } else {
        Collection<CollidableComponent> collidableComponents = con.getCollidableComponents();
        for (CollidableComponent bnd : collidableComponents) {
            setBlockBounds(bnd.bound.minX, bnd.bound.minY, bnd.bound.minZ, bnd.bound.maxX, bnd.bound.maxY, bnd.bound.maxZ);
            super.addCollisionBoxToList(state, world, pos, axisalignedbb, arraylist, par7Entity, b);
        }
        if (con.getConduits().isEmpty()) {
            // just in case
            setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
            super.addCollisionBoxToList(state, world, pos, axisalignedbb, arraylist, par7Entity, b);
        }
    }
    setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
Also used : CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle)

Example 5 with IConduitBundle

use of crazypants.enderio.base.conduit.IConduitBundle in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method getExplosionResistance.

@Override
public float getExplosionResistance(@Nonnull World world, @Nonnull BlockPos pos, @Nullable Entity par1Entity, @Nonnull Explosion explosion) {
    float resist = super.getExplosionResistance(world, pos, par1Entity, explosion);
    IConduitBundle te = (IConduitBundle) world.getTileEntity(pos);
    return te != null && te.getFacadeType().isHardened() ? resist * 10 : resist;
}
Also used : IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle)

Aggregations

IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)17 Nonnull (javax.annotation.Nonnull)8 TileEntity (net.minecraft.tileentity.TileEntity)7 ItemStack (net.minecraft.item.ItemStack)6 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)4 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)4 BlockPos (net.minecraft.util.math.BlockPos)4 ArrayList (java.util.ArrayList)3 World (net.minecraft.world.World)3 NNList (com.enderio.core.common.util.NNList)2 IConduit (crazypants.enderio.base.conduit.IConduit)2 IServerConduit (crazypants.enderio.base.conduit.IServerConduit)2 BoundingBox (com.enderio.core.client.render.BoundingBox)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 IClientConduit (crazypants.enderio.base.conduit.IClientConduit)1 IConduitRenderer (crazypants.enderio.base.conduit.IConduitRenderer)1 ConduitConnectorType (crazypants.enderio.base.conduit.geom.ConduitConnectorType)1 IoMode (crazypants.enderio.base.machine.modes.IoMode)1 IPowerInterface (crazypants.enderio.base.power.IPowerInterface)1 TileConduitBundle (crazypants.enderio.conduits.conduit.TileConduitBundle)1