Unicopia/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesBlock.java

47 lines
1.6 KiB
Java
Raw Normal View History

2022-09-23 23:25:00 +02:00
package com.minelittlepony.unicopia.block;
2023-04-30 11:46:33 +02:00
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
2022-09-23 23:25:00 +02:00
import net.minecraft.block.*;
import net.minecraft.server.world.ServerWorld;
2022-09-23 23:25:00 +02:00
import net.minecraft.state.StateManager;
import net.minecraft.state.property.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2022-09-23 23:25:00 +02:00
public class ZapAppleLeavesBlock extends BaseZapAppleLeavesBlock {
2022-09-23 23:25:00 +02:00
public static final EnumProperty<ZapAppleStageStore.Stage> STAGE = EnumProperty.of("stage", ZapAppleStageStore.Stage.class);
ZapAppleLeavesBlock() {
setDefaultState(getDefaultState().with(STAGE, ZapAppleStageStore.Stage.HIBERNATING));
}
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (oldState.isOf(state.getBlock())
|| oldState.isOf(UBlocks.ZAP_LEAVES)
|| oldState.isOf(UBlocks.FLOWERING_ZAP_LEAVES)
|| oldState.isOf(UBlocks.ZAP_LEAVES_PLACEHOLDER)
|| !(world instanceof ServerWorld sw)) {
return;
}
ZapAppleStageStore store = ZapAppleStageStore.get(sw);
ZapAppleStageStore.Stage currentStage = store.getStage();
if (currentStage != getStage(state)) {
world.setBlockState(pos, currentStage.getNewState(state));
}
}
2022-09-23 23:25:00 +02:00
@Override
protected ZapAppleStageStore.Stage getStage(BlockState state) {
return state.get(STAGE);
2022-09-23 23:25:00 +02:00
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(STAGE);
2022-09-23 23:25:00 +02:00
}
}