Search in sources :

Example 6 with CoverBehavior

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

the class PipeCoverableImplementation method updateInputRedstoneSignals.

public void updateInputRedstoneSignals() {
    for (EnumFacing side : EnumFacing.VALUES) {
        int redstoneValue = GTUtility.getRedstonePower(getWorld(), getPos(), side);
        int currentValue = sidedRedstoneInput[side.getIndex()];
        if (redstoneValue != currentValue) {
            this.sidedRedstoneInput[side.getIndex()] = redstoneValue;
            CoverBehavior coverBehavior = getCoverAtSide(side);
            if (coverBehavior != null) {
                coverBehavior.onRedstoneInputSignalChange(redstoneValue);
            }
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 7 with CoverBehavior

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

the class PipeCoverableImplementation method writeToNBT.

public void writeToNBT(NBTTagCompound data) {
    NBTTagList coversList = new NBTTagList();
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()];
        if (coverBehavior != null) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            ResourceLocation coverId = coverBehavior.getCoverDefinition().getCoverId();
            tagCompound.setString("CoverId", coverId.toString());
            tagCompound.setByte("Side", (byte) coverSide.getIndex());
            coverBehavior.writeToNBT(tagCompound);
            coversList.appendTag(tagCompound);
        }
    }
    data.setTag("Covers", coversList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EnumFacing(net.minecraft.util.EnumFacing) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 8 with CoverBehavior

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

the class MetaTileEntity method getPickItem.

public ItemStack getPickItem(CuboidRayTraceResult result, EntityPlayer player) {
    IndexedCuboid6 hitCuboid = result.cuboid6;
    if (hitCuboid.data instanceof CoverSideData) {
        CoverSideData coverSideData = (CoverSideData) hitCuboid.data;
        CoverBehavior behavior = getCoverAtSide(coverSideData.side);
        return behavior == null ? ItemStack.EMPTY : behavior.getPickItem();
    } else if (hitCuboid.data == null || hitCuboid.data instanceof PrimaryBoxData) {
        // data is null -> MetaTileEntity hull hit
        CoverBehavior behavior = getCoverAtSide(result.sideHit);
        if (behavior != null) {
            return behavior.getPickItem();
        }
        return getStackForm();
    } else {
        return ItemStack.EMPTY;
    }
}
Also used : IndexedCuboid6(codechicken.lib.raytracer.IndexedCuboid6) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 9 with CoverBehavior

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

the class MetaTileEntity method placeCoverOnSide.

public boolean placeCoverOnSide(EnumFacing side, ItemStack itemStack, CoverDefinition coverDefinition) {
    Preconditions.checkNotNull(side, "side");
    Preconditions.checkNotNull(coverDefinition, "coverDefinition");
    CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, side);
    if (!canPlaceCoverOnSide(side) || !coverBehavior.canAttach()) {
        return false;
    }
    if (coverBehaviors[side.getIndex()] != null) {
        removeCover(side);
    }
    this.coverBehaviors[side.getIndex()] = coverBehavior;
    coverBehavior.onAttached(itemStack);
    writeCustomData(-5, buffer -> {
        buffer.writeByte(side.getIndex());
        buffer.writeVarInt(CoverDefinition.getNetworkIdForCover(coverDefinition));
        coverBehavior.writeInitialSyncData(buffer);
    });
    if (getHolder() != null) {
        getHolder().notifyBlockUpdate();
        getHolder().markDirty();
    }
    onCoverPlacementUpdate();
    return true;
}
Also used : CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 10 with CoverBehavior

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

the class MetaTileEntity method receiveInitialSyncData.

public void receiveInitialSyncData(PacketBuffer buf) {
    this.frontFacing = EnumFacing.VALUES[buf.readByte()];
    this.paintingColor = buf.readInt();
    int amountOfTraits = buf.readShort();
    for (int i = 0; i < amountOfTraits; i++) {
        int traitNetworkId = buf.readVarInt();
        MTETrait trait = mteTraits.stream().filter(otherTrait -> otherTrait.getNetworkID() == traitNetworkId).findAny().get();
        trait.receiveInitialData(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;
        }
    }
    this.isFragile = buf.readBoolean();
}
Also used : 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