Prevent zap leaves from changing state when placed manually

This commit is contained in:
Sollace 2023-11-26 18:18:34 +00:00
parent 9809f13fd1
commit 2df34bd986
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 17 additions and 4 deletions

View file

@ -41,6 +41,10 @@ public class BaseZapAppleLeavesBlock extends LeavesBlock implements TintedBlock
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(PERSISTENT)) {
return state;
}
if (world instanceof ServerWorld sw) {
ZapAppleStageStore store = ZapAppleStageStore.get(sw);
ZapAppleStageStore.Stage currentStage = store.getStage();
@ -56,7 +60,9 @@ public class BaseZapAppleLeavesBlock extends LeavesBlock implements TintedBlock
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
super.scheduledTick(state, world, pos, random);
tryAdvanceStage(state, world, pos, random);
world.scheduleBlockTick(pos, this, 1);
if (!state.get(PERSISTENT)) {
world.scheduleBlockTick(pos, this, 1);
}
}
private void tryAdvanceStage(BlockState state, ServerWorld world, BlockPos pos, Random random) {

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
import net.minecraft.block.*;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.*;
@ -13,12 +14,13 @@ public class ZapAppleLeavesBlock extends BaseZapAppleLeavesBlock {
public static final EnumProperty<ZapAppleStageStore.Stage> STAGE = EnumProperty.of("stage", ZapAppleStageStore.Stage.class);
ZapAppleLeavesBlock() {
setDefaultState(getDefaultState().with(STAGE, ZapAppleStageStore.Stage.HIBERNATING));
setDefaultState(getDefaultState().with(STAGE, ZapAppleStageStore.Stage.GREENING));
}
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (oldState.isOf(state.getBlock())
if (state.get(PERSISTENT)
|| oldState.isOf(state.getBlock())
|| oldState.isOf(UBlocks.ZAP_LEAVES)
|| oldState.isOf(UBlocks.FLOWERING_ZAP_LEAVES)
|| oldState.isOf(UBlocks.ZAP_LEAVES_PLACEHOLDER)
@ -33,6 +35,11 @@ public class ZapAppleLeavesBlock extends BaseZapAppleLeavesBlock {
}
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.Stage.GREENING);
}
@Override
protected ZapAppleStageStore.Stage getStage(BlockState state) {
return state.get(STAGE);

View file

@ -171,7 +171,7 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
if (this == ZapAppleStageStore.Stage.FLOWERING) {
return UBlocks.FLOWERING_ZAP_LEAVES.getDefaultState();
}
return UBlocks.FLOWERING_ZAP_LEAVES.getDefaultState().withIfExists(ZapAppleLeavesBlock.STAGE, this);
return UBlocks.ZAP_LEAVES.getDefaultState().with(ZapAppleLeavesBlock.STAGE, this);
}
@Override