Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Description: SlidingDoorBlockEntity.java
Submitted on June 6, 2025 at 06:00 PM
Expires on September 4, 2025 at 06:00 PM (2 months from now)

package net.andrew.scp_mod.block.entity;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.animatable.GeoBlockEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.core.animation.AnimationController;
import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;

public class SlidingDoorBlockEntity extends BlockEntity implements GeoBlockEntity {

    private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

    private boolean isOpen = false;

    private boolean hasInteracted = false;

    private @Nullable RawAnimation getAnimation() {
        if (!hasInteracted) return null;
        return isOpen
                ? RawAnimation.begin().thenPlay("animation.sliding_door.1")
                : RawAnimation.begin().thenPlay("animation.sliding_door.2");
    }

    public SlidingDoorBlockEntity(BlockPos pos, BlockState state) {
        super(ModBlockEntities.SLIDING_DOOR_ENTITY.get(), pos, state);
    }

    public void setOpen(boolean open) {
        if (this.isOpen != open) {
            System.out.println("PORTA: open = " + open);
            this.isOpen = open;
            this.hasInteracted = true;
            level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 3);

        }
    }

    @Override
    public void registerControllers(AnimatableManager.@NotNull ControllerRegistrar controllers) {
        controllers.add(new AnimationController<>(this, "controller", 0, state -> {
            RawAnimation current = getAnimation();
            if (current != null) {
                state.setAnimation(current);
            }

            return PlayState.CONTINUE;
        }));
    }


    @Override
    public AnimatableInstanceCache getAnimatableInstanceCache() {
        return cache;
    }
}