Vent particles optimization

This commit is contained in:
paulevsGitch 2020-12-04 23:53:49 +03:00
parent 329a59c7be
commit b659424952
6 changed files with 66 additions and 8 deletions

View file

@ -25,6 +25,7 @@ import net.minecraft.world.WorldView;
import ru.betterend.blocks.BlockProperties.HydraluxShape;
import ru.betterend.blocks.basis.BlockUnderwaterPlant;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndItems;
import ru.betterend.util.MHelper;
public class BlockHydralux extends BlockUnderwaterPlant {
@ -78,7 +79,10 @@ public class BlockHydralux extends BlockUnderwaterPlant {
@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
HydraluxShape shape = state.get(SHAPE);
if (shape == HydraluxShape.ROOTS) {
if (shape == HydraluxShape.FLOWER_BIG_BOTTOM || shape == HydraluxShape.FLOWER_SMALL_BOTTOM) {
return Lists.newArrayList(new ItemStack(EndItems.HYDRALUX_PETAL, MHelper.randRange(1, 4, MHelper.RANDOM)));
}
else if (shape == HydraluxShape.ROOTS) {
return Lists.newArrayList(new ItemStack(EndBlocks.HYDRALUX_SAPLING, MHelper.randRange(1, 2, MHelper.RANDOM)));
}
return Collections.emptyList();

View file

@ -4,6 +4,8 @@ import java.util.Random;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
@ -22,6 +24,7 @@ import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
@ -37,9 +40,11 @@ import net.minecraft.world.WorldView;
import ru.betterend.blocks.basis.BlockBaseNotFull;
import ru.betterend.blocks.entities.BlockEntityHydrothermalVent;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndParticles;
public class BlockHydrothermalVent extends BlockBaseNotFull implements BlockEntityProvider, FluidFillable, Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVATED;
private static final VoxelShape SHAPE = Block.createCuboidShape(1, 1, 1, 15, 16, 15);
public BlockHydrothermalVent() {
@ -48,12 +53,12 @@ public class BlockHydrothermalVent extends BlockBaseNotFull implements BlockEnti
.sounds(BlockSoundGroup.STONE)
.noCollision()
.requiresTool());
this.setDefaultState(getDefaultState().with(WATERLOGGED, true));
this.setDefaultState(getDefaultState().with(WATERLOGGED, true).with(ACTIVATED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED);
builder.add(WATERLOGGED, ACTIVATED);
}
@Override
@ -116,4 +121,20 @@ public class BlockHydrothermalVent extends BlockBaseNotFull implements BlockEnti
scheduledTick(state,(ServerWorld) world, pos, world.random);
}
}
@Environment(EnvType.CLIENT)
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (!state.get(ACTIVATED) && random.nextBoolean()) {
super.randomDisplayTick(state, world, pos, random);
double x = pos.getX() + random.nextDouble();
double y = pos.getY() + 0.9 + random.nextDouble() * 0.3;
double z = pos.getZ() + random.nextDouble();
if (state.get(WATERLOGGED)) {
world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0);
}
else {
world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
}
}
}
}

View file

@ -16,13 +16,13 @@ public class BlockEntityHydrothermalVent extends BlockEntity implements Tickable
@Override
public void tick() {
if (world.random.nextInt(32) == 0) {
if (world.random.nextInt(20) == 0) {
double x = pos.getX() + world.random.nextDouble();
double y = pos.getY() + 0.9 + world.random.nextDouble() * 0.3;
double z = pos.getZ() + world.random.nextDouble();
BlockState state = getCachedState();
if (state.isOf(EndBlocks.HYDROTHERMAL_VENT)) {
if (getCachedState().get(BlockHydrothermalVent.WATERLOGGED)) {
if (state.isOf(EndBlocks.HYDROTHERMAL_VENT) && state.get(BlockHydrothermalVent.ACTIVATED)) {
if (state.get(BlockHydrothermalVent.WATERLOGGED)) {
world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0);
}
else {