mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Ensure zap apple trees have the correct state when generated
This commit is contained in:
parent
d73240c981
commit
94d7ff1419
2 changed files with 35 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue