Skip to content

Commit

Permalink
uncommited work
Browse files Browse the repository at this point in the history
  • Loading branch information
rotgruengelb committed Jul 31, 2024
1 parent 9038be0 commit 900bad7
Show file tree
Hide file tree
Showing 57 changed files with 1,252 additions and 103 deletions.
10 changes: 8 additions & 2 deletions src/client/java/net/rotgruengelb/forestal/ForestalClient.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.rotgruengelb.forestal;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.minecraft.client.render.RenderLayer;
import net.rotgruengelb.forestal.block.ForestalBlocks;
import net.rotgruengelb.forestal.client.particle.ForestalParticleFactories;
import net.rotgruengelb.forestal.client.render.entity.DeerEntityRenderer;
import net.rotgruengelb.forestal.client.render.entity.BlackBearEntityRenderer;
import net.rotgruengelb.forestal.client.render.entity.GrizzlyBearEntityRenderer;
import net.rotgruengelb.forestal.entity.ForestalEntities;

Expand All @@ -12,8 +15,11 @@ public class ForestalClient implements ClientModInitializer {
public void onInitializeClient() {

EntityRendererRegistry.register(ForestalEntities.GRIZZLY_BEAR, GrizzlyBearEntityRenderer::new);
// EntityRendererRegistry.register(ForestalEntities.DEER, DeerEntityRenderer::new);
EntityRendererRegistry.register(ForestalEntities.BLACK_BEAR, BlackBearEntityRenderer::new);
// EntityRendererRegistry.register(ForestalEntities.DEER, DeerEntityRenderer::new);

ForestalParticleFactories.registerModParticleFactories();

BlockRenderLayerMap.INSTANCE.putBlock(ForestalBlocks.PUFFED_DANDELION, RenderLayer.getCutout());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.rotgruengelb.forestal.client.particle;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;

@Environment(value = EnvType.CLIENT)
public class DandelionPappusParticle extends SpriteBillboardParticle {
private final float j;
private final float k;
private float l;

protected DandelionPappusParticle(ClientWorld world, double x, double y, double z, SpriteProvider spriteProvider) {
super(world, x, y, z);
float f;
this.setSprite(spriteProvider);
this.l = (float) Math.toRadians(this.random.nextBoolean() ? -30.0 : 30.0);
this.j = this.random.nextFloat();
this.k = (float) Math.toRadians(this.random.nextBoolean() ? -5.0 : 5.0);
this.maxAge = 300;
this.gravityStrength = 5E-4f;
this.scale = f = this.random.nextBoolean() ? 0.05f : 0.075f;
this.setBoundingBoxSpacing(f, f);
this.velocityMultiplier = 0.8f;
}

@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
}

@Override
public void tick() {
this.prevPosX = this.x;
this.prevPosY = this.y;
this.prevPosZ = this.z;
if (this.maxAge-- <= 0) {
this.markDead();
}
if (this.dead) {
return;
}
float f = 300 - this.maxAge;
float g = Math.min(f / 300.0f, 1.0f);
double d = Math.cos(Math.toRadians(this.j * 60.0f)) * 2.0 * Math.pow(g, 1.25);
double e = Math.sin(Math.toRadians(this.j * 60.0f)) * 2.0 * Math.pow(g, 1.25);
this.velocityX += d * (double) 0.0025f;
this.velocityZ += e * (double) 0.0025f;
this.velocityY -= this.gravityStrength;
this.l += this.k / 20.0f;
this.prevAngle = this.angle;
this.angle += this.l / 20.0f;
this.move(this.velocityX, this.velocityY, this.velocityZ);
if (this.onGround || this.maxAge < 299 && (this.velocityX == 0.0 || this.velocityZ == 0.0)) {
this.markDead();
}
if (this.dead) {
return;
}
this.velocityX *= this.velocityMultiplier * (this.random.nextBoolean() ? 1.15 : 1.25);
this.velocityY *= this.velocityMultiplier;
this.velocityZ *= this.velocityMultiplier * (this.random.nextBoolean() ? 1.15 : 1.25);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ForestalParticleFactories {

public static void registerModParticleFactories() {
registerSleepingParticle(ForestalParticleTypes.SLEEPING_ZZZ);
registerDandelionPappusParticle(ForestalParticleTypes.DANDELION_PAPPUS);
}

public static void registerSleepingParticle(DefaultParticleType particleType) {
Expand All @@ -17,4 +18,9 @@ public static void registerSleepingParticle(DefaultParticleType particleType) {
return factory.createParticle(particleType, world, x, y, z, velocityX, velocityY, velocityZ);
});
}

public static void registerDandelionPappusParticle(DefaultParticleType particleType) {
ParticleFactoryRegistry.getInstance()
.register(particleType, provider -> (parameters, world, x, y, z, velocityX, velocityY, velocityZ) -> new DandelionPappusParticle(world, x, y, z, provider));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.rotgruengelb.forestal.client.render.entity;

import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.rotgruengelb.forestal.Forestal;
import net.rotgruengelb.forestal.client.render.entity.model.BlackBearEntityModel;
import net.rotgruengelb.forestal.entity.BlackBearEntity;
import software.bernie.geckolib.renderer.GeoEntityRenderer;

public class BlackBearEntityRenderer extends GeoEntityRenderer<BlackBearEntity> {

public BlackBearEntityRenderer(EntityRendererFactory.Context renderManager) {
super(renderManager, new BlackBearEntityModel());
}

@Override
public Identifier getTextureLocation(BlackBearEntity grizzlyBear) {
if (grizzlyBear.isSleeping()) {
return new Identifier(Forestal.MOD_ID, "textures/entity/black_bear/black_bear_sleeping.png");
}
return new Identifier(Forestal.MOD_ID, "textures/entity/black_bear/black_bear_normal.png");
}

@Override
public void render(BlackBearEntity grizzlyBearEntity, float entityYaw, float partialTick, MatrixStack poseStack, VertexConsumerProvider bufferSource, int packedLight) {
poseStack.scale(1.6F, 1.6F, 1.6F);
if (grizzlyBearEntity.isBaby()) {
poseStack.scale(0.6F, 0.6F, 0.6F);
}
if (grizzlyBearEntity.isSleeping()) {
poseStack.translate(0, -0.5, 0);
}
super.render(grizzlyBearEntity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.rotgruengelb.forestal.client.render.entity.model;

import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.rotgruengelb.forestal.Forestal;
import net.rotgruengelb.forestal.entity.BlackBearEntity;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.model.data.EntityModelData;

public class BlackBearEntityModel extends GeoModel<BlackBearEntity> {
@Override
public Identifier getModelResource(BlackBearEntity animatable) {
return new Identifier(Forestal.MOD_ID, "geo/black_bear.geo.json");
}

@Override
public Identifier getTextureResource(BlackBearEntity grizzlyBear) {
if (grizzlyBear.isSleeping()) {
return new Identifier(Forestal.MOD_ID, "textures/entity/black_bear/black_bear_sleeping.png");
}
return new Identifier(Forestal.MOD_ID, "textures/entity/black_bear/black_bear_normal.png");
}

@Override
public Identifier getAnimationResource(BlackBearEntity animatable) {
return new Identifier(Forestal.MOD_ID, "animations/black_bear.animation.json");
}

@Override
public void setCustomAnimations(BlackBearEntity animatable, long instanceId, AnimationState<BlackBearEntity> animationState) {
CoreGeoBone head = getAnimationProcessor().getBone("head");

if (head != null) {
EntityModelData entityData = animationState.getData(DataTickets.ENTITY_MODEL_DATA);
head.setRotX(entityData.headPitch() * MathHelper.RADIANS_PER_DEGREE);
head.setRotY(entityData.netHeadYaw() * MathHelper.RADIANS_PER_DEGREE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.MapColor;
import net.minecraft.item.BlockItem;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
Expand All @@ -13,10 +14,13 @@

public class ForestalBlocks {

public static final Block GRIZZLY_PLUSHIE = registerBlock("grizzly_plushie", new PlushieBlock(FabricBlockSettings.create()
public static final Block GRIZZLY_BEAR_PLUSHIE = registerBlock("grizzly_bear_plushie", new PlushieBlock(FabricBlockSettings.create()
.nonOpaque().breakInstantly().noBlockBreakParticles().sounds(BlockSoundGroup.WOOL)));
public static final Block PUFFED_DANDELION = registerBlock("puffed_dandelion",
new PuffedDandelionBlock(FabricBlockSettings.copyOf(Blocks.DANDELION)));
public static final Block BLACK_BEAR_PLUSHIE = registerBlock("black_bear_plushie",
new PlushieBlock(FabricBlockSettings.create()
.nonOpaque().breakInstantly().noBlockBreakParticles().sounds(BlockSoundGroup.WOOL)));
public static final Block PUFFED_DANDELION = registerBlock("puffed_dandelion", new PuffedDandelionBlock(FabricBlockSettings.copyOf(Blocks.DANDELION)
.mapColor(MapColor.OFF_WHITE)));

private static Block registerBlockNoItem(String name, Block block) {
return Registry.register(Registries.BLOCK, new Identifier(Forestal.MOD_ID, name), block);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
package net.rotgruengelb.forestal.block;

import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBiomeTags;
import net.minecraft.block.BlockState;
import net.minecraft.block.CherryLeavesBlock;
import net.minecraft.block.FlowerBlock;
import net.minecraft.client.util.ParticleUtil;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionType;
import net.rotgruengelb.forestal.particle.ForestalParticleTypes;

import java.awt.*;

public class PuffedDandelionBlock extends FlowerBlock {

public PuffedDandelionBlock(FabricBlockSettings settings) {
super(StatusEffects.SATURATION, 7, settings);
}

public static void spawnParticle(World world, Vec3d pos, Random random, ParticleEffect effect) {
double d = pos.getX() + (random.nextDouble() / 2);
double e = pos.getY() - 0.05;
double f = pos.getZ() + (random.nextDouble() / 2);
world.addParticle(effect, d, e, f, 0.0, 0.0, 0.0);
}

public int particlesFrequency(World world, BlockPos pos) {
if (world.hasRain(pos)) { return 1; }

final RegistryEntry<Biome> biome = world.getBiome(pos);
final DimensionType dim = world.getDimension();

int freq = 19;
if (biome.isIn(ConventionalBiomeTags.IN_NETHER) || dim.ultrawarm()) { freq += 5; }
if (biome.isIn(ConventionalBiomeTags.CLIMATE_DRY)) { freq += 6; }
if (!world.isSkyVisible(pos) || world.isRaining()) { freq += 2; }
if (!biome.isIn(ConventionalBiomeTags.FLORAL)) { freq += 3; }
return freq;
}

@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
super.randomDisplayTick(state, world, pos, random);
if (random.nextInt(10) != 0) {
return;
}
BlockPos blockPos = pos.down();
BlockState blockState = world.getBlockState(blockPos);
if (CherryLeavesBlock.isFaceFullSquare(blockState.getCollisionShape(world, blockPos), Direction.UP)) {
if (random.nextInt(particlesFrequency(world, pos)) != 2) {
return;
}
ParticleUtil.spawnParticle(world, pos, random, ParticleTypes.CHERRY_LEAVES);
double spawnY = (pos.getY() + (random.nextBoolean() ? 0.7 : 0.5));
Vec3d particlePos = new Vec3d(pos.getX(), spawnY, pos.getZ());
spawnParticle(world, particlePos, random, ForestalParticleTypes.DANDELION_PAPPUS);
}
}
Loading

0 comments on commit 900bad7

Please sign in to comment.