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.*;
|
2023-09-12 13:27:47 +02:00
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2022-09-23 23:25:00 +02:00
|
|
|
import net.minecraft.state.StateManager;
|
2022-09-25 00:14:29 +02:00
|
|
|
import net.minecraft.state.property.*;
|
2023-09-12 13:27:47 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2022-09-23 23:25:00 +02:00
|
|
|
|
2023-05-25 12:56:18 +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));
|
|
|
|
}
|
|
|
|
|
2023-09-12 13:27:47 +02:00
|
|
|
@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
|
2023-05-25 12:56:18 +02:00
|
|
|
protected ZapAppleStageStore.Stage getStage(BlockState state) {
|
|
|
|
return state.get(STAGE);
|
2022-09-23 23:25:00 +02:00
|
|
|
}
|
|
|
|
|
2022-09-25 00:14:29 +02:00
|
|
|
@Override
|
2023-05-25 12:56:18 +02:00
|
|
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
|
|
|
super.appendProperties(builder);
|
|
|
|
builder.add(STAGE);
|
2022-09-23 23:25:00 +02:00
|
|
|
}
|
|
|
|
}
|