Search in sources :

Example 16 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method recolorBlock.

@Override
public boolean recolorBlock(World world, BlockPos pos, EnumFacing side, EnumDyeColor color) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
    if (metaTileEntity == null || metaTileEntity.getPaintingColor() == color.colorValue)
        return false;
    metaTileEntity.setPaintingColor(color.colorValue);
    return true;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 17 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method onBlockClicked.

@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    if (metaTileEntity == null)
        return;
    CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) RayTracer.retraceBlock(worldIn, playerIn, pos);
    if (rayTraceResult != null) {
        metaTileEntity.onCoverLeftClick(playerIn, rayTraceResult);
    }
}
Also used : CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 18 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method neighborChanged.

@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    if (metaTileEntity != null) {
        metaTileEntity.updateInputRedstoneSignals();
        metaTileEntity.onNeighborChanged();
    }
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity)

Example 19 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class BlockMachine method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
    CuboidRayTraceResult rayTraceResult = (CuboidRayTraceResult) RayTracer.retraceBlock(worldIn, playerIn, pos);
    ItemStack itemStack = playerIn.getHeldItem(hand);
    if (metaTileEntity == null || rayTraceResult == null) {
        return false;
    }
    if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null)) {
        IScrewdriverItem screwdriver = itemStack.getCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null);
        if (screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, true) && metaTileEntity.onCoverScrewdriverClick(playerIn, hand, rayTraceResult)) {
            screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, false);
            return true;
        }
        return false;
    }
    if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_WRENCH, null)) {
        IWrenchItem wrenchItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_WRENCH, null);
        EnumFacing wrenchDirection = ICoverable.determineGridSideHit(rayTraceResult);
        if (wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, true) && metaTileEntity.onWrenchClick(playerIn, hand, wrenchDirection, rayTraceResult)) {
            wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, false);
            return true;
        }
        return false;
    }
    return metaTileEntity.onCoverRightClick(playerIn, hand, rayTraceResult);
}
Also used : IScrewdriverItem(gregtech.api.capability.tool.IScrewdriverItem) CuboidRayTraceResult(codechicken.lib.raytracer.CuboidRayTraceResult) IWrenchItem(gregtech.api.capability.tool.IWrenchItem) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 20 with MetaTileEntity

use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.

the class MachineItemBlock method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(stack);
    if (metaTileEntity == null)
        return;
    // item specific tooltip like: gregtech.machine.lathe.lv.tooltip
    String tooltipLocale = metaTileEntity.getMetaName() + ".tooltip";
    if (I18n.hasKey(tooltipLocale)) {
        String[] lines = I18n.format(tooltipLocale).split("/n");
        tooltip.addAll(Arrays.asList(lines));
    }
    // tier less tooltip for a electric machine like: gregtech.machine.lathe.tooltip
    if (metaTileEntity instanceof ITieredMetaTileEntity) {
        String tierlessTooltipLocale = ((ITieredMetaTileEntity) metaTileEntity).getTierlessTooltipKey();
        // case when it's not true would be any machine extending from TieredMetaTileEntity but having only one tier
        if (!tooltipLocale.equals(tierlessTooltipLocale) && I18n.hasKey(tierlessTooltipLocale)) {
            String[] lines = I18n.format(tierlessTooltipLocale).split("/n");
            tooltip.addAll(Arrays.asList(lines));
        }
    }
    metaTileEntity.addInformation(stack, worldIn, tooltip, flagIn.isAdvanced());
    if (flagIn.isAdvanced()) {
        tooltip.add(String.format("MetaTileEntity Id: %s", metaTileEntity.metaTileEntityId.toString()));
    }
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) ITieredMetaTileEntity(gregtech.api.metatileentity.ITieredMetaTileEntity) ITieredMetaTileEntity(gregtech.api.metatileentity.ITieredMetaTileEntity) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)25 IFastRenderMetaTileEntity (gregtech.api.metatileentity.IFastRenderMetaTileEntity)6 CCRenderState (codechicken.lib.render.CCRenderState)5 ItemStack (net.minecraft.item.ItemStack)5 Matrix4 (codechicken.lib.vec.Matrix4)4 IRenderMetaTileEntity (gregtech.api.metatileentity.IRenderMetaTileEntity)4 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ArrayList (java.util.ArrayList)3 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)2 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)2 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)2 ITieredMetaTileEntity (gregtech.api.metatileentity.ITieredMetaTileEntity)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 ColourMultiplier (codechicken.lib.render.pipeline.ColourMultiplier)1 Cuboid6 (codechicken.lib.vec.Cuboid6)1 Vector3 (codechicken.lib.vec.Vector3)1