Search in sources :

Example 1 with TileEntityConveyor

use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.

the class MFRUtil method directionsWithoutConveyors.

public static ForgeDirection[] directionsWithoutConveyors(World world, int x, int y, int z) {
    ArrayList<ForgeDirection> nonConveyors = new ArrayList<ForgeDirection>();
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        BlockPosition bp = new BlockPosition(x, y, z);
        bp.orientation = direction;
        bp.moveForwards(1);
        TileEntity te = world.getBlockTileEntity(bp.x, bp.y, bp.z);
        if (te == null || !(te instanceof TileEntityConveyor)) {
            nonConveyors.add(direction);
        }
    }
    return nonConveyors.toArray(new ForgeDirection[nonConveyors.size()]);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) BlockPosition(powercrystals.core.position.BlockPosition) ArrayList(java.util.ArrayList) ForgeDirection(net.minecraftforge.common.ForgeDirection)

Example 2 with TileEntityConveyor

use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.

the class BlockConveyor method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
    if (entity instanceof EntityPlayer && MFRConfig.conveyorNeverCapturesPlayers.getBoolean(false)) {
        return;
    }
    // TODO: add conveyer entity blacklist: these two cases will be covered conditionally elsewhere
    if (entity.getClass().getName().contains("thaumcraft.common.entities.golems") && MFRConfig.conveyorNeverCapturesTCGolems.getBoolean(false)) {
        return;
    }
    if (!(entity instanceof EntityItem || entity instanceof EntityXPOrb || (entity instanceof EntityLiving && MFRConfig.conveyorCaptureNonItems.getBoolean(true)))) {
        return;
    }
    TileEntity conveyor = world.getBlockTileEntity(x, y, z);
    if (!(conveyor instanceof TileEntityConveyor && ((TileEntityConveyor) conveyor).getConveyorActive())) {
        return;
    }
    if (!world.isRemote && entity instanceof EntityItem) {
        specialRoute(world, x, y, z, (EntityItem) entity);
    }
    double xVelocity = 0;
    double yVelocity = 0;
    double zVelocity = 0;
    int md = world.getBlockMetadata(x, y, z);
    int horizDirection = md & 0x03;
    boolean isUphill = (md & 0x04) != 0;
    boolean isDownhill = (md & 0x08) != 0;
    if (isUphill) {
        yVelocity = 0.25D;
    }
    if (isUphill || isDownhill) {
        entity.onGround = false;
    }
    if (horizDirection == 0) {
        xVelocity = 0.1D;
    } else if (horizDirection == 1) {
        zVelocity = 0.1D;
    } else if (horizDirection == 2) {
        xVelocity = -0.1D;
    } else if (horizDirection == 3) {
        zVelocity = -0.1D;
    }
    if (horizDirection == 0 || horizDirection == 2) {
        if (entity.posZ > z + 0.55D) {
            zVelocity = -0.1D;
        } else if (entity.posZ < z + 0.45D) {
            zVelocity = 0.1D;
        }
    } else if (horizDirection == 1 || horizDirection == 3) {
        if (entity.posX > x + 0.55D) {
            xVelocity = -0.1D;
        } else if (entity.posX < x + 0.45D) {
            xVelocity = 0.1D;
        }
    }
    setEntityVelocity(entity, xVelocity, yVelocity, zVelocity);
    if (entity instanceof EntityLiving) {
        ((EntityLiving) entity).fallDistance = 0;
    } else if (entity instanceof EntityItem) {
        ((EntityItem) entity).delayBeforeCanPickup = 40;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityLiving(net.minecraft.entity.EntityLiving) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 3 with TileEntityConveyor

use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.

the class BlockConveyor method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity, ItemStack stack) {
    if (entity == null) {
        return;
    }
    int facing = MathHelper.floor_double((entity.rotationYaw * 4F) / 360F + 0.5D) & 3;
    if (facing == 0) {
        world.setBlockMetadataWithNotify(x, y, z, 1, 2);
    }
    if (facing == 1) {
        world.setBlockMetadataWithNotify(x, y, z, 2, 2);
    }
    if (facing == 2) {
        world.setBlockMetadataWithNotify(x, y, z, 3, 2);
    }
    if (facing == 3) {
        world.setBlockMetadataWithNotify(x, y, z, 0, 2);
    }
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te instanceof TileEntityConveyor) {
        ((TileEntityConveyor) te).setDyeColor(stack.getItemDamage() == 16 ? -1 : stack.getItemDamage());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor)

Example 4 with TileEntityConveyor

use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.

the class ClientPacketHandler method onPacketData.

@SuppressWarnings("rawtypes")
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
    DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
    int packetType = PacketWrapper.readPacketID(data);
    if (// server -> client; server propagating machine rotation; args X Y Z rotation isActive
    packetType == Packets.TileDescription) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
        if (te instanceof TileEntityFactory) {
            TileEntityFactory tef = (TileEntityFactory) te;
            tef.rotateDirectlyTo((Integer) packetReadout[3]);
            tef.setIsActive((Boolean) packetReadout[4]);
        }
    } else if (// server -> client; server propagating conveyor color, activity state
    packetType == Packets.ConveyorDescription) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
        if (te instanceof TileEntityConveyor) {
            TileEntityConveyor tec = (TileEntityConveyor) te;
            tec.setDyeColor((Integer) packetReadout[3]);
            tec.setConveyorActive((Boolean) packetReadout[4]);
        }
    } else if (// server -> client; server playing a record
    packetType == Packets.AutoJukeboxPlay) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
        if (te instanceof TileEntityAutoJukebox) {
            Minecraft.getMinecraft().ingameGUI.setRecordPlayingMessage(((ItemRecord) Item.itemsList[(Integer) packetReadout[3]]).recordName);
        }
    } else if (// server -> client; road block light changed
    packetType == Packets.RoadBlockUpdate) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        ((EntityPlayer) player).worldObj.setBlock((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2], MineFactoryReloadedCore.factoryRoadBlock.blockID, (Integer) packetReadout[3], 6);
        ((EntityPlayer) player).worldObj.markBlockForRenderUpdate((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
    } else if (// server -> client; cable side colors
    packetType == Packets.CableDescription) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Byte.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
        if (te instanceof TileEntityRedNetCable) {
            TileEntityRedNetCable tec = (TileEntityRedNetCable) te;
            tec.setSideColor(ForgeDirection.DOWN, (Integer) packetReadout[3]);
            tec.setSideColor(ForgeDirection.UP, (Integer) packetReadout[4]);
            tec.setSideColor(ForgeDirection.NORTH, (Integer) packetReadout[5]);
            tec.setSideColor(ForgeDirection.SOUTH, (Integer) packetReadout[6]);
            tec.setSideColor(ForgeDirection.WEST, (Integer) packetReadout[7]);
            tec.setSideColor(ForgeDirection.EAST, (Integer) packetReadout[8]);
            tec.setMode((Byte) packetReadout[9]);
        }
    } else if (// server -> client: logic circuit (class and pins)
    packetType == Packets.LogicCircuitDefinition) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
        if (te instanceof TileEntityRedNetLogic) {
            ((TileEntityRedNetLogic) te).setCircuitFromPacket(data);
        }
    } else if (packetType == Packets.HistorianValueChanged) {
        Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
        Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
        TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
        if (te instanceof TileEntityRedNetHistorian) {
            ((TileEntityRedNetHistorian) te).setClientValue((Integer) packetReadout[3]);
        }
    }
}
Also used : TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) TileEntityRedNetCable(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable) DataInputStream(java.io.DataInputStream) TileEntityRedNetLogic(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic) TileEntity(net.minecraft.tileentity.TileEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntityAutoJukebox(powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox) TileEntityRedNetHistorian(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)

Example 5 with TileEntityConveyor

use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.

the class BlockConveyor method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, int blockId, int meta) {
    TileEntity te = world.getBlockTileEntity(x, y, z);
    int dyeColor = 16;
    if (te instanceof TileEntityConveyor) {
        dyeColor = ((TileEntityConveyor) te).getDyeColor();
        if (dyeColor == -1)
            dyeColor = 16;
    }
    dropBlockAsItem_do(world, x, y, z, new ItemStack(blockID, 1, dyeColor));
    super.breakBlock(world, x, y, z, blockId, meta);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityConveyor(powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)5 TileEntityConveyor (powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 EntityLiving (net.minecraft.entity.EntityLiving)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 ItemStack (net.minecraft.item.ItemStack)1 ForgeDirection (net.minecraftforge.common.ForgeDirection)1 BlockPosition (powercrystals.core.position.BlockPosition)1 TileEntityFactory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)1 TileEntityAutoJukebox (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox)1 TileEntityRedNetCable (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)1 TileEntityRedNetHistorian (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)1 TileEntityRedNetLogic (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic)1