Commit c90d1cfa by Jonathan Thomas

Initial proof of concept changes to Fabric Minecraft example mod. Generate 1…

Initial proof of concept changes to Fabric Minecraft example mod. Generate 1 random ChatGPT prompt, display it above all Living Entities.
parent 60fdaa75
# Automatically build the project and run any configured tests for every push
# and submitted pull request. This can help catch issues that only occur on
# certain platforms or Java versions, and provides a first line of defence
# against bad commits.
name: build
on: [pull_request, push]
jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
]
# and run on both Linux and Windows
os: [ubuntu-22.04, windows-2022]
runs-on: ${{ matrix.os }}
steps:
- name: checkout repository
uses: actions/checkout@v3
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'microsoft'
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: build/libs/
\ No newline at end of file
......@@ -22,7 +22,7 @@ loom {
splitEnvironmentSourceSets()
mods {
"modid" {
"mobgpt" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
......
......@@ -10,8 +10,8 @@ loader_version=0.14.22
# Mod Properties
mod_version=1.0.0
maven_group=com.example
archives_base_name=modid
maven_group=com.owlmaddie
archives_base_name=mobgpt
# Dependencies
fabric_version=0.89.1+1.20.2
package com.example;
import net.fabricmc.api.ClientModInitializer;
public class ExampleModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
}
}
\ No newline at end of file
package com.owlmaddie;
import java.util.List;
public class ChatGPTResponse {
public List<ChatGPTChoice> choices;
public static class ChatGPTChoice {
public ChatGPTMessage message;
}
public static class ChatGPTMessage {
public String content;
}
}
// GreetingResponse.java
package com.owlmaddie;
public class GreetingResponse {
private String greeting;
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
package com.owlmaddie;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.entity.Entity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.font.TextRenderer.TextLayerType;
public class LabelEntityRenderer<T extends Entity> extends EntityRenderer<T> {
public LabelEntityRenderer(EntityRendererFactory.Context context) {
super(context);
}
@Override
public Identifier getTexture(T entity) {
return MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(entity).getTexture(entity);
}
@Override
public void render(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
super.render(entity, yaw, tickDelta, matrices, vertexConsumers, light);
//MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(entity).render(entity, yaw, tickDelta, matrices, vertexConsumers, light);
Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera();
double cameraDistanceToEntity = camera.getPos().squaredDistanceTo(entity.getPos());
// Only show the label if we're within a certain distance (e.g., 25 blocks).
if (cameraDistanceToEntity <= 625) { // 25 * 25 to avoid sqrt for distance check.
// Get the name of the entity to display.
Text text = Text.literal("I'm a " + entity.getType().getName().getString());
// Calculate the position above the entity's head.
double yOffset = entity.getHeight() + 0.5; // Adjust this to position the label correctly.
// Push a new matrix onto the stack.
matrices.push();
// Translate to the entity's position.
matrices.translate(0, yOffset, 0);
// Rotate the label to always face the player.
matrices.multiply(camera.getRotation());
// Scale down the label so it's not huge.
matrices.scale(-0.025F, -0.025F, 0.025F);
// Render the text.
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
fontRenderer.draw(text, -fontRenderer.getWidth(text) / 2f, 0, 0xFFFFFF, false, matrices.peek().getPositionMatrix(), immediate, TextLayerType.NORMAL, 0, light);
// Pop the matrix to return to the original state.
matrices.pop();
}
}
}
\ No newline at end of file
package com.example.mixin.client;
package com.owlmaddie.mixin.client;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
......
{
"required": true,
"package": "com.example.mixin.client",
"package": "com.owlmaddie.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"ExampleClientMixin"
......
package com.example;
package com.owlmaddie;
import net.fabricmc.api.ModInitializer;
......@@ -9,7 +9,7 @@ public class ExampleMod implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("modid");
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
@Override
public void onInitialize() {
......@@ -17,6 +17,6 @@ public class ExampleMod implements ModInitializer {
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
LOGGER.info("Hello COW TEXT world!");
}
}
\ No newline at end of file
package com.example.mixin;
package com.owlmaddie.mixin;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
......
{
"schemaVersion": 1,
"id": "modid",
"id": "mobgpt",
"version": "${version}",
"name": "Example mod",
"name": "Mob GPT",
"description": "This is an example description! Tell everyone what your mod is about!",
"authors": [
"Me!"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
"homepage": "http://owlmaddie.com",
"sources": "http://gitlab.openshot.org/minecraft/mobgpt"
},
"license": "CC0-1.0",
"icon": "assets/modid/icon.png",
"icon": "assets/mobgpt/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.example.ExampleMod"
"com.owlmaddie.ExampleMod"
],
"client": [
"com.example.ExampleModClient"
"com.owlmaddie.ExampleModClient"
]
},
"mixins": [
"modid.mixins.json",
"mobgpt.mixins.json",
{
"config": "modid.client.mixins.json",
"config": "mobgpt.client.mixins.json",
"environment": "client"
}
],
......
{
"required": true,
"package": "com.example.mixin",
"package": "com.owlmaddie.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ExampleMixin"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment