This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
361 additions
and
177 deletions.
There are no files selected for viewing
143 changes: 14 additions & 129 deletions
143
reference-mod/src/main/java/dev/mineblock11/fabric/referencemod/MyMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,146 +1,31 @@ | ||
package dev.mineblock11.fabric.referencemod; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import dev.mineblock11.fabric.referencemod.block.ModBlockEntities; | ||
import dev.mineblock11.fabric.referencemod.block.ModBlocks; | ||
import dev.mineblock11.fabric.referencemod.event.ModEvents; | ||
import dev.mineblock11.fabric.referencemod.item.ModItems; | ||
import dev.mineblock11.fabric.referencemod.particle.ModParticles; | ||
import dev.mineblock11.fabric.referencemod.sound.ModSounds; | ||
import dev.mineblock11.fabric.referencemod.util.helper.LoggerUtil; | ||
import dev.mineblock11.fabric.referencemod.util.helper.TextUtil; | ||
import net.fabricmc.api.ModInitializer; | ||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; | ||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; | ||
import net.fabricmc.fabric.api.event.player.AttackEntityCallback; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.hud.ChatHud; | ||
import net.minecraft.client.render.*; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.RotationAxis; | ||
import net.minecraft.util.math.Vec3d; | ||
import org.apache.commons.lang3.text.WordUtils; | ||
import org.joml.Matrix4f; | ||
import org.lwjgl.opengl.GL11; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MyMod implements ModInitializer { | ||
public static final String MOD_ID = "referencemod"; | ||
|
||
public static String generateHumanReadable(Identifier identifier) { | ||
String identifier_path = identifier.getPath(); | ||
String lowercase = identifier_path.replace("_", " "); | ||
String capitalized = WordUtils.capitalize(lowercase); | ||
return capitalized; | ||
} | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
|
||
@Override | ||
public void onInitialize() { | ||
ModBlocks.initialize(); | ||
ModBlockEntities.registerBlockEntityTypes(); | ||
ModItems.initialize(); | ||
ModSounds.initializeSounds(); | ||
ModEvents.registerAllEvents(); | ||
ModParticles.initialize(); | ||
TextUtil.initializeAllTextFunctions(); | ||
|
||
PlayerDiedCallback.EVENT.register((player, deathMessage) -> { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
ChatHud chat = client.inGameHud.getChatHud(); | ||
|
||
chat.addMessage(Text.literal(player.getEntityName() + "... you're an absolute idiot.")); | ||
}); | ||
|
||
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> { | ||
Matrix4f positionMatrix = drawContext.getMatrices().peek().getPositionMatrix(); | ||
Tessellator tessellator = Tessellator.getInstance(); | ||
BufferBuilder buffer = tessellator.getBuffer(); | ||
|
||
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE); | ||
buffer.vertex(positionMatrix, 20, 20, 0).color(1f, 1f, 1f, 1f).texture(0f, 0f).next(); | ||
buffer.vertex(positionMatrix, 20, 60, 0).color(1f, 0f, 0f, 1f).texture(0f, 1f).next(); | ||
buffer.vertex(positionMatrix, 60, 60, 0).color(0f, 1f, 0f, 1f).texture(1f, 1f).next(); | ||
buffer.vertex(positionMatrix, 60, 20, 0).color(0f, 0f, 1f, 1f).texture(1f, 0f).next(); | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorTexProgram); | ||
RenderSystem.setShaderTexture(0, new Identifier(MyMod.MOD_ID, "icon.png")); | ||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f); | ||
|
||
tessellator.draw(); | ||
}); | ||
|
||
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> { | ||
MatrixStack matrixStack = drawContext.getMatrices(); | ||
matrixStack.push(); | ||
|
||
matrixStack.translate(40, 40, 0); | ||
matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((System.currentTimeMillis() % 5000) / 5000f * 360f)); | ||
matrixStack.translate(-40, -40, 0); | ||
|
||
Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix(); | ||
Tessellator tessellator = Tessellator.getInstance(); | ||
BufferBuilder buffer = tessellator.getBuffer(); | ||
|
||
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE); | ||
buffer.vertex(positionMatrix, 20, 20, 0).color(1f, 1f, 1f, 1f).texture(0f, 0f).next(); | ||
buffer.vertex(positionMatrix, 20, 60, 0).color(1f, 0f, 0f, 1f).texture(0f, 1f).next(); | ||
buffer.vertex(positionMatrix, 60, 60, 0).color(0f, 1f, 0f, 1f).texture(1f, 1f).next(); | ||
buffer.vertex(positionMatrix, 60, 20, 0).color(0f, 0f, 1f, 1f).texture(1f, 0f).next(); | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorTexProgram); | ||
RenderSystem.setShaderTexture(0, new Identifier(MyMod.MOD_ID, "icon.png")); | ||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f); | ||
|
||
tessellator.draw(); | ||
matrixStack.pop(); | ||
}); | ||
|
||
WorldRenderEvents.END.register(context -> { | ||
Camera camera = context.camera(); | ||
|
||
Vec3d targetPosition = new Vec3d(0, 100, 0); | ||
Vec3d transformedPosition = targetPosition.subtract(camera.getPos()); | ||
|
||
MatrixStack matrixStack = new MatrixStack(); | ||
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); | ||
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(camera.getYaw() + 180.0F)); | ||
matrixStack.translate(transformedPosition.x, transformedPosition.y, transformedPosition.z); | ||
|
||
Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix(); | ||
Tessellator tessellator = Tessellator.getInstance(); | ||
BufferBuilder buffer = tessellator.getBuffer(); | ||
|
||
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE); | ||
buffer.vertex(positionMatrix, 0, 1, 0).color(1f, 1f, 1f, 1f).texture(0f, 0f).next(); | ||
buffer.vertex(positionMatrix, 0, 0, 0).color(1f, 0f, 0f, 1f).texture(0f, 1f).next(); | ||
buffer.vertex(positionMatrix, 1, 0, 0).color(0f, 1f, 0f, 1f).texture(1f, 1f).next(); | ||
buffer.vertex(positionMatrix, 1, 1, 0).color(0f, 0f, 1f, 1f).texture(1f, 0f).next(); | ||
|
||
RenderSystem.setShader(GameRenderer::getPositionColorTexProgram); | ||
RenderSystem.setShaderTexture(0, new Identifier(MyMod.MOD_ID, "icon.png")); | ||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f); | ||
RenderSystem.disableCull(); | ||
RenderSystem.depthFunc(GL11.GL_ALWAYS); | ||
|
||
tessellator.draw(); | ||
|
||
RenderSystem.depthFunc(GL11.GL_LEQUAL); | ||
RenderSystem.enableCull(); | ||
}); | ||
|
||
Text translatable = Text.translatable("my_mod.text.hello"); | ||
MutableText mutable = Text.translatable("my_mod.text.bye"); | ||
|
||
String jsonString = Text.Serializer.toJson(mutable); | ||
MutableText result = Text.Serializer.fromJson(jsonString); | ||
|
||
result = Text.literal("Hello World!").formatted(Formatting.AQUA, Formatting.BOLD, Formatting.UNDERLINE); | ||
|
||
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> { | ||
var playerName = player.getDisplayName().copy(); | ||
var entityName = entity.getDisplayName().copy(); | ||
|
||
MinecraftClient client = MinecraftClient.getInstance(); | ||
ChatHud chat = client.inGameHud.getChatHud(); | ||
|
||
chat.addMessage(Text.of("SNAP!!!!")); | ||
chat.addMessage(playerName.append(" attacked ").append(entityName)); | ||
|
||
return ActionResult.PASS; | ||
}); | ||
LoggerUtil.devLogger("All classes have been initialized"); | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
...bric/referencemod/client/MyModClient.java → ...ck11/fabric/referencemod/MyModClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
package dev.mineblock11.fabric.referencemod.client; | ||
package dev.mineblock11.fabric.referencemod; | ||
|
||
import dev.mineblock11.fabric.referencemod.ModParticles; | ||
import dev.mineblock11.fabric.referencemod.MyParticle; | ||
import dev.mineblock11.fabric.referencemod.particle.ModParticles; | ||
import dev.mineblock11.fabric.referencemod.particle.custom.MyParticle; | ||
import dev.mineblock11.fabric.referencemod.util.helper.LoggerUtil; | ||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; | ||
import net.minecraft.client.particle.EndRodParticle; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class MyModClient implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
ParticleFactoryRegistry.getInstance().register(ModParticles.MY_PARTICLE, MyParticle.Factory::new); | ||
|
||
LoggerUtil.devLogger("All client classes have been initialized"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ferencemod/block/PrismarineLampBlock.java → ...mod/block/custom/PrismarineLampBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
.../fabric/referencemod/block/TestBlock.java → .../referencemod/block/custom/TestBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...c/referencemod/block/TestBlockEntity.java → ...encemod/block/entity/TestBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
reference-mod/src/main/java/dev/mineblock11/fabric/referencemod/datagen/MyModDatagen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...d/datagen/EnglishTranslationProvider.java → .../provider/EnglishTranslationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...erencemod/datagen/MyBlockTagProvider.java → .../datagen/provider/MyBlockTagProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.