mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Pick-block on zap leaves now gives you the corresponding state
This commit is contained in:
parent
4713be600f
commit
c25ef42068
3 changed files with 21 additions and 47 deletions
|
@ -7,23 +7,20 @@ import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
|
|||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.*;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.*;
|
||||
|
||||
public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
||||
public static final EnumProperty<ZapAppleStageStore.Stage> STAGE = EnumProperty.of("stage", ZapAppleStageStore.Stage.class);
|
||||
|
||||
ZapAppleLeavesBlock() {
|
||||
|
||||
super(Settings.of(Material.LEAVES)
|
||||
.strength(500, 1200)
|
||||
.ticksRandomly()
|
||||
|
@ -50,21 +47,17 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
|||
@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, newStage == ZapAppleStageStore.Stage.HIBERNATING ? UBlocks.ZAP_LEAVES_PLACEHOLDER.getDefaultState() : state.with(STAGE, newStage));
|
||||
onStageChanged(store, newStage, world, state, pos, random);
|
||||
}
|
||||
tryAdvanceStage(state, world, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
private void tryAdvanceStage(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||
if (state.get(PERSISTENT)) {
|
||||
return;
|
||||
}
|
||||
|
@ -75,8 +68,6 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
|||
world.setBlockState(pos, newStage == ZapAppleStageStore.Stage.HIBERNATING ? UBlocks.ZAP_LEAVES_PLACEHOLDER.getDefaultState() : state.with(STAGE, newStage));
|
||||
onStageChanged(store, newStage, world, state, pos, random);
|
||||
}
|
||||
|
||||
world.scheduleBlockTick(pos, this, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,9 +75,16 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
|
||||
ItemStack stack = super.getPickStack(world, pos, state);
|
||||
stack.setDamage(Math.max(0, state.get(STAGE).ordinal() - 1));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.Stage.GREENING);
|
||||
return super.getPlacementState(ctx).with(STAGE, ZapAppleStageStore.Stage.byId(ctx.getStack().getDamage() + 1));
|
||||
}
|
||||
|
||||
static void onStageChanged(ZapAppleStageStore store, ZapAppleStageStore.Stage stage, ServerWorld world, BlockState state, BlockPos pos, Random random) {
|
||||
|
@ -123,34 +121,6 @@ public class ZapAppleLeavesBlock extends LeavesBlock implements TintedBlock {
|
|||
ZapBlock.triggerLightning(state, world, pos, player);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return isAir(state) ? BlockRenderType.INVISIBLE : super.getRenderType(state);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return isAir(state) ? VoxelShapes.empty() : super.getOutlineShape(state, world, pos, context);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean canReplace(BlockState state, ItemPlacementContext context) {
|
||||
return isAir(state) || super.canReplace(state, context);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean canBucketPlace(BlockState state, Fluid fluid) {
|
||||
return isAir(state) || super.canBucketPlace(state, fluid);
|
||||
}
|
||||
|
||||
protected boolean isAir(BlockState state) {
|
||||
return state.get(STAGE) == ZapAppleStageStore.Stage.HIBERNATING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTint(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int foliageColor) {
|
||||
|
||||
|
|
|
@ -32,5 +32,4 @@ public class ZapAppleLeavesPlaceholderBlock extends AirBlock {
|
|||
|
||||
world.scheduleBlockTick(pos, this, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.minecraft.sound.SoundEvents;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.PersistentState;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -145,7 +146,11 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
|
|||
static final Stage[] VALUES = values();
|
||||
|
||||
public Stage getNext() {
|
||||
return VALUES[(ordinal() + 1) % VALUES.length];
|
||||
return byId((ordinal() + 1) % VALUES.length);
|
||||
}
|
||||
|
||||
public static Stage byId(int id) {
|
||||
return VALUES[MathHelper.clamp(id, 0, VALUES.length)];
|
||||
}
|
||||
|
||||
public boolean mustChangeInto(Stage to) {
|
||||
|
|
Loading…
Reference in a new issue