Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
44 changes: 37 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: build
on: [pull_request, push]

jobs:
build:
build-fabric-1-21-1:
runs-on: ubuntu-24.04
steps:
- name: checkout repository
Expand All @@ -17,14 +17,44 @@ jobs:
- name: setup jdk
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'microsoft'
java-version: "25"
distribution: "microsoft"
- name: make gradle wrapper executable
working-directory: ./Fabric-1.21.1
run: chmod +x ./gradlew
- name: build

- name: build Fabric 1.21.1
working-directory: ./Fabric-1.21.1
run: ./gradlew build
- name: capture build artifacts

- name: upload artifacts Fabric 1.21.1
uses: actions/upload-artifact@v4
with:
name: Fabric-1.21.1-artifacts
path: Fabric-1.21.1/build/libs/

build-fabric-1-21-11:
runs-on: ubuntu-24.04
steps:
- name: checkout repository
uses: actions/checkout@v4
- name: validate gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: setup jdk
uses: actions/setup-java@v4
with:
java-version: "25"
distribution: "microsoft"
- name: make gradle wrapper executable
working-directory: ./Fabric-1.21.11
run: chmod +x ./gradlew

- name: build Fabric 1.21.11
working-directory: ./Fabric-1.21.11
run: ./gradlew build

- name: upload artifacts Fabric 1.21.11
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
name: Fabric-1.21.11-artifacts
path: Fabric-1.21.11/build/libs/
90 changes: 90 additions & 0 deletions Fabric-1.21.1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
plugins {
id 'net.fabricmc.fabric-loom-remap' version "${loom_version}"
id 'maven-publish'
}

version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}

loom {
splitEnvironmentSourceSets()

mods {
"box3" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}

}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": inputs.properties.version
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
inputs.property "archivesName", project.base.archivesName

from("LICENSE") {
rename { "${it}_${inputs.properties.archivesName}"}
}
}

// configure the maven publication
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
20 changes: 20 additions & 0 deletions Fabric-1.21.1/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# IntelliJ IDEA is not yet fully compatible with configuration cache, see: https://github.com/FabricMC/fabric-loom/issues/1349
org.gradle.configuration-cache=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
loader_version=0.18.4
loom_version=1.15-SNAPSHOT

# Mod Properties
mod_version=1.4.0-mc1.21.1
maven_group=com.box3lab
archives_base_name=box3

# Dependencies
fabric_api_version=0.116.8+1.21.1
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions Fabric-1.21.1/src/client/java/com/box3lab/Box3Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.box3lab;

import com.box3lab.register.ModBlocks;
import com.box3lab.util.BlockIndexUtil;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;

public class Box3Client implements ClientModInitializer {
@Override
public void onInitializeClient() {

for (var entry : ModBlocks.BLOCKS.entrySet()) {
String registryName = entry.getKey();
Block block = entry.getValue();

Integer id = BlockIndexUtil.getIdByName(registryName);
if (id != null && !BlockIndexUtil.isSolid(id)) {
BlockRenderLayerMap.INSTANCE.putBlock(block, RenderType.translucent());
}
}

}
}
53 changes: 53 additions & 0 deletions Fabric-1.21.1/src/main/java/com/box3lab/item/ModelDisplayItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.box3lab.item;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

public class ModelDisplayItem extends Item {
public ModelDisplayItem(Properties properties) {
super(properties);
}

@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
if (!(level instanceof ServerLevel serverLevel)) {
return InteractionResult.SUCCESS;
}

Display.ItemDisplay display = (Display.ItemDisplay) EntityType.ITEM_DISPLAY.create(serverLevel);
if (display == null) {
return InteractionResult.FAIL;
}

BlockPos placePos = context.getClickedPos().relative(context.getClickedFace());
Vec3 pos = Vec3.atCenterOf(placePos);
display.setPos(pos.x, pos.y, pos.z);

Player player = context.getPlayer();
if (player != null) {
display.setYRot(player.getYRot());
}

ItemStack displayStack = context.getItemInHand().copyWithCount(1);
display.getSlot(0).set(displayStack);

display.setNoGravity(true);
serverLevel.addFreshEntity(display);

if (player == null || !player.getAbilities().instabuild) {
context.getItemInHand().shrink(1);
}

return InteractionResult.SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.box3lab.register;

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import com.box3lab.Box3;
import com.box3lab.item.ModelDisplayItem;
import com.box3lab.register.creative.CreativeTabExtras;
import com.box3lab.register.creative.CreativeTabRegistrar;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;

public final class ModelItemRegistrar {
private static final String ITEMS_DIR_PREFIX = "assets/" + Box3.MOD_ID + "/items/";
public static final String DEFAULT_TAB = "models";

private ModelItemRegistrar() {
}

public static void registerAll() {
Set<String> itemPaths = discoverModelItemPaths();
if (itemPaths.isEmpty()) {
return;
}

for (String path : itemPaths) {
ResourceLocation id;
try {
id = ResourceLocation.fromNamespaceAndPath(Box3.MOD_ID, path);
} catch (IllegalArgumentException e) {
continue;
}

if (BuiltInRegistries.ITEM.containsKey(id)) {
continue;
}

Item item = new ModelDisplayItem(new Item.Properties());
Registry.register(BuiltInRegistries.ITEM, id, item);
CreativeTabExtras.add(DEFAULT_TAB, item);
}

CreativeTabRegistrar.registerModelTab(Box3.MOD_ID);
}

private static Set<String> discoverModelItemPaths() {
Set<String> results = new LinkedHashSet<>();
Path resourcepacksDir = FabricLoader.getInstance().getGameDir().resolve("resourcepacks");
if (!Files.isDirectory(resourcepacksDir)) {
return results;
}

try (DirectoryStream<Path> stream = Files.newDirectoryStream(resourcepacksDir)) {
for (Path entry : stream) {
if (Files.isDirectory(entry)) {
scanDirectoryPack(entry, results);
} else if (isArchive(entry)) {
scanZipPack(entry, results);
}
}
} catch (IOException ignored) {
}

return results;
}

private static boolean isArchive(Path path) {
String name = path.getFileName().toString().toLowerCase(Locale.ROOT);
return name.endsWith(".zip") || name.endsWith(".jar");
}

private static void scanDirectoryPack(Path packDir, Set<String> out) {
Path itemsDir = packDir.resolve("assets").resolve(Box3.MOD_ID).resolve("items");
if (!Files.isDirectory(itemsDir)) {
return;
}

try (var paths = Files.walk(itemsDir)) {
paths.filter(Files::isRegularFile)
.forEach(file -> {
String name = file.getFileName().toString();
if (!name.endsWith(".json")) {
return;
}

String rel = itemsDir.relativize(file).toString().replace(File.separatorChar, '/');
if (rel.endsWith(".json")) {
rel = rel.substring(0, rel.length() - 5);
}
if (!rel.isBlank()) {
out.add(rel);
}
});
} catch (IOException ignored) {
}
}

private static void scanZipPack(Path zipPath, Set<String> out) {
try (ZipFile zip = new ZipFile(zipPath.toFile())) {
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.isDirectory()) {
continue;
}
String name = entry.getName();
if (!name.startsWith(ITEMS_DIR_PREFIX) || !name.endsWith(".json")) {
continue;
}
String rel = name.substring(ITEMS_DIR_PREFIX.length(), name.length() - 5);
if (!rel.isBlank()) {
out.add(rel);
}
}
} catch (IOException ignored) {
}
}
}
Loading