net.minecraft.util.ITickable Java Examples

The following examples show how to use net.minecraft.util.ITickable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public final 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 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;
}
 
Example #2
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void update() {
    if (!getWorld().isRemote) {
        for (CoverBehavior coverBehavior : coverBehaviors) {
            if (coverBehavior instanceof ITickable) {
                ((ITickable) coverBehavior).update();
            }
        }
    }
}
 
Example #3
Source File: MixinWorld.java    From VanillaFix with MIT License 5 votes vote down vote up
/**
 * @reason Adds subsections to the "root.tick.level.entities.blockEntities"
 * profiler, using the entity ID, or the class name if the ID is null.
 */
@Redirect(method = "updateEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ITickable;update()V"))
private void tileEntityUpdate(ITickable tileEntity) {
    profiler.func_194340_a(() -> { // func_194340_a = startSection(Supplier<String>)
        final ResourceLocation tileEntityID = TileEntity.getKey(((TileEntity) tileEntity).getClass());
        return tileEntityID == null ? tileEntity.getClass().getSimpleName() : tileEntityID.toString();
    });
    tileEntity.update();
    profiler.endSection();
}
 
Example #4
Source File: TickableWorldPipeNet.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void update() {
    if (getWorld().getTotalWorldTime() % getUpdateRate() == 0L) {
        tickingPipeNets.forEach(ITickable::update);
    }
}