mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-08 06:26:43 +01:00
Prevent zap leaves from changing state when placed manually
This commit is contained in:
parent
9809f13fd1
commit
2df34bd986
3 changed files with 17 additions and 4 deletions
|
@ -41,6 +41,10 @@ public class BaseZapAppleLeavesBlock extends LeavesBlock implements TintedBlock
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
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) {
|
if (world instanceof ServerWorld sw) {
|
||||||
ZapAppleStageStore store = ZapAppleStageStore.get(sw);
|
ZapAppleStageStore store = ZapAppleStageStore.get(sw);
|
||||||
ZapAppleStageStore.Stage currentStage = store.getStage();
|
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) {
|
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||||
super.scheduledTick(state, world, pos, random);
|
super.scheduledTick(state, world, pos, random);
|
||||||
tryAdvanceStage(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) {
|
private void tryAdvanceStage(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.block;
|
||||||
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
|
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
|
||||||
|
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.*;
|
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);
|
public static final EnumProperty<ZapAppleStageStore.Stage> STAGE = EnumProperty.of("stage", ZapAppleStageStore.Stage.class);
|
||||||
|
|
||||||
ZapAppleLeavesBlock() {
|
ZapAppleLeavesBlock() {
|
||||||
setDefaultState(getDefaultState().with(STAGE, ZapAppleStageStore.Stage.HIBERNATING));
|
setDefaultState(getDefaultState().with(STAGE, ZapAppleStageStore.Stage.GREENING));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
|
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.ZAP_LEAVES)
|
||||||
|| oldState.isOf(UBlocks.FLOWERING_ZAP_LEAVES)
|
|| oldState.isOf(UBlocks.FLOWERING_ZAP_LEAVES)
|
||||||
|| oldState.isOf(UBlocks.ZAP_LEAVES_PLACEHOLDER)
|
|| 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
|
@Override
|
||||||
protected ZapAppleStageStore.Stage getStage(BlockState state) {
|
protected ZapAppleStageStore.Stage getStage(BlockState state) {
|
||||||
return state.get(STAGE);
|
return state.get(STAGE);
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
|
||||||
if (this == ZapAppleStageStore.Stage.FLOWERING) {
|
if (this == ZapAppleStageStore.Stage.FLOWERING) {
|
||||||
return UBlocks.FLOWERING_ZAP_LEAVES.getDefaultState();
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue