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;
}
}
}
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);
}
}
}
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();
}
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);
}
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));
}
Aggregations