Search in sources :

Example 1 with SmartWrenchMode

use of mcjty.lib.api.smartwrench.SmartWrenchMode in project RFTools by McJty.

the class SmartWrenchItem method getCurrentMode.

public static SmartWrenchMode getCurrentMode(ItemStack itemStack) {
    SmartWrenchMode mode = SmartWrenchMode.MODE_WRENCH;
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound != null) {
        String modeString = tagCompound.getString("mode");
        if (modeString != null && !modeString.isEmpty()) {
            mode = SmartWrenchMode.getMode(modeString);
        }
    }
    return mode;
}
Also used : SmartWrenchMode(mcjty.lib.api.smartwrench.SmartWrenchMode) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with SmartWrenchMode

use of mcjty.lib.api.smartwrench.SmartWrenchMode in project RFTools by McJty.

the class SmartWrenchItem method initModel.

@SideOnly(Side.CLIENT)
public void initModel() {
    ModelResourceLocation selectedModel = new ModelResourceLocation(getRegistryName() + "_select", "inventory");
    ModelResourceLocation normalModel = new ModelResourceLocation(getRegistryName(), "inventory");
    ModelBakery.registerItemVariants(this, selectedModel, normalModel);
    ModelLoader.setCustomMeshDefinition(this, stack -> {
        SmartWrenchMode mode = getCurrentMode(stack);
        if (mode == SmartWrenchMode.MODE_SELECT) {
            return selectedModel;
        } else {
            return normalModel;
        }
    });
}
Also used : SmartWrenchMode(mcjty.lib.api.smartwrench.SmartWrenchMode) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with SmartWrenchMode

use of mcjty.lib.api.smartwrench.SmartWrenchMode in project RFTools by McJty.

the class SmartWrenchItem method getMode.

@Override
public SmartWrenchMode getMode(ItemStack itemStack) {
    SmartWrenchMode mode = SmartWrenchMode.MODE_WRENCH;
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    if (tagCompound != null) {
        String modeString = tagCompound.getString("mode");
        if (modeString != null && !modeString.isEmpty()) {
            mode = SmartWrenchMode.getMode(modeString);
        }
    }
    return mode;
}
Also used : SmartWrenchMode(mcjty.lib.api.smartwrench.SmartWrenchMode) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 4 with SmartWrenchMode

use of mcjty.lib.api.smartwrench.SmartWrenchMode in project RFTools by McJty.

the class SmartWrenchItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (player.isSneaking()) {
            // Make sure the block get activated if it is a GenericBlock
            IBlockState state = world.getBlockState(pos);
            Block block = state.getBlock();
            if (block instanceof GenericBlock) {
                if (DimensionalShardBlock.activateBlock(block, world, pos, state, player, hand, facing, hitX, hitY, hitZ)) {
                    return EnumActionResult.SUCCESS;
                }
            }
        }
        SmartWrenchMode mode = getCurrentMode(stack);
        if (mode == SmartWrenchMode.MODE_SELECT) {
            GlobalCoordinate b = getCurrentBlock(stack);
            if (b != null) {
                if (b.getDimension() != world.provider.getDimension()) {
                    Logging.message(player, TextFormatting.RED + "The selected block is in another dimension!");
                    return EnumActionResult.FAIL;
                }
                TileEntity te = world.getTileEntity(b.getCoordinate());
                if (te instanceof SmartWrenchSelector) {
                    SmartWrenchSelector smartWrenchSelector = (SmartWrenchSelector) te;
                    smartWrenchSelector.selectBlock(player, pos);
                }
            }
        }
    }
    return EnumActionResult.SUCCESS;
}
Also used : GenericBlock(mcjty.lib.container.GenericBlock) SmartWrenchMode(mcjty.lib.api.smartwrench.SmartWrenchMode) TileEntity(net.minecraft.tileentity.TileEntity) SmartWrenchSelector(mcjty.lib.api.smartwrench.SmartWrenchSelector) IBlockState(net.minecraft.block.state.IBlockState) DimensionalShardBlock(mcjty.rftools.blocks.ores.DimensionalShardBlock) GenericBlock(mcjty.lib.container.GenericBlock) Block(net.minecraft.block.Block) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) ItemStack(net.minecraft.item.ItemStack)

Example 5 with SmartWrenchMode

use of mcjty.lib.api.smartwrench.SmartWrenchMode in project RFTools by McJty.

the class SmartWrenchItem method addInformation.

// @Override
// public boolean doesSneakBypassUse(ItemStack stack, IBlockAccess world, BlockPos pos, EntityPlayer player) {
// return true;
// }
// 
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemStack, World player, List<String> list, ITooltipFlag whatIsThis) {
    super.addInformation(itemStack, player, list, whatIsThis);
    GlobalCoordinate b = getCurrentBlock(itemStack);
    if (b != null) {
        list.add(TextFormatting.GREEN + "Block: " + BlockPosTools.toString(b.getCoordinate()) + " at dimension " + b.getDimension());
    }
    SmartWrenchMode mode = getCurrentMode(itemStack);
    list.add(TextFormatting.WHITE + "Right-click on air to change mode.");
    list.add(TextFormatting.GREEN + "Mode: " + mode.getName());
    if (mode == SmartWrenchMode.MODE_WRENCH) {
        list.add(TextFormatting.WHITE + "Use as a normal wrench:");
        list.add(TextFormatting.WHITE + "    Sneak-right-click to pick up machines.");
        list.add(TextFormatting.WHITE + "    Right-click to rotate machines.");
    } else if (mode == SmartWrenchMode.MODE_SELECT) {
        list.add(TextFormatting.WHITE + "Use as a block selector:");
        list.add(TextFormatting.WHITE + "    Sneak-right-click select master block.");
        list.add(TextFormatting.WHITE + "    Right-click to associate blocks with master.");
    }
}
Also used : SmartWrenchMode(mcjty.lib.api.smartwrench.SmartWrenchMode) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

SmartWrenchMode (mcjty.lib.api.smartwrench.SmartWrenchMode)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 SmartWrenchSelector (mcjty.lib.api.smartwrench.SmartWrenchSelector)1 GenericBlock (mcjty.lib.container.GenericBlock)1 DimensionalShardBlock (mcjty.rftools.blocks.ores.DimensionalShardBlock)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1