1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
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;
}
}