Skip to content

Commit

Permalink
Initial support for PlantBlock, only short_grass block added
Browse files Browse the repository at this point in the history
  • Loading branch information
ishikyoo committed Sep 27, 2024
1 parent c2b6548 commit e52b19c
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/main/java/com/ishikyoo/leavesly/Leavesly.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ else if (block == Blocks.SPRUCE_LEAVES)
boolean isVineBlock(Block block) {
return block == Blocks.VINE;
}
boolean isPlantBlock(Block block) {
if (block == Blocks.SHORT_GRASS)
return true;
return false;
}
boolean isValidBlock(Block block) {
return isLeavesBlock(block) | isVineBlock(block);
return isLeavesBlock(block) | isVineBlock(block) | isPlantBlock(block);
}

double getNeighboursInfluence(ServerWorld world, BlockPos pos, int range) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/ishikyoo/leavesly/LeaveslyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class LeaveslyClient implements ClientModInitializer {
static final double FLOWERING_AZALEA_LEAVES_MASK = 0.5725490196;
static final double CHERRY_LEAVES_MASK = 0.6;
static final double VINE_MASK = 0.66666666666;
static final double SHORT_GRASS_MASK = 0.72156862745;

static final int SPRUCE_LEAVES_COLOR = FoliageColors.getSpruceColor();
static final int BIRTH_LEAVES_COLOR = FoliageColors.getBirchColor();
Expand Down Expand Up @@ -74,6 +75,8 @@ private int getFoliageColor(Block block, BlockRenderView world, BlockPos positio
return getMaskedColor(BiomeColors.getFoliageColor(world, position), OAK_LEAVES_MASK);
} else if (block == Blocks.VINE) {
return getMaskedColor(BiomeColors.getFoliageColor(world, position), VINE_MASK);
} else if (block == Blocks.SHORT_GRASS) {
return getMaskedColor(BiomeColors.getGrassColor(world, position), SHORT_GRASS_MASK);
}
return 0;
}
Expand Down Expand Up @@ -108,7 +111,8 @@ public void onInitializeClient() {
Blocks.AZALEA_LEAVES,
Blocks.FLOWERING_AZALEA_LEAVES,
Blocks.CHERRY_LEAVES,
Blocks.VINE
Blocks.VINE,
Blocks.SHORT_GRASS
);
instance = this;
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/ishikyoo/leavesly/mixin/PlantBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.ishikyoo.leavesly.mixin;

import com.ishikyoo.leavesly.Leavesly;
import net.minecraft.block.*;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlantBlock.class)
public abstract class PlantBlockMixin extends Block {

public PlantBlockMixin(Settings settings) {
super(settings);
}

@Unique
protected boolean isValidClass() {
if (this.getClass().equals(ShortPlantBlock.class))
return true;
return false;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
if (isValidClass()) {
builder.add(Leavesly.SNOW);
}
}

@Inject(at = @At("TAIL"), method = "<init>")
private void init(AbstractBlock.Settings settings, CallbackInfo ci) {
if (isValidClass()) {
((BlockInvoker) this).invokeSetDefaultState(((Block) (Object) this).getDefaultState().with(Leavesly.SNOW, 0));
}
}

@Override
protected boolean hasRandomTicks(BlockState state) {
return true;
}

@Override
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
Leavesly.getInstance().tick(state, world, pos, random);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private void appendProperties(StateManager.Builder<Block, BlockState> builder, C
builder.add(Leavesly.SNOW);
}

// Set the default snowiness to zero
@Inject(at = @At("TAIL"), method = "<init>")
private void init(AbstractBlock.Settings settings, CallbackInfo ci) {
((BlockInvoker) this).invokeSetDefaultState(((Block) (Object) this).getDefaultState().with(Leavesly.SNOW, 0));
Expand Down
26 changes: 26 additions & 0 deletions src/main/resources/assets/leavesly/models/block/short_plant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"ambientocclusion": false,
"textures": {
"particle": "#plant"
},
"elements": [
{ "from": [ 0.8, 0, 8 ],
"to": [ 15.2, 16, 8 ],
"rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
"shade": false,
"faces": {
"north": { "uv": [ 0, 0, 16, 16 ], "texture": "#plant", "tintindex": 0 },
"south": { "uv": [ 0, 0, 16, 16 ], "texture": "#plant", "tintindex": 0 }
}
},
{ "from": [ 8, 0, 0.8 ],
"to": [ 8, 16, 15.2 ],
"rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
"shade": false,
"faces": {
"west": { "uv": [ 0, 0, 16, 16 ], "texture": "#plant", "tintindex": 0 },
"east": { "uv": [ 0, 0, 16, 16 ], "texture": "#plant", "tintindex": 0 }
}
}
]
}
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "leavesly:block/short_plant",
"textures": {
"plant": "leavesly:block/short_grass"
}
}
1 change: 1 addition & 0 deletions src/main/resources/leavesly.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mixins": [
"BlockInvoker",
"LeavesBlockMixin",
"PlantBlockMixin",
"VineBlockMixin"
],
"injectors": {
Expand Down

0 comments on commit e52b19c

Please sign in to comment.