Search in sources :

Example 1 with CoverDefinition

use of gregtech.api.cover.CoverDefinition 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 2 with CoverDefinition

use of gregtech.api.cover.CoverDefinition 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)

Example 3 with CoverDefinition

use of gregtech.api.cover.CoverDefinition 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)

Example 4 with CoverDefinition

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

the class MetaTileEntity method readFromNBT.

public void readFromNBT(NBTTagCompound data) {
    this.frontFacing = EnumFacing.VALUES[data.getInteger("FrontFacing")];
    this.paintingColor = data.getInteger(TAG_KEY_PAINTING_COLOR);
    this.cachedLightValue = data.getInteger("CachedLightValue");
    if (shouldSerializeInventories()) {
        GTUtility.readItems(importItems, "ImportInventory", data);
        GTUtility.readItems(exportItems, "ExportInventory", data);
        importFluids.deserializeNBT(data.getCompoundTag("ImportFluidInventory"));
        exportFluids.deserializeNBT(data.getCompoundTag("ExportFluidInventory"));
    }
    for (MTETrait mteTrait : this.mteTraits) {
        NBTTagCompound traitCompound = data.getCompoundTag(mteTrait.getName());
        mteTrait.deserializeNBT(traitCompound);
    }
    NBTTagList coversList = data.getTagList("Covers", NBT.TAG_COMPOUND);
    for (int index = 0; index < coversList.tagCount(); index++) {
        NBTTagCompound tagCompound = coversList.getCompoundTagAt(index);
        if (tagCompound.hasKey("CoverId", NBT.TAG_STRING)) {
            EnumFacing coverSide = EnumFacing.VALUES[tagCompound.getByte("Side")];
            ResourceLocation coverId = new ResourceLocation(tagCompound.getString("CoverId"));
            CoverDefinition coverDefinition = CoverDefinition.getCoverById(coverId);
            CoverBehavior coverBehavior = coverDefinition.createCoverBehavior(this, coverSide);
            coverBehavior.readFromNBT(tagCompound);
            this.coverBehaviors[coverSide.getIndex()] = coverBehavior;
        }
    }
    this.isFragile = data.getBoolean(TAG_KEY_FRAGILE);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CoverBehavior(gregtech.api.cover.CoverBehavior) CoverDefinition(gregtech.api.cover.CoverDefinition)

Example 5 with CoverDefinition

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

the class CoverBehaviors method registerBehavior.

public static void registerBehavior(int coverNetworkId, ResourceLocation coverId, MetaValueItem placerItem, BiFunction<ICoverable, EnumFacing, CoverBehavior> behaviorCreator) {
    CoverDefinition coverDefinition = new CoverDefinition(coverId, behaviorCreator, placerItem.getStackForm());
    CoverDefinition.registerCover(coverNetworkId, coverDefinition);
    placerItem.addComponents(new CoverPlaceBehavior(coverDefinition));
}
Also used : CoverPlaceBehavior(gregtech.common.items.behaviors.CoverPlaceBehavior) CoverDefinition(gregtech.api.cover.CoverDefinition)

Aggregations

CoverDefinition (gregtech.api.cover.CoverDefinition)6 CoverBehavior (gregtech.api.cover.CoverBehavior)5 EnumFacing (net.minecraft.util.EnumFacing)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 CoverPlaceBehavior (gregtech.common.items.behaviors.CoverPlaceBehavior)1 ResourceLocation (net.minecraft.util.ResourceLocation)1