Search in sources :

Example 1 with TileEntityFactory

use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactory in project MineFactoryReloaded by powercrystals.

the class BlockRedNetPanel method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
    PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
        return false;
    }
    ItemStack s = player.inventory.getCurrentItem();
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (MFRUtil.isHoldingHammer(player) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
        ((TileEntityFactory) te).rotate();
        world.markBlockForUpdate(x, y, z);
        return true;
    } else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(player.inventory) != null) {
        player.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
        return true;
    } else if (te instanceof TileEntityRedNetHistorian && s != null && s.itemID == Item.dyePowder.itemID) {
        ((TileEntityRedNetHistorian) te).setSelectedSubnet(15 - s.getItemDamage());
        world.markBlockForUpdate(x, y, z);
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) ItemStack(net.minecraft.item.ItemStack) TileEntityRedNetHistorian(powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)

Example 2 with TileEntityFactory

use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactory in project MineFactoryReloaded by powercrystals.

the class BlockFactoryMachine method onInputChanged.

@Override
public void onInputChanged(World world, int x, int y, int z, ForgeDirection side, int inputValue) {
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te instanceof TileEntityFactory) {
        ((TileEntityFactory) te).onRedNetChanged(side, inputValue);
        onNeighborBlockChange(world, x, y, z, MineFactoryReloadedCore.rednetCableBlock.blockID);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)

Example 3 with TileEntityFactory

use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactory in project MineFactoryReloaded by powercrystals.

the class BlockFactoryMachine method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float xOffset, float yOffset, float zOffset) {
    PlayerInteractEvent e = new PlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, x, y, z, side);
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.useBlock == Result.DENY) {
        return false;
    }
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te == null) {
        return false;
    }
    if (te instanceof ITankContainerBucketable && LiquidContainerRegistry.isEmptyContainer(entityplayer.inventory.getCurrentItem()) && ((ITankContainerBucketable) te).allowBucketDrain()) {
        if (MFRLiquidMover.manuallyDrainTank((ITankContainerBucketable) te, entityplayer)) {
            return true;
        }
    } else if (te instanceof ITankContainerBucketable && LiquidContainerRegistry.isFilledContainer(entityplayer.inventory.getCurrentItem()) && ((ITankContainerBucketable) te).allowBucketFill()) {
        if (MFRLiquidMover.manuallyFillTank((ITankContainerBucketable) te, entityplayer)) {
            return true;
        }
    }
    if (MFRUtil.isHoldingHammer(entityplayer) && te instanceof TileEntityFactory && ((TileEntityFactory) te).canRotate()) {
        ((TileEntityFactory) te).rotate();
        world.markBlockForUpdate(x, y, z);
        return true;
    } else if (te instanceof TileEntityFactory && ((TileEntityFactory) te).getContainer(entityplayer.inventory) != null) {
        if (!world.isRemote) {
            entityplayer.openGui(MineFactoryReloadedCore.instance(), 0, world, x, y, z);
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory) ITankContainerBucketable(powercrystals.minefactoryreloaded.core.ITankContainerBucketable) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent)

Example 4 with TileEntityFactory

use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactory 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 TileEntityFactory

use of powercrystals.minefactoryreloaded.tile.base.TileEntityFactory in project MineFactoryReloaded by powercrystals.

the class BlockFactoryMachine method getBlockTexture.

@Override
public Icon getBlockTexture(IBlockAccess iblockaccess, int x, int y, int z, int side) {
    int md = iblockaccess.getBlockMetadata(x, y, z);
    boolean isActive = false;
    TileEntity te = iblockaccess.getBlockTileEntity(x, y, z);
    if (te instanceof TileEntityFactory) {
        side = ((TileEntityFactory) te).getRotatedSide(side);
        isActive = ((TileEntityFactory) te).getIsActive();
    }
    return Machine.getMachineFromIndex(_mfrMachineBlockIndex, md).getIcon(side, isActive);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFactory(powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)7 TileEntityFactory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactory)7 PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)2 TileEntityRedNetHistorian (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetHistorian)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 ITankContainerBucketable (powercrystals.minefactoryreloaded.core.ITankContainerBucketable)1 TileEntityFactoryInventory (powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryInventory)1 TileEntityConveyor (powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor)1 TileEntityAutoJukebox (powercrystals.minefactoryreloaded.tile.machine.TileEntityAutoJukebox)1 TileEntityRedNetCable (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetCable)1 TileEntityRedNetLogic (powercrystals.minefactoryreloaded.tile.rednet.TileEntityRedNetLogic)1