Skip to content

Commit

Permalink
Added debugging, grass still green
Browse files Browse the repository at this point in the history
  • Loading branch information
haslo committed Oct 10, 2023
1 parent e5ef293 commit 74b4bbd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ dependencies {
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
implementation 'org.spongepowered:mixin:0.8.+'
modImplementation "net.fabricmc.fabric-api:fabric-renderer-api-v1:3.2.1+2034447cb2"

// implementation 'org.spongepowered:mixin:0.8.5' // BREAKS EVERYTHING DO NOT USE
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
public class ExampleClientMixin {
@Inject(at = @At("HEAD"), method = "run")
private void run(CallbackInfo info) {
// This code is injected into the start of MinecraftClient.run()V
System.out.println("Hello, World! Bluegrass mod is loaded.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -21,11 +19,13 @@
public class GrassBlockMixin {
@Inject(method = "getModel", at = @At("HEAD"), cancellable = true)
public void getModel(ModelIdentifier id, CallbackInfoReturnable<BakedModel> cir) {
if (id.equals(new Identifier("minecraft", "grass_block_side"))) {
System.out.println("Requested model: " + id.toString());
if ("minecraft".equals(id.getNamespace()) && "grass_block".equals(id.getPath())) {
Identifier blockAtlasId = new Identifier("minecraft", "textures/atlas/blocks.png");
Function<Identifier, Sprite> spriteGetter = MinecraftClient.getInstance().getSpriteAtlas(blockAtlasId);
BakedModel customModel = new BlueGrassSideModel(spriteGetter);
cir.setReturnValue(customModel);
System.out.println("Mixin applied!");
}
}
}
19 changes: 13 additions & 6 deletions src/client/java/ch/haslo/bluegrass/models/BlueGrassSideModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
Expand All @@ -25,13 +23,19 @@ public class BlueGrassSideModel implements BakedModel {
public BlueGrassSideModel(Function<Identifier, Sprite> spriteGetter) {
Identifier identifier = new Identifier("bluegrass", "block/grass_block_side");
this.sprite = spriteGetter.apply(identifier);
if (this.sprite == null) {
System.out.println("Sprite is null");
} else {
System.out.println("Sprite loaded");
}
}

@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction face, Random random) {
System.out.println("Getting quads for " + state + " / " + face + " / " + random);
BakedModel originalModel = MinecraftClient.getInstance().getBakedModelManager().getModel(new ModelIdentifier(new Identifier("minecraft", "grass_block"), ""));
List<BakedQuad> quads = new ArrayList<>(originalModel.getQuads(state, face, random));
if (face == null) {
if (face == null || face == Direction.DOWN) {
return originalModel.getQuads(state, face, random);
}
if (face == Direction.UP) {
Expand All @@ -44,12 +48,10 @@ public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction
int red = color >> 16 & 255;
int green = color >> 8 & 255;
int blue = color & 255;

// Multiply to apply blue tint
blue = Math.min(255, blue * 2); // Multiply blue component by 2, capped at 255

int newColor = (alpha << 24) | (red << 16) | (green << 8) | blue;
vertexData[i + 3] = newColor;
System.out.println("Blue tint applied to " + i);
}
BakedQuad newQuad = new BakedQuad(vertexData, -1, quad.getFace(), quad.getSprite(), quad.hasShade());
newQuads.add(newQuad);
Expand All @@ -69,6 +71,11 @@ public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction
quads.add(customQuad);
}
// south, noop
if (quads.isEmpty()) {
System.out.println("No quads generated for " + face);
} else {
System.out.println("Quads generated for " + face);
}
return quads;
}

Expand Down

0 comments on commit 74b4bbd

Please sign in to comment.