Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public enum Blocks {

TEST_BLOCK("test_block", "testBlock", id -> new TemplateBlock(id, Material.CLAY).setHardness(1)),
TEST_BLOCK("test_block", "testBlock", id -> new TemplateBlock(id, Material.STONE).setHardness(1)),
TEST_ANIMATED_BLOCK("test_animated_block", "testAnimatedBlock", id -> new ModdedMetaBlock(id, Material.NETHER_PORTAL)),
CUSTOM_MODEL_BLOCK("farlands_block", "farlands_block", id -> new ModdedModelBlock(id, Material.SOIL).setHardness(1)),
FREEZER("freezer", "freezer", id -> new BlockFreezer(id).setHardness(2.5F).setSoundGroup(TemplateBlock.DEFAULT_SOUND_GROUP)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.modificationstation.sltest.gui.hud;

import net.mine_diver.unsafeevents.listener.EventListener;
import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine;
import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextRenderEvent;

import java.util.Collections;
import java.util.Random;

public class TestHudText {
private final Random random = new Random();

@EventListener
public void renderHudText(HudTextRenderEvent event) {
event.setVersion(new HudTextLine(
"Statint api 2rd version ;)" + (event.debug ? "(" + event.minecraft.debugText + ")" : ""),
random.nextInt(0xFFFFFF + 1))
);
Collections.addAll(event.left,
new HudTextLine("yippee :3"),
new HudTextLine("wahoo")
);
Collections.addAll(event.right,
new HudTextLine("gaming", 0x5BCEFA),
new HudTextLine("god has forsaken me", 0xF5A9B8,8),
new HudTextLine("waow :o", HudTextLine.WHITE, 8),
new HudTextLine("this is not a test", 0xF5A9B8, 8),
new HudTextLine("ok nvm now it is", 0x5BCEFA, 8)
);
if (event.debug) {
event.left.add(new HudTextLine("This Texts only Shows In de Bugge ?!??! :0"));
event.right.add(new HudTextLine("this text has a rly big offsets", 0xFF0000, 47));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import net.modificationstation.sltest.block.Blocks;
import net.modificationstation.sltest.block.VariationBlock;
import net.modificationstation.stationapi.api.event.registry.ItemRegistryEvent;
import net.modificationstation.stationapi.api.item.tool.MiningLevelManager;
import net.modificationstation.stationapi.api.item.tool.ToolMaterialFactory;
import net.modificationstation.stationapi.api.registry.BlockRegistry;
import net.modificationstation.stationapi.api.registry.ItemRegistry;
import net.modificationstation.stationapi.api.registry.Registry;
import net.modificationstation.stationapi.api.tag.TagKey;
import net.modificationstation.stationapi.api.template.item.BlockStateItem;

import static net.modificationstation.sltest.SLTest.NAMESPACE;
Expand All @@ -17,8 +20,13 @@ public class ItemListener {

@EventListener
public void registerItems(ItemRegistryEvent event) {
MiningLevelManager.LevelNode moddedNode = new MiningLevelManager.LevelNode(TagKey.of(BlockRegistry.KEY, NAMESPACE.id("needs_tool_level_modded")));
MiningLevelManager.GRAPH.putEdge(ToolMaterial.STONE.getMiningLevelNode(), moddedNode);
MiningLevelManager.GRAPH.putEdge(moddedNode, ToolMaterial.IRON.getMiningLevelNode());
MiningLevelManager.invalidateCache();

testItem = new ModdedItem(NAMESPACE.id("test_item")).setTranslationKey(NAMESPACE, "testItem"); //8475
testMaterial = ToolMaterialFactory.create("testMaterial", 3, Integer.MAX_VALUE, Float.MAX_VALUE, Integer.MAX_VALUE - 2);
testMaterial = ToolMaterialFactory.create("testMaterial", 3, Integer.MAX_VALUE, Float.MAX_VALUE, Integer.MAX_VALUE - 2).miningLevelNode(moddedNode);
testPickaxe = new ModdedPickaxeItem(NAMESPACE.id("test_pickaxe"), testMaterial).setTranslationKey(NAMESPACE, "testPickaxe"); //8476
testNBTItem = new NBTItem(NAMESPACE.id("nbt_item")).setTranslationKey(NAMESPACE, "nbt_item"); //8477
testModelItem = new ModelItem(NAMESPACE.id("model_item")).setMaxCount(1).setTranslationKey(NAMESPACE, "idkSomething");
Expand All @@ -30,6 +38,8 @@ public void registerItems(ItemRegistryEvent event) {
testShears = new TestShearsItem(NAMESPACE.id("test_shears")).setTranslationKey(NAMESPACE, "test_shears");
pacifistSword = new PacifistSwordItem(NAMESPACE.id("pacifist_sword")).setTranslationKey(NAMESPACE, "pacifist_sword");
dullPickaxe = new DullPickaxeItem(NAMESPACE.id("dull_pickaxe")).setTranslationKey(NAMESPACE, "dull_pickaxe");


}

public static Item testItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:test_block"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:test_block"
]
}
3 changes: 2 additions & 1 deletion src/test/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"net.modificationstation.sltest.datafixer.DataFixerListener",
"net.modificationstation.sltest.worldgen.TestWorldgenListener",
"net.modificationstation.sltest.bonemeal.BonemealListener",
"net.modificationstation.sltest.dispenser.DispenserListener"
"net.modificationstation.sltest.dispenser.DispenserListener",
"net.modificationstation.sltest.gui.hud.TestHudText"
],
"stationapi:event_bus_client": [
"net.modificationstation.sltest.gui.GuiListener",
Expand Down
1 change: 1 addition & 0 deletions station-flattening-v0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = getSubprojectVersion(project, "1.0.0")

addModuleDependencies(project,
"station-api-base",
"station-gui-api-v0",
"station-maths-v0",
"station-registry-api-v0",
"station-networking-v0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net.modificationstation.stationapi.impl.client.gui.hud;

import net.fabricmc.loader.api.FabricLoader;
import net.mine_diver.unsafeevents.listener.EventListener;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.hit.HitResultType;
import net.modificationstation.stationapi.api.StationAPI;
import net.modificationstation.stationapi.api.block.BlockState;
import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextRenderEvent;
import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine;
import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint;
import net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy;
import net.modificationstation.stationapi.api.state.property.Property;
import net.modificationstation.stationapi.api.tag.TagKey;

import java.util.Collection;
import java.util.Collections;

import static net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine.GRAY;
import static net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine.WHITE;

@Entrypoint(eventBus = @EventBusPolicy(registerInstance = false))
public class StationFlatteningHudText {
@EventListener(phase = StationAPI.INTERNAL_PHASE)
private static void renderHudText(HudTextRenderEvent event) {
if (!event.debug) return;
HitResult hit = event.minecraft.field_2823;
if (hit == null || hit.type != HitResultType.BLOCK) return;
BlockState state = event.minecraft.world.getBlockState(hit.blockX, hit.blockY, hit.blockZ);
Collections.addAll(event.right,
new HudTextLine("Block: " + state.getBlock().getTranslatedName(), WHITE, 20),
new HudTextLine("Meta: " + event.minecraft.world.getBlockMeta(hit.blockX, hit.blockY, hit.blockZ))
);
Collection<Property<?>> properties = state.getProperties();
if (!properties.isEmpty()) {
event.right.add(new HudTextLine("Properties:"));
event.right.addAll(properties.stream().map(prop ->
new HudTextLine(prop.getName() + ": " + state.get(prop), GRAY)
).toList());
}

Collection<TagKey<Block>> tags = state.streamTags().toList();
if (!tags.isEmpty()) {
event.right.add(new HudTextLine("Tags:"));
event.right.addAll(tags.stream().map(tag -> new HudTextLine("#" + tag.id(), GRAY)).toList());
}

if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
BlockEntity entity = event.minecraft.world.method_1777(hit.blockX, hit.blockY, hit.blockZ);
if (entity != null) {
String className = entity.getClass().getName();
String text = "Tile Entity: " + className.substring(className.lastIndexOf('.') + 1);
event.right.add(new HudTextLine(text, WHITE, 20));
}
}
}
}

This file was deleted.

3 changes: 2 additions & 1 deletion station-flattening-v0/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"net.modificationstation.stationapi.api.block.States",
"net.modificationstation.stationapi.impl.block.PlacementStateImpl",
"net.modificationstation.stationapi.impl.world.WorldDataVersionImpl",
"net.modificationstation.stationapi.impl.block.BlockInteractionImpl"
"net.modificationstation.stationapi.impl.block.BlockInteractionImpl",
"net.modificationstation.stationapi.impl.client.gui.hud.StationFlatteningHudText"
],
"main": [
"net.modificationstation.stationapi.impl.packet.StationFlatteningNetworkingImpl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"client": [
"client.BlockRenderManagerMixin",
"client.ClientWorldMixin",
"client.InGameHudMixin",
"client.InteractionManagerMixin",
"client.MinecraftMixin",
"client.MultiplayerChunkCacheMixin",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.modificationstation.stationapi.api.client.event.gui.hud;

import lombok.AllArgsConstructor;

/**
* Text and info for rendering custom HUD text lines.
*/
@AllArgsConstructor
public final class HudTextLine {
public static final int WHITE = 0xFFFFFF;
public static final int GRAY = 0xE0E0E0;

public String text;
public int color;
public int offset;

public HudTextLine(String text) {
this(text, WHITE);
}
public HudTextLine(String text, int color) {
this(text, color, 10);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.modificationstation.stationapi.api.client.event.gui.hud;

import lombok.Getter;
import lombok.experimental.SuperBuilder;
import net.mine_diver.unsafeevents.Event;
import net.mine_diver.unsafeevents.event.EventPhases;
import net.minecraft.client.Minecraft;
import net.modificationstation.stationapi.api.StationAPI;

import java.util.ArrayList;
import java.util.List;

/**
* Fires while rendering the game HUD.
*/
@SuperBuilder
@EventPhases({StationAPI.INTERNAL_PHASE, EventPhases.DEFAULT_PHASE})
public class HudTextRenderEvent extends Event {
public final List<HudTextLine> left = new ArrayList<>(), right = new ArrayList<>();
@Getter private HudTextLine version;
public final boolean debug;
public final Minecraft minecraft;

/**
* Set by highest priority listener.
*/
public void setVersion(HudTextLine line) {
if (version == null) version = line;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package net.modificationstation.stationapi.impl.client.gui.hud;

import net.mine_diver.unsafeevents.listener.EventListener;
import net.mine_diver.unsafeevents.listener.ListenerPriority;
import net.minecraft.util.math.MathHelper;
import net.modificationstation.stationapi.api.StationAPI;
import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextRenderEvent;
import net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine;
import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint;
import net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy;

import static net.modificationstation.stationapi.api.client.event.gui.hud.HudTextLine.GRAY;

import java.util.Collections;

@Entrypoint(eventBus = @EventBusPolicy(registerInstance = false))
public class StationVanillaHudText {
@EventListener(phase = StationAPI.INTERNAL_PHASE, priority = ListenerPriority.HIGHEST)
private static void renderVanillaDebugText(HudTextRenderEvent event) {
if (!event.debug) return;
Collections.addAll(event.left,
new HudTextLine(event.minecraft.method_2141()),
new HudTextLine(event.minecraft.method_2142()),
new HudTextLine(event.minecraft.method_2144()),
new HudTextLine(event.minecraft.method_2143()),
new HudTextLine("x: " + event.minecraft.player.x, GRAY, 22),
new HudTextLine("y: " + event.minecraft.player.y, GRAY, 8),
new HudTextLine("z: " + event.minecraft.player.y, GRAY, 8),
new HudTextLine(
"f: " + (MathHelper.floor((double)(event.minecraft.player.yaw * 4.0F / 360.0F) + 0.5) & 3),
GRAY, 8
)
);
long max = Runtime.getRuntime().maxMemory();
long total = Runtime.getRuntime().totalMemory();
long free = Runtime.getRuntime().freeMemory();
long used = total - free;
Collections.addAll(event.right,
new HudTextLine(
"Used memory: " + used * 100L / max + "% (" + used / 1024L / 1024L + "MB) of " +
max / 1024L / 1024L + "MB", GRAY
),
new HudTextLine(
"Allocated memory: " + total * 100L / max + "% (" + total / 1024L / 1024L + "MB)", GRAY
)
);
}

@EventListener(priority = ListenerPriority.LOWEST)
private static void renderVanillaVersionText(HudTextRenderEvent event) {
if (!event.debug) return;
event.setVersion(new HudTextLine("Minecraft Beta 1.7.3 (" + event.minecraft.debugText + ")"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.modificationstation.stationapi.api.client.gui.widget.ButtonWidgetDetachedContext;
import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint;
import net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy;
import net.modificationstation.stationapi.mixin.gui.client.ScreenAccessor;
import net.modificationstation.stationapi.mixin.client.gui.ScreenAccessor;

@Entrypoint(eventBus = @EventBusPolicy(registerInstance = false))
@EventListener(phase = StationAPI.INTERNAL_PHASE)
Expand Down
Loading