Search in sources :

Example 1 with IColorable

use of micdoodle8.mods.galacticraft.api.tile.IColorable in project Galacticraft by micdoodle8.

the class BlockFluidPipe method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
    final TileEntityFluidPipe tileEntity = (TileEntityFluidPipe) worldIn.getTileEntity(pos);
    if (super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ)) {
        return true;
    }
    if (!worldIn.isRemote) {
        final ItemStack stack = playerIn.inventory.getCurrentItem();
        if (stack != null) {
            if (stack.getItem() instanceof ItemDye) {
                final int dyeColor = playerIn.inventory.getCurrentItem().getItemDamage();
                final byte colorBefore = tileEntity.getColor(state);
                tileEntity.onColorUpdate();
                worldIn.setBlockState(pos, state.withProperty(COLOR, EnumDyeColor.byDyeDamage(dyeColor)));
                GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(PacketSimple.EnumSimplePacket.C_RECOLOR_PIPE, GCCoreUtil.getDimensionID(worldIn), new Object[] { pos }), new NetworkRegistry.TargetPoint(GCCoreUtil.getDimensionID(worldIn), pos.getX(), pos.getY(), pos.getZ(), 40.0));
                if (colorBefore != (byte) dyeColor && !playerIn.capabilities.isCreativeMode && --playerIn.inventory.getCurrentItem().stackSize == 0) {
                    playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
                }
                if (colorBefore != (byte) dyeColor && colorBefore != 15) {
                    spawnItem(worldIn, pos, colorBefore);
                }
                // GCCorePacketManager.sendPacketToClients(GCCorePacketManager.getPacket(GalacticraftCore.CHANNELENTITIES, tileEntity, tileEntity.getColor(), (byte) -1)); TODO Fix pipe color
                BlockPos tileVec = tileEntity.getPos();
                for (final EnumFacing dir : EnumFacing.VALUES) {
                    final TileEntity tileAt = worldIn.getTileEntity(tileVec.offset(dir));
                    if (tileAt != null && tileAt instanceof IColorable) {
                        ((IColorable) tileAt).onAdjacentColorChanged(dir);
                    }
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ItemDye(net.minecraft.item.ItemDye) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) IColorable(micdoodle8.mods.galacticraft.api.tile.IColorable) TileEntity(net.minecraft.tileentity.TileEntity) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) ItemStack(net.minecraft.item.ItemStack) TileEntityFluidPipe(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidPipe)

Example 2 with IColorable

use of micdoodle8.mods.galacticraft.api.tile.IColorable in project Galacticraft by micdoodle8.

the class TileEntityFluidPipe method canConnect.

@Override
public boolean canConnect(EnumFacing direction, NetworkType type) {
    TileEntity adjacentTile = new BlockVec3(this).getTileEntityOnSide(this.worldObj, direction);
    if (type == NetworkType.FLUID) {
        if (adjacentTile instanceof IColorable) {
            IBlockState state = this.worldObj.getBlockState(this.getPos());
            IBlockState adjacentTileState = adjacentTile.getWorld().getBlockState(adjacentTile.getPos());
            byte thisCol = this.getColor(state);
            byte otherCol = ((IColorable) adjacentTile).getColor(adjacentTileState);
            return thisCol == otherCol || thisCol == EnumDyeColor.WHITE.getDyeDamage() || otherCol == EnumDyeColor.WHITE.getDyeDamage();
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) IColorable(micdoodle8.mods.galacticraft.api.tile.IColorable)

Aggregations

IColorable (micdoodle8.mods.galacticraft.api.tile.IColorable)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)1 TileEntityFluidPipe (micdoodle8.mods.galacticraft.core.tile.TileEntityFluidPipe)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemDye (net.minecraft.item.ItemDye)1 ItemStack (net.minecraft.item.ItemStack)1 NetworkRegistry (net.minecraftforge.fml.common.network.NetworkRegistry)1