diff --git a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java index ed0eec30..0c4cdade 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java @@ -45,6 +45,7 @@ public interface UBlocks { Block STRIPPED_ZAP_WOOD = register("stripped_zap_wood", new ZapAppleLogBlock(Blocks.STRIPPED_OAK_WOOD, MapColor.GRAY, MapColor.GRAY), ItemGroups.BUILDING_BLOCKS); Block ZAP_LEAVES = register("zap_leaves", new ZapAppleLeavesBlock(), ItemGroups.NATURAL); + Block ZAP_LEAVES_PLACEHOLDER = register("zap_leaves_placeholder", new ZapAppleLeavesPlaceholderBlock()); Block ZAP_BULB = register("zap_bulb", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).strength(500, 1200).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE, false)); Block ZAP_APPLE = register("zap_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GRAY).sounds(BlockSoundGroup.AZALEA_LEAVES), Direction.DOWN, ZAP_LEAVES, FruitBlock.DEFAULT_SHAPE, false)); diff --git a/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesBlock.java index fb53b47d..f533fd0e 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesBlock.java @@ -23,6 +23,7 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock { public static final EnumProperty STAGE = EnumProperty.of("stage", ZapAppleStageStore.Stage.class); ZapAppleLeavesBlock() { + super(Settings.of(Material.LEAVES) .strength(500, 1200) .ticksRandomly() @@ -43,17 +44,20 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock { @Override public boolean hasRandomTicks(BlockState state) { - return true; + return !state.get(PERSISTENT); } @Override public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { super.randomTick(state, world, pos, random); + if (state.get(PERSISTENT)) { + return; + } ZapAppleStageStore store = ZapAppleStageStore.get(world); ZapAppleStageStore.Stage newStage = store.getStage(); if (!world.isDay() && state.get(STAGE).mustChangeInto(newStage)) { - world.setBlockState(pos, state.with(STAGE, newStage)); + world.setBlockState(pos, newStage == ZapAppleStageStore.Stage.HIBERNATING ? UBlocks.ZAP_LEAVES_PLACEHOLDER.getDefaultState() : state.with(STAGE, newStage)); onStageChanged(store, newStage, world, state, pos, random); } } @@ -61,11 +65,14 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock { @Override public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { super.scheduledTick(state, world, pos, random); + if (state.get(PERSISTENT)) { + return; + } ZapAppleStageStore store = ZapAppleStageStore.get(world); ZapAppleStageStore.Stage newStage = store.getStage(); if (!world.isDay() && state.get(STAGE).mustChangeIntoInstantly(newStage)) { - world.setBlockState(pos, state.with(STAGE, newStage)); + world.setBlockState(pos, newStage == ZapAppleStageStore.Stage.HIBERNATING ? UBlocks.ZAP_LEAVES_PLACEHOLDER.getDefaultState() : state.with(STAGE, newStage)); onStageChanged(store, newStage, world, state, pos, random); } @@ -79,14 +86,10 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock { @Override public BlockState getPlacementState(ItemPlacementContext ctx) { - if (!ctx.getWorld().isClient) { - ctx.getWorld().scheduleBlockTick(ctx.getBlockPos(), this, 1); - return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.get(ctx.getWorld()).getStage()); - } - return super.getPlacementState(ctx); + return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.Stage.GREENING); } - private void onStageChanged(ZapAppleStageStore store, ZapAppleStageStore.Stage stage, ServerWorld world, BlockState state, BlockPos pos, Random random) { + static void onStageChanged(ZapAppleStageStore store, ZapAppleStageStore.Stage stage, ServerWorld world, BlockState state, BlockPos pos, Random random) { boolean mustFruit = Random.create(state.getRenderingSeed(pos)).nextInt(5) < 2; BlockState below = world.getBlockState(pos.down()); diff --git a/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesPlaceholderBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesPlaceholderBlock.java new file mode 100644 index 00000000..776cd63e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/ZapAppleLeavesPlaceholderBlock.java @@ -0,0 +1,36 @@ +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.util.math.*; +import net.minecraft.util.math.random.Random; + +public class ZapAppleLeavesPlaceholderBlock extends AirBlock { + + ZapAppleLeavesPlaceholderBlock() { + super(AbstractBlock.Settings.of(Material.AIR).noCollision().dropsNothing().air()); + } + + @Override + public boolean hasRandomTicks(BlockState state) { + return true; + } + + @Deprecated + @Override + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + super.scheduledTick(state, world, pos, random); + + ZapAppleStageStore store = ZapAppleStageStore.get(world); + ZapAppleStageStore.Stage newStage = store.getStage(); + if (!world.isDay() && ZapAppleStageStore.Stage.HIBERNATING.mustChangeIntoInstantly(newStage)) { + world.setBlockState(pos, UBlocks.ZAP_LEAVES.getDefaultState().with(ZapAppleLeavesBlock.STAGE, newStage)); + ZapAppleLeavesBlock.onStageChanged(store, newStage, world, state, pos, random); + } + + world.scheduleBlockTick(pos, this, 1); + } + +} diff --git a/src/main/resources/assets/unicopia/blockstates/zap_leaves_placeholder.json b/src/main/resources/assets/unicopia/blockstates/zap_leaves_placeholder.json new file mode 100644 index 00000000..2c8f02f0 --- /dev/null +++ b/src/main/resources/assets/unicopia/blockstates/zap_leaves_placeholder.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "minecraft:block/air" + } + } +} \ No newline at end of file