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