Ensure zap apple trees have the correct state when generated

This commit is contained in:
Sollace 2023-09-12 12:27:47 +01:00
parent d73240c981
commit 94d7ff1419
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 35 additions and 0 deletions

View file

@ -3,8 +3,11 @@ package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
import net.minecraft.block.*;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ZapAppleLeavesBlock extends BaseZapAppleLeavesBlock {
public static final EnumProperty<ZapAppleStageStore.Stage> STAGE = EnumProperty.of("stage", ZapAppleStageStore.Stage.class);
@ -13,6 +16,23 @@ public class ZapAppleLeavesBlock extends BaseZapAppleLeavesBlock {
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));
}
}
@Override
protected ZapAppleStageStore.Stage getStage(BlockState state) {
return state.get(STAGE);

View file

@ -6,6 +6,7 @@ import net.minecraft.block.*;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.WorldAccess;
public class ZapAppleLeavesPlaceholderBlock extends AirBlock {
@ -18,6 +19,20 @@ public class ZapAppleLeavesPlaceholderBlock extends AirBlock {
return true;
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (world instanceof ServerWorld sw) {
ZapAppleStageStore store = ZapAppleStageStore.get(sw);
ZapAppleStageStore.Stage currentStage = store.getStage();
if (currentStage != ZapAppleStageStore.Stage.HIBERNATING) {
return currentStage.getNewState(state);
}
}
return state;
}
@Deprecated
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {