mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed hybernating zap leaves not properly treated as air
This commit is contained in:
parent
5698264da7
commit
4713be600f
4 changed files with 56 additions and 9 deletions
|
@ -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 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 = 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_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));
|
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));
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
||||||
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() {
|
||||||
|
|
||||||
super(Settings.of(Material.LEAVES)
|
super(Settings.of(Material.LEAVES)
|
||||||
.strength(500, 1200)
|
.strength(500, 1200)
|
||||||
.ticksRandomly()
|
.ticksRandomly()
|
||||||
|
@ -43,17 +44,20 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasRandomTicks(BlockState state) {
|
public boolean hasRandomTicks(BlockState state) {
|
||||||
return true;
|
return !state.get(PERSISTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||||
super.randomTick(state, world, pos, random);
|
super.randomTick(state, world, pos, random);
|
||||||
|
if (state.get(PERSISTENT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ZapAppleStageStore store = ZapAppleStageStore.get(world);
|
ZapAppleStageStore store = ZapAppleStageStore.get(world);
|
||||||
ZapAppleStageStore.Stage newStage = store.getStage();
|
ZapAppleStageStore.Stage newStage = store.getStage();
|
||||||
if (!world.isDay() && state.get(STAGE).mustChangeInto(newStage)) {
|
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);
|
onStageChanged(store, newStage, world, state, pos, random);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,11 +65,14 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
||||||
@Override
|
@Override
|
||||||
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);
|
||||||
|
if (state.get(PERSISTENT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ZapAppleStageStore store = ZapAppleStageStore.get(world);
|
ZapAppleStageStore store = ZapAppleStageStore.get(world);
|
||||||
ZapAppleStageStore.Stage newStage = store.getStage();
|
ZapAppleStageStore.Stage newStage = store.getStage();
|
||||||
if (!world.isDay() && state.get(STAGE).mustChangeIntoInstantly(newStage)) {
|
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);
|
onStageChanged(store, newStage, world, state, pos, random);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +86,10 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
if (!ctx.getWorld().isClient) {
|
return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.Stage.GREENING);
|
||||||
ctx.getWorld().scheduleBlockTick(ctx.getBlockPos(), this, 1);
|
|
||||||
return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.get(ctx.getWorld()).getStage());
|
|
||||||
}
|
|
||||||
return super.getPlacementState(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
boolean mustFruit = Random.create(state.getRenderingSeed(pos)).nextInt(5) < 2;
|
||||||
BlockState below = world.getBlockState(pos.down());
|
BlockState below = world.getBlockState(pos.down());
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "minecraft:block/air"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue