diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c37caf --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Cache of project +.gradletasknamecache + +**/build/ + +# Common working directory +run/ + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a0e67c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ac680fc --- /dev/null +++ b/build.gradle @@ -0,0 +1,84 @@ +plugins { + id 'fabric-loom' version '0.12-SNAPSHOT' + id 'maven-publish' + id 'io.github.juuxel.loom-quiltflower' version '1.8.0' +} + +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 + +archivesBaseName = project.archives_base_name +version = "${project.mod_version}+${project.minecraft_base_version}" +group = project.maven_group + +repositories { + // modmenu, trinkets + maven { url "https://maven.terraformersmc.com/" } + + // cca + maven { url "https://ladysnake.jfrog.io/artifactory/mods" } + + // owo + maven { url "https://maven.wispforest.io" } + + // rei + maven { url "https://maven.shedaniel.me/" } + + // lazydfu + maven { + url "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } + } +} + +dependencies { + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // actual dependencies + + modLocalRuntime "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}" + modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}" + + modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" + + modImplementation "dev.emi:trinkets:${project.trinkets_version}" + + modImplementation "io.wispforest:owo-lib:${project.owo_version}" + include "io.wispforest:owo-sentinel:${project.owo_version}" + + // dev utils + + modLocalRuntime "maven.modrinth:lazydfu:0.1.3" +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 +} + +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() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..a2366ba --- /dev/null +++ b/gradle.properties @@ -0,0 +1,29 @@ +# Done to increase the memory available to gradle. + org.gradle.jvmargs=-Xmx1G + +# Fabric Properties +# check these on https://fabricmc.net/develop + minecraft_base_version=1.19.3 + minecraft_version=1.19.3 + yarn_mappings=1.19.3+build.5 + loader_version=0.14.13 + + fabric_version=0.73.0+1.19.3 + +# Mod Properties + mod_version=0.1.0 + maven_group=io.wispforest + archives_base_name=out-the-door + +# Dependencies + # https://www.curseforge.com/minecraft/mc-mods/trinkets/files + trinkets_version=3.5.0 + + # https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/ + rei_version=10.0.578 + + # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu + modmenu_version=5.0.2 + + # https://maven.wispforest.io/io/wispforest/owo-lib/ + owo_version=0.10.1+1.19.3 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..41d9927 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..aa991fc --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..f91a4fe --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/io/wispforest/outthedoor/OutTheDoor.java b/src/main/java/io/wispforest/outthedoor/OutTheDoor.java new file mode 100644 index 0000000..7926e5a --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/OutTheDoor.java @@ -0,0 +1,41 @@ +package io.wispforest.outthedoor; + +import io.wispforest.outthedoor.misc.BackpackType; +import io.wispforest.outthedoor.object.OutTheDoorBackpackTypes; +import io.wispforest.outthedoor.object.OutTheDoorBlocks; +import io.wispforest.outthedoor.object.OutTheDoorItems; +import io.wispforest.owo.itemgroup.Icon; +import io.wispforest.owo.itemgroup.OwoItemGroup; +import io.wispforest.owo.registration.reflect.FieldRegistrationHandler; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; +import net.fabricmc.fabric.api.event.registry.RegistryAttribute; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class OutTheDoor implements ModInitializer { + + public static final String MOD_ID = "out-the-door"; + + public static final OwoItemGroup GROUP = OwoItemGroup + .builder(id("out-the-door"), () -> Icon.of(OutTheDoorItems.LEATHER_BACKPACK)) + .build(); + + public static final Registry BACKPACK_REGISTRY = FabricRegistryBuilder.createSimple(BackpackType.class, id("backpack")) + .attribute(RegistryAttribute.SYNCED) + .buildAndRegister(); + + @Override + public void onInitialize() { + FieldRegistrationHandler.register(OutTheDoorBackpackTypes.class, MOD_ID, false); + + FieldRegistrationHandler.register(OutTheDoorBlocks.class, MOD_ID, true); + FieldRegistrationHandler.register(OutTheDoorItems.class, MOD_ID, false); + + GROUP.initialize(); + } + + public static Identifier id(String path) { + return new Identifier(MOD_ID, path); + } +} diff --git a/src/main/java/io/wispforest/outthedoor/block/BackpackBlock.java b/src/main/java/io/wispforest/outthedoor/block/BackpackBlock.java new file mode 100644 index 0000000..e997d46 --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/block/BackpackBlock.java @@ -0,0 +1,46 @@ +package io.wispforest.outthedoor.block; + +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.*; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import org.jetbrains.annotations.Nullable; + +public class BackpackBlock extends HorizontalFacingBlock implements BlockEntityProvider { + + private static final VoxelShape Z_SHAPE = Block.createCuboidShape(2.75, 0, 5.25, 12.75, 11, 11.25); + private static final VoxelShape X_SHAPE = Block.createCuboidShape(5, 0, 3, 11, 11, 13); + + public BackpackBlock() { + super(FabricBlockSettings.copyOf(Blocks.BROWN_WOOL).nonOpaque()); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return state.get(FACING).getAxis() == Direction.Axis.X + ? X_SHAPE + : Z_SHAPE; + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(FACING); + } + + @Nullable + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite()); + } + + @Nullable + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new BackpackBlockEntity(pos, state); + } +} diff --git a/src/main/java/io/wispforest/outthedoor/block/BackpackBlockEntity.java b/src/main/java/io/wispforest/outthedoor/block/BackpackBlockEntity.java new file mode 100644 index 0000000..515bf02 --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/block/BackpackBlockEntity.java @@ -0,0 +1,42 @@ +package io.wispforest.outthedoor.block; + +import io.wispforest.outthedoor.item.BackpackItem; +import io.wispforest.outthedoor.object.OutTheDoorBlocks; +import io.wispforest.owo.nbt.NbtKey; +import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachmentBlockEntity; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +public class BackpackBlockEntity extends BlockEntity implements RenderAttachmentBlockEntity { + + public static final NbtKey BACKPACK = new NbtKey<>("Backpack", NbtKey.Type.ITEM_STACK); + + public ItemStack backpack = ItemStack.EMPTY; + + public BackpackBlockEntity(BlockPos pos, BlockState state) { + super(OutTheDoorBlocks.Entities.BACKPACK, pos, state); + } + + @Override + public void readNbt(NbtCompound nbt) { + super.readNbt(nbt); + this.backpack = nbt.get(BACKPACK); + } + + @Override + protected void writeNbt(NbtCompound nbt) { + super.writeNbt(nbt); + nbt.put(BACKPACK, this.backpack); + } + + @Override + public @Nullable Object getRenderAttachmentData() { + return this.backpack.getItem() instanceof BackpackItem backpackItem + ? backpackItem.type.model() + : null; + } +} diff --git a/src/main/java/io/wispforest/outthedoor/client/OutTheDoorClient.java b/src/main/java/io/wispforest/outthedoor/client/OutTheDoorClient.java new file mode 100644 index 0000000..00ddc06 --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/client/OutTheDoorClient.java @@ -0,0 +1,29 @@ +package io.wispforest.outthedoor.client; + +import io.wispforest.outthedoor.OutTheDoor; +import io.wispforest.outthedoor.client.model.BackpackModel; +import io.wispforest.outthedoor.client.model.BackpackUnbakedModel; +import io.wispforest.outthedoor.object.OutTheDoorBlocks; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; +import net.minecraft.client.render.RenderLayer; + +@Environment(EnvType.CLIENT) +public class OutTheDoorClient implements ClientModInitializer { + + @Override + public void onInitializeClient() { + BlockRenderLayerMap.INSTANCE.putBlock(OutTheDoorBlocks.BACKPACK, RenderLayer.getCutout()); + + ModelLoadingRegistry.INSTANCE.registerResourceProvider(resourceManager -> (resourceId, context) -> { + if (resourceId.equals(OutTheDoor.id("block/backpack"))) { + return new BackpackUnbakedModel(); + } else { + return null; + } + }); + } +} diff --git a/src/main/java/io/wispforest/outthedoor/client/model/BackpackModel.java b/src/main/java/io/wispforest/outthedoor/client/model/BackpackModel.java new file mode 100644 index 0000000..7973d69 --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/client/model/BackpackModel.java @@ -0,0 +1,87 @@ +package io.wispforest.outthedoor.client.model; + +import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.BakedQuad; +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.item.ItemStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.random.Random; +import net.minecraft.world.BlockRenderView; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +public class BackpackModel implements BakedModel, FabricBakedModel { + + private final Map backpackModels; + + public BackpackModel(Map backpackModels) { + this.backpackModels = backpackModels; + } + + @Override + public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + var modelId = (Identifier) ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos); + if (modelId == null) return; + + ((FabricBakedModel) this.backpackModels.get(modelId)).emitBlockQuads(blockView, state, pos, randomSupplier, context); + } + + @Override + public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) {} + + @Override + public List getQuads(@Nullable BlockState state, @Nullable Direction face, Random random) { + return List.of(); + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public boolean useAmbientOcclusion() { + return false; + } + + @Override + public boolean hasDepth() { + return true; + } + + @Override + public boolean isSideLit() { + return true; + } + + @Override + public boolean isBuiltin() { + return false; + } + + @Override + public Sprite getParticleSprite() { + return this.backpackModels.values().iterator().next().getParticleSprite(); + } + + @Override + public ModelTransformation getTransformation() { + return null; + } + + @Override + public ModelOverrideList getOverrides() { + return ModelOverrideList.EMPTY; + } +} diff --git a/src/main/java/io/wispforest/outthedoor/client/model/BackpackUnbakedModel.java b/src/main/java/io/wispforest/outthedoor/client/model/BackpackUnbakedModel.java new file mode 100644 index 0000000..6635aaa --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/client/model/BackpackUnbakedModel.java @@ -0,0 +1,45 @@ +package io.wispforest.outthedoor.client.model; + +import com.google.common.collect.ImmutableMap; +import io.wispforest.outthedoor.OutTheDoor; +import io.wispforest.outthedoor.misc.BackpackType; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.Baker; +import net.minecraft.client.render.model.ModelBakeSettings; +import net.minecraft.client.render.model.UnbakedModel; +import net.minecraft.client.texture.Sprite; +import net.minecraft.client.util.SpriteIdentifier; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.function.Function; + +public class BackpackUnbakedModel implements UnbakedModel { + + @Override + public Collection getModelDependencies() { + return OutTheDoor.BACKPACK_REGISTRY.stream().map(BackpackType::model).toList(); + } + + @Override + public void setParents(Function modelLoader) { + OutTheDoor.BACKPACK_REGISTRY.stream().map(BackpackType::model).forEach(identifier -> { + modelLoader.apply(identifier).setParents(modelLoader); + }); + } + + @Nullable + @Override + @SuppressWarnings("DataFlowIssue") + public BakedModel bake(Baker baker, Function textureGetter, ModelBakeSettings bakeSettings, Identifier modelId) { + var models = ImmutableMap.builder(); + + for (var backpackType : OutTheDoor.BACKPACK_REGISTRY) { + models.put(backpackType.model(), baker.bake(backpackType.model(), bakeSettings)); + } + + return new BackpackModel(models.build()); + } + +} diff --git a/src/main/java/io/wispforest/outthedoor/item/BackpackItem.java b/src/main/java/io/wispforest/outthedoor/item/BackpackItem.java new file mode 100644 index 0000000..12f3a03 --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/item/BackpackItem.java @@ -0,0 +1,57 @@ +package io.wispforest.outthedoor.item; + +import io.wispforest.outthedoor.OutTheDoor; +import io.wispforest.outthedoor.block.BackpackBlockEntity; +import io.wispforest.outthedoor.misc.BackpackType; +import io.wispforest.outthedoor.object.OutTheDoorBlocks; +import io.wispforest.owo.itemgroup.OwoItemSettings; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Util; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +public class BackpackItem extends BlockItem { + + public final BackpackType type; + + public BackpackItem(BackpackType type) { + super( + OutTheDoorBlocks.BACKPACK, + new OwoItemSettings().group(OutTheDoor.GROUP).maxCount(1) + ); + + this.type = type; + } + + @Override + public String getTranslationKey() { + return this.getOrCreateTranslationKey(); + } + + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + if (!context.getPlayer().isSneaking()) { + return ActionResult.PASS; + } else { + return super.useOnBlock(context); + } + } + + @Override + protected boolean postPlacement(BlockPos pos, World world, @Nullable PlayerEntity player, ItemStack stack, BlockState state) { + super.postPlacement(pos, world, player, stack, state); + + if (world.getBlockEntity(pos) instanceof BackpackBlockEntity backpack) { + backpack.backpack = stack.copy(); + } + + return true; + } +} diff --git a/src/main/java/io/wispforest/outthedoor/misc/BackpackType.java b/src/main/java/io/wispforest/outthedoor/misc/BackpackType.java new file mode 100644 index 0000000..7fd58bf --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/misc/BackpackType.java @@ -0,0 +1,8 @@ +package io.wispforest.outthedoor.misc; + +import net.minecraft.util.Identifier; + +public interface BackpackType { + String name(); + Identifier model(); +} diff --git a/src/main/java/io/wispforest/outthedoor/object/OutTheDoorBackpackTypes.java b/src/main/java/io/wispforest/outthedoor/object/OutTheDoorBackpackTypes.java new file mode 100644 index 0000000..8e28a0f --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/object/OutTheDoorBackpackTypes.java @@ -0,0 +1,26 @@ +package io.wispforest.outthedoor.object; + +import io.wispforest.outthedoor.OutTheDoor; +import io.wispforest.outthedoor.misc.BackpackType; +import io.wispforest.owo.registration.reflect.AutoRegistryContainer; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class OutTheDoorBackpackTypes implements AutoRegistryContainer { + + public static final BackpackType LEATHER = new Type("leather", OutTheDoor.id("item/leather_backpack")); + public static final BackpackType HIDE = new Type("hide", OutTheDoor.id("item/hide_backpack")); + public static final BackpackType PUMPKIN = new Type("pumpkin", OutTheDoor.id("item/pumpkin_backpack")); + + @Override + public Registry getRegistry() { + return OutTheDoor.BACKPACK_REGISTRY; + } + + @Override + public Class getTargetFieldType() { + return BackpackType.class; + } + + public record Type(String name, Identifier model) implements BackpackType {} +} diff --git a/src/main/java/io/wispforest/outthedoor/object/OutTheDoorBlocks.java b/src/main/java/io/wispforest/outthedoor/object/OutTheDoorBlocks.java new file mode 100644 index 0000000..17632b6 --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/object/OutTheDoorBlocks.java @@ -0,0 +1,21 @@ +package io.wispforest.outthedoor.object; + +import io.wispforest.outthedoor.block.BackpackBlock; +import io.wispforest.outthedoor.block.BackpackBlockEntity; +import io.wispforest.owo.registration.reflect.BlockEntityRegistryContainer; +import io.wispforest.owo.registration.reflect.BlockRegistryContainer; +import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; +import net.minecraft.block.Block; +import net.minecraft.block.entity.BlockEntityType; + +public class OutTheDoorBlocks implements BlockRegistryContainer { + + public static final Block BACKPACK = new BackpackBlock(); + + public static class Entities implements BlockEntityRegistryContainer { + + public static final BlockEntityType BACKPACK + = FabricBlockEntityTypeBuilder.create(BackpackBlockEntity::new, OutTheDoorBlocks.BACKPACK).build(); + + } +} diff --git a/src/main/java/io/wispforest/outthedoor/object/OutTheDoorItems.java b/src/main/java/io/wispforest/outthedoor/object/OutTheDoorItems.java new file mode 100644 index 0000000..dd51b1c --- /dev/null +++ b/src/main/java/io/wispforest/outthedoor/object/OutTheDoorItems.java @@ -0,0 +1,13 @@ +package io.wispforest.outthedoor.object; + +import io.wispforest.outthedoor.item.BackpackItem; +import io.wispforest.owo.registration.reflect.ItemRegistryContainer; +import net.minecraft.item.Item; + +public class OutTheDoorItems implements ItemRegistryContainer { + + public static final Item LEATHER_BACKPACK = new BackpackItem(OutTheDoorBackpackTypes.LEATHER); + public static final Item HIDE_BACKPACK = new BackpackItem(OutTheDoorBackpackTypes.HIDE); + public static final Item PUMPKIN_BACKPACK = new BackpackItem(OutTheDoorBackpackTypes.PUMPKIN); + +} diff --git a/src/main/resources/assets/out-the-door/blockstates/backpack.json b/src/main/resources/assets/out-the-door/blockstates/backpack.json new file mode 100644 index 0000000..b8e39e6 --- /dev/null +++ b/src/main/resources/assets/out-the-door/blockstates/backpack.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=north": { + "model": "out-the-door:block/backpack", + "y": 90 + }, + "facing=south": { + "model": "out-the-door:block/backpack", + "y": -90 + }, + "facing=west": { + "model": "out-the-door:block/backpack" + }, + "facing=east": { + "model": "out-the-door:block/backpack", + "y": 180 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/out-the-door/lang/en_us.json b/src/main/resources/assets/out-the-door/lang/en_us.json new file mode 100644 index 0000000..6ef0ea9 --- /dev/null +++ b/src/main/resources/assets/out-the-door/lang/en_us.json @@ -0,0 +1,7 @@ +{ + "itemGroup.out-the-door.out-the-door": "Out the Door", + + "item.out-the-door.leather_backpack": "Leather Backpack", + "item.out-the-door.hide_backpack": "Hide Backpack", + "item.out-the-door.pumpkin_backpack": "Pumpkin Backpack" +} \ No newline at end of file diff --git a/src/main/resources/assets/out-the-door/models/item/backpack.json b/src/main/resources/assets/out-the-door/models/item/backpack.json new file mode 100644 index 0000000..fa67583 --- /dev/null +++ b/src/main/resources/assets/out-the-door/models/item/backpack.json @@ -0,0 +1,123 @@ +{ + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "elements": [ + { + "from": [5.5, -0.25, 4.5], + "to": [9.5, 8.75, 11.5], + "rotation": {"angle": 0, "axis": "y", "origin": [7.75, 11.75, 8]}, + "faces": { + "north": {"uv": [2, 5, 0, 9.5], "texture": "#1"}, + "east": {"uv": [3.5, 11.5, 7, 16], "texture": "#1"}, + "south": {"uv": [0, 5, 2, 9.5], "texture": "#1"}, + "west": {"uv": [0, 11.5, 3.5, 16], "texture": "#1"}, + "up": {"uv": [3.5, 9.5, 0, 11.5], "rotation": 90, "texture": "#1"}, + "down": {"uv": [7, 11.5, 3.5, 9.5], "rotation": 90, "texture": "#1"} + } + }, + { + "from": [9.5, -0.25, 4.5], + "to": [10.5, 8.75, 11.5], + "rotation": {"angle": 0, "axis": "y", "origin": [7.75, 11.75, 8]}, + "faces": { + "east": {"uv": [0, 0, 3.5, 4.5], "texture": "#1"}, + "up": {"uv": [3.5, 0.5, 0, 0], "rotation": 90, "texture": "#1"}, + "down": {"uv": [0, 4.5, 3.5, 4], "rotation": 90, "texture": "#1"} + } + }, + { + "from": [9.5, 8.75, 4.5], + "to": [10.5, -0.25, 11.5], + "rotation": {"angle": 0, "axis": "y", "origin": [7.75, 11.75, 8]}, + "faces": { + "east": {"uv": [0, 0, 3.5, 4.5], "texture": "#1"}, + "up": {"uv": [0, 4, 3.5, 4.5], "rotation": 90, "texture": "#1"}, + "down": {"uv": [0, 0, 3.5, 0.5], "rotation": 90, "texture": "#1"} + } + }, + { + "from": [6.5, -0.25, 3.5], + "to": [9.5, 4.75, 12.5], + "rotation": {"angle": 0, "axis": "y", "origin": [7.75, 11.75, 8]}, + "faces": { + "north": {"uv": [2, 7, 3.5, 9.5], "texture": "#1"}, + "east": {"uv": [7, 11, 11.5, 13.5], "texture": "#1"}, + "south": {"uv": [3.5, 7, 2, 9.5], "texture": "#1"}, + "west": {"uv": [7, 13.5, 11.5, 16], "texture": "#1"}, + "up": {"uv": [4, 6.5, 8.5, 8], "rotation": 90, "texture": "#1"}, + "down": {"uv": [4, 9.5, 8.5, 8], "rotation": 90, "texture": "#1"} + } + }, + { + "from": [8.5, -0.25, 2.5], + "to": [8.5, 11.75, 13.5], + "rotation": {"angle": 0, "axis": "y", "origin": [7.75, 11.75, 8]}, + "faces": { + "north": {"uv": [0, 0, 0, 0], "texture": "#1"}, + "east": {"uv": [9, 0, 3.5, 6], "texture": "#1"}, + "south": {"uv": [0, 0, 0, 0], "texture": "#1"}, + "west": {"uv": [3.5, 0, 9, 6], "texture": "#1"}, + "up": {"uv": [0, 0, 0, 0], "texture": "#1"}, + "down": {"uv": [0, 0, 0, 0], "texture": "#1"} + } + }, + { + "from": [5.5, 5.75, 4.5], + "to": [6.5, 4.75, 11.5], + "rotation": {"angle": 0, "axis": "y", "origin": [7.75, 11.75, 8]}, + "faces": { + "east": {"uv": [3.5, 13.5, 7, 14], "texture": "#1"}, + "up": {"uv": [0, 13.5, 3.5, 14], "rotation": 90, "texture": "#1"}, + "down": {"uv": [0, 10, 3.5, 10.5], "rotation": 90, "texture": "#1"} + } + } + ], + "display": { + "thirdperson_righthand": { + "rotation": [70, -90, 0], + "translation": [0, -2.25, -2.25], + "scale": [0.85, 0.85, 0.85] + }, + "thirdperson_lefthand": { + "rotation": [-112.5, 90, -180], + "translation": [0, -2.5, -2.25], + "scale": [0.85, 0.85, 0.85] + }, + "firstperson_righthand": { + "rotation": [0, 90, 0], + "translation": [0, 3, 0], + "scale": [0.68, 0.68, 0.68] + }, + "firstperson_lefthand": { + "rotation": [0, -90, 0], + "translation": [0, 3, 0], + "scale": [0.68, 0.68, 0.68] + }, + "ground": { + "translation": [0, 2, 0], + "scale": [0.5, 0.5, 0.5] + }, + "gui": { + "rotation": [30, 135, 0], + "translation": [0, 2, 0], + "scale": [0.625, 0.625, 0.625] + }, + "head": { + "rotation": [0, -90, 0], + "translation": [0, 18.75, 2.5], + "scale": [1.5, 1.5, 1.5] + }, + "fixed": { + "rotation": [0, -90, 0], + "translation": [0, 3, 0] + } + }, + "groups": [ + { + "name": "bone2", + "origin": [7.5, 11.5, 14], + "color": 0, + "children": [0, 1, 2, 3, 4, 5] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/out-the-door/models/item/hide_backpack.json b/src/main/resources/assets/out-the-door/models/item/hide_backpack.json new file mode 100644 index 0000000..68a326f --- /dev/null +++ b/src/main/resources/assets/out-the-door/models/item/hide_backpack.json @@ -0,0 +1,7 @@ +{ + "parent": "out-the-door:item/backpack", + "textures": { + "1": "out-the-door:item/hide_backpack", + "particle": "out-the-door:item/hide_backpack" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/out-the-door/models/item/leather_backpack.json b/src/main/resources/assets/out-the-door/models/item/leather_backpack.json new file mode 100644 index 0000000..6ec2360 --- /dev/null +++ b/src/main/resources/assets/out-the-door/models/item/leather_backpack.json @@ -0,0 +1,7 @@ +{ + "parent": "out-the-door:item/backpack", + "textures": { + "1": "out-the-door:item/leather_backpack", + "particle": "out-the-door:item/leather_backpack" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/out-the-door/models/item/pumpkin_backpack.json b/src/main/resources/assets/out-the-door/models/item/pumpkin_backpack.json new file mode 100644 index 0000000..85561a6 --- /dev/null +++ b/src/main/resources/assets/out-the-door/models/item/pumpkin_backpack.json @@ -0,0 +1,7 @@ +{ + "parent": "out-the-door:item/backpack", + "textures": { + "1": "out-the-door:item/pumpkin_backpack", + "particle": "out-the-door:item/pumpkin_backpack" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/out-the-door/textures/item/hide_backpack.png b/src/main/resources/assets/out-the-door/textures/item/hide_backpack.png new file mode 100644 index 0000000..bfea69f Binary files /dev/null and b/src/main/resources/assets/out-the-door/textures/item/hide_backpack.png differ diff --git a/src/main/resources/assets/out-the-door/textures/item/leather_backpack.png b/src/main/resources/assets/out-the-door/textures/item/leather_backpack.png new file mode 100644 index 0000000..1e25c0b Binary files /dev/null and b/src/main/resources/assets/out-the-door/textures/item/leather_backpack.png differ diff --git a/src/main/resources/assets/out-the-door/textures/item/pumpkin_backpack.png b/src/main/resources/assets/out-the-door/textures/item/pumpkin_backpack.png new file mode 100644 index 0000000..35aaf92 Binary files /dev/null and b/src/main/resources/assets/out-the-door/textures/item/pumpkin_backpack.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..6e96467 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,26 @@ +{ + "schemaVersion": 1, + "id": "out-the-door", + "version": "${version}", + + "name": "Out The Door", + "description": "", + "authors": [], + "contact": {}, + + "license": "MIT", + "icon": "assets/out-the-door/icon.png", + + "environment": "*", + "entrypoints": {"client": ["io.wispforest.outthedoor.client.OutTheDoorClient"], "main": ["io.wispforest.outthedoor.OutTheDoor"]}, + + "mixins": [ + "out-the-door.mixins.json" + ], + + "depends": { + "fabricloader": ">=0.14.13", + "fabric": "*", + "minecraft": "1.19.3" + } +} diff --git a/src/main/resources/out-the-door.mixins.json b/src/main/resources/out-the-door.mixins.json new file mode 100644 index 0000000..20e701c --- /dev/null +++ b/src/main/resources/out-the-door.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "io.wispforest.outthedoor.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +}