Search in sources :

Example 1 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class BlockPipe method onPipeActivated.

public boolean onPipeActivated(EntityPlayer entityPlayer, EnumHand hand, CuboidRayTraceResult hit, IPipeTile<PipeType, NodeDataType> pipeTile) {
    ItemStack itemStack = entityPlayer.getHeldItem(hand);
    EnumFacing coverSide = ICoverable.traceCoverSide(hit);
    if (coverSide == null)
        return false;
    if (!(hit.cuboid6.data instanceof CoverSideData)) {
        IWrenchItem wrenchItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_WRENCH, null);
        if (wrenchItem != null) {
            if (wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, true)) {
                if (!entityPlayer.world.isRemote) {
                    boolean isBlocked = pipeTile.isConnectionBlocked(AttachmentType.PIPE, coverSide);
                    pipeTile.setConnectionBlocked(AttachmentType.PIPE, coverSide, !isBlocked);
                    wrenchItem.damageItem(DamageValues.DAMAGE_FOR_WRENCH, false);
                }
                return true;
            }
            return false;
        }
    }
    CoverBehavior coverBehavior = pipeTile.getCoverableImplementation().getCoverAtSide(coverSide);
    if (coverBehavior == null)
        return false;
    IScrewdriverItem screwdriver = itemStack.getCapability(GregtechCapabilities.CAPABILITY_SCREWDRIVER, null);
    if (screwdriver != null) {
        if (screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, true) && coverBehavior.onScrewdriverClick(entityPlayer, hand, hit) == EnumActionResult.SUCCESS) {
            screwdriver.damageItem(DamageValues.DAMAGE_FOR_SCREWDRIVER, false);
            return true;
        }
        return false;
    }
    return coverBehavior.onRightClick(entityPlayer, hand, hit) == EnumActionResult.SUCCESS;
}
Also used : IScrewdriverItem(gregtech.api.capability.tool.IScrewdriverItem) IWrenchItem(gregtech.api.capability.tool.IWrenchItem) CoverSideData(gregtech.api.cover.ICoverable.CoverSideData) ItemStack(net.minecraft.item.ItemStack) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 2 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class PipeCoverableImplementation method dropAllCovers.

public final void dropAllCovers() {
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()];
        if (coverBehavior == null)
            continue;
        List<ItemStack> drops = coverBehavior.getDrops();
        coverBehavior.onRemoved();
        for (ItemStack dropStack : drops) {
            Block.spawnAsEntity(getWorld(), getPos(), dropStack);
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 3 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class PipeCoverableImplementation method placeCoverOnSide.

public final boolean placeCoverOnSide(EnumFacing side, ItemStack itemStack, CoverDefinition coverDefinition) {
    if (side == null || coverDefinition == null) {
        return false;
    }
    CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, side);
    if (!canPlaceCoverOnSide(side) || !coverBehavior.canAttach()) {
        return false;
    }
    // if cover requires ticking and we're not tickable, update ourselves and redirect call to new tickable tile entity
    boolean requiresTicking = coverBehavior instanceof ITickable;
    if (requiresTicking && !holder.supportsTicking()) {
        IPipeTile<?, ?> newHolderTile = holder.setSupportsTicking();
        return newHolderTile.getCoverableImplementation().placeCoverOnSide(side, itemStack, coverDefinition);
    }
    if (coverBehaviors[side.getIndex()] != null) {
        removeCover(side);
    }
    this.coverBehaviors[side.getIndex()] = coverBehavior;
    coverBehavior.onAttached(itemStack);
    writeCustomData(1, buffer -> {
        buffer.writeByte(side.getIndex());
        buffer.writeVarInt(CoverDefinition.getNetworkIdForCover(coverDefinition));
        coverBehavior.writeInitialSyncData(buffer);
    });
    if (!coverBehavior.canPipePassThrough()) {
        holder.setConnectionBlocked(AttachmentType.COVER, side, true);
    }
    holder.notifyBlockUpdate();
    holder.markAsDirty();
    return true;
}
Also used : ITickable(net.minecraft.util.ITickable) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 4 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class PipeCoverableImplementation method readInitialSyncData.

public void readInitialSyncData(PacketBuffer buf) {
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        int coverId = buf.readVarInt();
        if (coverId != -1) {
            CoverDefinition coverDefinition = CoverDefinition.getCoverByNetworkId(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readInitialSyncData(buf);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) CoverBehavior(gregtech.api.cover.CoverBehavior) CoverDefinition(gregtech.api.cover.CoverDefinition)

Example 5 with CoverBehavior

use of gregtech.api.cover.CoverBehavior in project GregTech by GregTechCE.

the class PipeCoverableImplementation method readCustomData.

public void readCustomData(int dataId, PacketBuffer buf) {
    if (dataId == 1) {
        // cover placement event
        EnumFacing placementSide = EnumFacing.VALUES[buf.readByte()];
        int coverId = buf.readVarInt();
        CoverDefinition coverDefinition = CoverDefinition.getCoverByNetworkId(coverId);
        CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, placementSide);
        this.coverBehaviors[placementSide.getIndex()] = coverBehavior;
        coverBehavior.readInitialSyncData(buf);
        holder.scheduleChunkForRenderUpdate();
    } else if (dataId == 2) {
        // cover removed event
        EnumFacing placementSide = EnumFacing.VALUES[buf.readByte()];
        this.coverBehaviors[placementSide.getIndex()] = null;
        holder.scheduleChunkForRenderUpdate();
    } else if (dataId == 0) {
        // cover custom data received
        EnumFacing coverSide = EnumFacing.VALUES[buf.readByte()];
        CoverBehavior coverBehavior = getCoverAtSide(coverSide);
        int internalId = buf.readVarInt();
        if (coverBehavior != null) {
            coverBehavior.readUpdateData(internalId, buf);
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) CoverBehavior(gregtech.api.cover.CoverBehavior) CoverDefinition(gregtech.api.cover.CoverDefinition)

Aggregations

CoverBehavior (gregtech.api.cover.CoverBehavior)32 EnumFacing (net.minecraft.util.EnumFacing)10 ItemStack (net.minecraft.item.ItemStack)6 CoverDefinition (gregtech.api.cover.CoverDefinition)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 NBTTagList (net.minecraft.nbt.NBTTagList)4 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)2 CoverSideData (gregtech.api.cover.ICoverable.CoverSideData)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 NBT (net.minecraftforge.common.util.Constants.NBT)2 IndexedCuboid6 (codechicken.lib.raytracer.IndexedCuboid6)1 IScrewdriverItem (gregtech.api.capability.tool.IScrewdriverItem)1 IWrenchItem (gregtech.api.capability.tool.IWrenchItem)1 Nullable (javax.annotation.Nullable)1 ITickable (net.minecraft.util.ITickable)1