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