Skip to content

Commit

Permalink
Added Null particles, more improvements to Anomaly blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Forstride committed Jan 14, 2024
1 parent be80ee8 commit 13d4393
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 21 deletions.
50 changes: 42 additions & 8 deletions common/src/main/java/biomesoplenty/block/AnomalyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
Expand All @@ -18,7 +19,8 @@
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;

public class AnomalyBlock extends BaseEntityBlock
{
Expand All @@ -37,6 +39,45 @@ protected MapCodec<? extends BaseEntityBlock> codec()
return CODEC;
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext p_49479_)
{
AnomalyType type;
switch (p_49479_.getLevel().random.nextInt(4))
{
default:
case 0:
type = AnomalyBlock.AnomalyType.VOLATILE;
break;

case 1:
type = AnomalyBlock.AnomalyType.QUIRKY;
break;

case 2:
type = AnomalyBlock.AnomalyType.UNSTABLE;
break;

case 3:
type = AnomalyBlock.AnomalyType.STABLE;
break;
}
return this.defaultBlockState().setValue(ANOMALY_TYPE, type);
}

@Override
public boolean propagatesSkylightDown(BlockState state, BlockGetter getter, BlockPos pos)
{
return state.getValue(ANOMALY_TYPE) != AnomalyType.STABLE;
}

@Override
public float getShadeBrightness(BlockState state, BlockGetter getter, BlockPos pos)
{
return 1.0F;
}

@Override
public RenderShape getRenderShape(BlockState state)
{
Expand All @@ -47,13 +88,6 @@ public RenderShape getRenderShape(BlockState state)
public VoxelShape getOcclusionShape(BlockState state, BlockGetter getter, BlockPos pos)
{
if (state.getValue(ANOMALY_TYPE) == AnomalyType.STABLE) return Shapes.block();

AnomalyBlockEntity blockEntity = (AnomalyBlockEntity)getter.getBlockEntity(pos);

if (blockEntity != null)
{
return blockEntity.getRenderState().getOcclusionShape(getter, pos);
}
else return Shapes.empty();
}

Expand Down
53 changes: 53 additions & 0 deletions common/src/main/java/biomesoplenty/block/NullBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright 2022, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package biomesoplenty.block;

import biomesoplenty.init.ModParticles;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

public class NullBlock extends Block
{
public NullBlock(Properties properties)
{
super(properties);
}

@Override
public void animateTick(BlockState p_221253_, Level p_221254_, BlockPos p_221255_, RandomSource p_221256_)
{
if (p_221256_.nextInt(5) == 0)
{
Direction direction = Direction.getRandom(p_221256_);
Direction.Axis direction$axis = direction.getAxis();
BlockPos blockpos = p_221255_.relative(direction);
BlockState blockstate = p_221254_.getBlockState(blockpos);

if (!isFaceFull(blockstate.getCollisionShape(p_221254_, blockpos), direction))
{
double d0 = (double)p_221255_.getX() + 0.5D;
double d1 = (double)p_221255_.getY() + 0.5D;
double d2 = (double)p_221255_.getZ() + 0.5D;

double d3 = (p_221256_.nextDouble() * 0.5D) - (p_221256_.nextDouble() * 0.5D);
double d4 = direction$axis == Direction.Axis.X ? (double)direction.getStepX() * 0.55D : d3;
double d5 = direction$axis == Direction.Axis.Y ? (double)direction.getStepY() * 0.55D : d3;
double d6 = direction$axis == Direction.Axis.Z ? (double)direction.getStepZ() * 0.55D : d3;

double ymove = 0.1D;
if (direction == Direction.DOWN)
{
ymove = -0.1D;
}

p_221254_.addParticle(ModParticles.NULL, d0 + d4, d1 + d5, d2 + d6, 0.0D, ymove, 0.0D);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import biomesoplenty.block.AnomalyBlock;
import biomesoplenty.block.entity.AnomalyBlockEntity;
import biomesoplenty.core.BiomesOPlenty;
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.MultiBufferSource;
Expand All @@ -16,25 +14,22 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;

import java.util.Map;

public class AnomalyRenderer implements BlockEntityRenderer<AnomalyBlockEntity> {
private final BlockRenderDispatcher dispatcher;

public AnomalyRenderer(BlockEntityRendererProvider.Context context) {
this.dispatcher = context.getBlockRenderDispatcher();
}

@Override
public int getViewDistance() {
return 32;
}

@Override
public void render(AnomalyBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource buffer, int packedLight, int packedOverlay) {
// Do regular model rendering for stable anomalies
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/biomesoplenty/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static void registerBlocks(BiConsumer<ResourceLocation, Block> func)
ALGAL_END_STONE = register(func, new AlgalEndStoneBlock(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).mapColor(MapColor.TERRACOTTA_YELLOW).randomTicks().requiresCorrectToolForDrops().strength(3.0F, 9.0F)), "algal_end_stone");
BARNACLES = register(func, new BarnaclesBlock(BlockBehaviour.Properties.of().mapColor(MapColor.CLAY).pushReaction(PushReaction.DESTROY).replaceable().noCollission().sound(SoundType.CORAL_BLOCK)), "barnacles");
NULL_END_STONE = register(func, new Block(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).requiresCorrectToolForDrops().strength(1.5F, 4.5F)), "null_end_stone");
NULL_BLOCK = register(func, new Block(BlockBehaviour.Properties.of()), "null_block");
NULL_BLOCK = register(func, new NullBlock(BlockBehaviour.Properties.of()), "null_block");
ANOMALY = register(func, new AnomalyBlock(BlockBehaviour.Properties.of()), "anomaly");

TOADSTOOL = register(func, new MushroomBlockBOP(BlockBehaviour.Properties.of().pushReaction(PushReaction.DESTROY).mapColor(MapColor.COLOR_ORANGE).noCollission().instabreak().sound(SoundType.GRASS)), "toadstool");
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/biomesoplenty/init/ModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public static void registerParticleSprites(RegisterParticleSpritesEvent event)
event.registerSpriteSet(ModParticles.PUS, PusParticle.Provider::new);
event.registerSpriteSet(ModParticles.GLOWWORM, GlowwormParticle.Provider::new);
event.registerSpriteSet(ModParticles.STEAM, SteamParticle.Provider::new);
event.registerSpriteSet(ModParticles.NULL, NullParticle.Provider::new);
event.registerSpriteSet(ModParticles.JACARANDA_LEAVES, (p_277215_) -> {
return (p_277217_, p_277218_, p_277219_, p_277220_, p_277221_, p_277222_, p_277223_, p_277224_) -> {
return new LeafParticle(p_277218_, p_277219_, p_277220_, p_277221_, p_277215_);
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/biomesoplenty/init/ModParticles.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ModParticles
public static SimpleParticleType RED_MAPLE_LEAVES;
public static SimpleParticleType ORANGE_MAPLE_LEAVES;
public static SimpleParticleType YELLOW_MAPLE_LEAVES;
public static SimpleParticleType NULL;

public static void registerParticles(BiConsumer<ResourceLocation, ParticleType<?>> func)
{
Expand All @@ -40,6 +41,7 @@ public static void registerParticles(BiConsumer<ResourceLocation, ParticleType<?
RED_MAPLE_LEAVES = register(func, "red_maple_leaves", new SimpleParticleType(false));
ORANGE_MAPLE_LEAVES = register(func, "orange_maple_leaves", new SimpleParticleType(false));
YELLOW_MAPLE_LEAVES = register(func, "yellow_maple_leaves", new SimpleParticleType(false));
NULL = register(func, "null", new SimpleParticleType(false));
}

private static <T extends ParticleType<? extends ParticleOptions>> T register(BiConsumer<ResourceLocation, ParticleType<?>> func, String name, T particle)
Expand Down
59 changes: 59 additions & 0 deletions common/src/main/java/biomesoplenty/particle/NullParticle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright 2022, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package biomesoplenty.particle;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;

public class NullParticle extends TextureSheetParticle
{
NullParticle(ClientLevel p_105856_, double p_105857_, double p_105858_, double p_105859_, double p_105860_, double p_105861_, double p_105862_)
{
super(p_105856_, p_105857_, p_105858_, p_105859_);
this.setSize(0.02F, 0.02F);
this.lifetime = this.random.nextInt(24) + 8;
this.xd = p_105860_;
this.yd = p_105861_;
this.zd = p_105862_;
}

@Override
public void tick()
{
this.xo = this.x;
this.yo = this.y;
this.zo = this.z;
if (this.age++ < this.lifetime)
{
this.move(this.xd, this.yd, this.zd);
}
else
{
this.remove();
}
}

@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
}

public static class Provider implements ParticleProvider<SimpleParticleType>
{
private final SpriteSet sprites;

public Provider(SpriteSet p_105899_) {
this.sprites = p_105899_;
}

public Particle createParticle(SimpleParticleType p_105910_, ClientLevel p_105911_, double p_105912_, double p_105913_, double p_105914_, double p_105915_, double p_105916_, double p_105917_)
{
NullParticle particle = new NullParticle(p_105911_, p_105912_, p_105913_, p_105914_, p_105915_, p_105916_, p_105917_);
particle.pickSprite(this.sprites);
return particle;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceC
return false;
}

int radius = rand.nextInt(3);
int anomalyHeight = (radius*2)+4;
int radius = rand.nextInt(4);
int anomalyHeight = radius+4;

if (!this.checkSpace(world, startPos, radius, anomalyHeight))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"textures": [
"biomesoplenty:null_0",
"biomesoplenty:null_1",
"biomesoplenty:null_2"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 13d4393

Please sign in to comment.