Initial commit (basic Chiseled Bookshelf functionality)

This commit is contained in:
core 2023-08-04 21:40:11 -04:00
commit c29ba1f7e2
Signed by: core
GPG Key ID: FDBF740DADDCEECF
45 changed files with 2003 additions and 0 deletions

40
.gitignore vendored Normal file
View File

@ -0,0 +1,40 @@
# gradle
.gradle/
build/
out/
classes/
# eclipse
*.launch
# idea
.idea/
*.iml
*.ipr
*.iws
# vscode
.settings/
.vscode/
bin/
.classpath
.project
# macos
*.DS_Store
# fabric
run/
# java
hs_err_*.log
replay_*.log
*.hprof
*.jfr

80
build.gradle Normal file
View File

@ -0,0 +1,80 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}
version = project.mod_version
group = project.maven_group
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.
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
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_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}
base {
archivesName = project.archives_base_name
}
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()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}"}
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
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.
}
}

17
gradle.properties Normal file
View File

@ -0,0 +1,17 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.22
# Mod Properties
mod_version = 1.0.0
maven_group = dev.coredoes
archives_base_name = cherrybackports
# Dependencies
fabric_version=0.76.0+1.19.2

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

245
gradlew vendored Executable file
View File

@ -0,0 +1,245 @@
#!/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/HEAD/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
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# 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*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
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
# 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"'
# 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 \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# 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" "$@"

92
gradlew.bat vendored Normal file
View File

@ -0,0 +1,92 @@
@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=.
@rem This is normally unused
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% equ 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% equ 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!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

10
settings.gradle Normal file
View File

@ -0,0 +1,10 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}

View File

@ -0,0 +1,41 @@
package dev.coredoes.cherrybackports;
import dev.coredoes.cherrybackports.block.ChiseledBookshelfBlock;
import dev.coredoes.cherrybackports.blockentity.ChiseledBookshelfBlockEntity;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CherryBackports implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("cherrybackports");
public static final Block CHISELED_BOOKSHELF_BLOCK = new ChiseledBookshelfBlock(
FabricBlockSettings.of(Material.WOOD)
.strength(1.5f)
.requiresTool()
);
public static final BlockEntityType<ChiseledBookshelfBlockEntity> CHISELED_BOOKSHELF_BLOCK_ENTITY = Registry.register(
Registry.BLOCK_ENTITY_TYPE,
new Identifier("cherrybackports", "chiseled_bookshelf_block_entity"),
FabricBlockEntityTypeBuilder.create(ChiseledBookshelfBlockEntity::new, CHISELED_BOOKSHELF_BLOCK).build()
);
@Override
public void onInitialize() {
LOGGER.info("-=- Cherry Backports -=-");
Registry.register(Registry.BLOCK, new Identifier("cherrybackports", "chiseled_bookshelf"), CHISELED_BOOKSHELF_BLOCK);
Registry.register(Registry.ITEM, new Identifier("cherrybackports", "chiseled_bookshelf"), new BlockItem(CHISELED_BOOKSHELF_BLOCK, new Item.Settings().group(ItemGroup.BUILDING_BLOCKS)));
}
}

View File

@ -0,0 +1,149 @@
package dev.coredoes.cherrybackports.block;
import dev.coredoes.cherrybackports.blockentity.ChiseledBookshelfBlockEntity;
import dev.coredoes.cherrybackports.util.ItemCommonTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Objects;
public class ChiseledBookshelfBlock extends Block implements BlockEntityProvider {
public static final BooleanProperty SLOT_0_OCCUPIED = BooleanProperty.of("slot_0_occupied");
public static final BooleanProperty SLOT_1_OCCUPIED = BooleanProperty.of("slot_1_occupied");
public static final BooleanProperty SLOT_2_OCCUPIED = BooleanProperty.of("slot_2_occupied");
public static final BooleanProperty SLOT_3_OCCUPIED = BooleanProperty.of("slot_3_occupied");
public static final BooleanProperty SLOT_4_OCCUPIED = BooleanProperty.of("slot_4_occupied");
public static final BooleanProperty SLOT_5_OCCUPIED = BooleanProperty.of("slot_5_occupied");
public ChiseledBookshelfBlock(Settings settings) {
super(settings);
setDefaultState(
getDefaultState()
.with(SLOT_0_OCCUPIED, false)
.with(SLOT_1_OCCUPIED, false)
.with(SLOT_2_OCCUPIED, false)
.with(SLOT_3_OCCUPIED, false)
.with(SLOT_4_OCCUPIED, false)
.with(SLOT_5_OCCUPIED, false)
.with(Properties.FACING, Direction.NORTH)
);
}
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
if (!world.isClient) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof ChiseledBookshelfBlockEntity) {
ItemScatterer.spawn(world, pos, ((ChiseledBookshelfBlockEntity) blockEntity).getInvStackList());
// update comparators
world.updateComparators(pos, this);
}
super.onBreak(world, pos, state, player);
}
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
if (!world.isClient) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof ChiseledBookshelfBlockEntity entity) {
if (player.isSneaking()) {
// remove
if (entity.canRemoveItem()) {
ItemStack item = entity.removeItem();
// add it to the player's inventory
if (player.getStackInHand(hand) == ItemStack.EMPTY) {
player.setStackInHand(hand, item);
updateBlockState(world, pos, state, entity);
return ActionResult.SUCCESS;
} else {
player.getInventory().insertStack(item);
updateBlockState(world, pos, state, entity);
return ActionResult.SUCCESS;
}
}
} else {
// add
ItemStack handStack = player.getStackInHand(hand);
boolean is_book = handStack.isIn(ItemCommonTags.BOOKS);
if (is_book) {
if (!entity.canAddItem()) {
return ActionResult.FAIL;
}
entity.addItem(handStack);
player.setStackInHand(hand, ItemStack.EMPTY);
updateBlockState(world, pos, state, entity);
return ActionResult.SUCCESS;
} else {
return ActionResult.FAIL;
}
}
}
}
return ActionResult.PASS;
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new ChiseledBookshelfBlockEntity(pos, state);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(SLOT_0_OCCUPIED);
builder.add(SLOT_1_OCCUPIED);
builder.add(SLOT_2_OCCUPIED);
builder.add(SLOT_3_OCCUPIED);
builder.add(SLOT_4_OCCUPIED);
builder.add(SLOT_5_OCCUPIED);
builder.add(Properties.FACING);
}
private void updateBlockState(World world, BlockPos pos, BlockState state, ChiseledBookshelfBlockEntity entity) {
world.setBlockState(pos, state
.with(SLOT_0_OCCUPIED, entity.isSlotOccupied(0))
.with(SLOT_1_OCCUPIED, entity.isSlotOccupied(1))
.with(SLOT_2_OCCUPIED, entity.isSlotOccupied(2))
.with(SLOT_3_OCCUPIED, entity.isSlotOccupied(3))
.with(SLOT_4_OCCUPIED, entity.isSlotOccupied(4))
.with(SLOT_5_OCCUPIED, entity.isSlotOccupied(5))
);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return Objects.requireNonNull(super.getPlacementState(ctx))
.with(Properties.FACING, ctx.getPlayerFacing().getOpposite())
.with(SLOT_0_OCCUPIED, false)
.with(SLOT_1_OCCUPIED, false)
.with(SLOT_2_OCCUPIED, false)
.with(SLOT_3_OCCUPIED, false)
.with(SLOT_4_OCCUPIED, false)
.with(SLOT_5_OCCUPIED, false);
}
}

View File

@ -0,0 +1,92 @@
package dev.coredoes.cherrybackports.blockentity;
import dev.coredoes.cherrybackports.CherryBackports;
import dev.coredoes.cherrybackports.block.ChiseledBookshelfBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
public class ChiseledBookshelfBlockEntity extends BlockEntity {
private int last_interacted_slot = -1;
private DefaultedList<ItemStack> inventory;
private int used_slots = 0;
private final int max_slots = 6;
public ChiseledBookshelfBlockEntity(BlockPos pos, BlockState state) {
super(CherryBackports.CHISELED_BOOKSHELF_BLOCK_ENTITY, pos, state);
inventory = DefaultedList.ofSize(6, ItemStack.EMPTY);
}
public DefaultedList<ItemStack> getInvStackList() {
return this.inventory;
}
public boolean canRemoveItem() {
return used_slots != 0;
}
public boolean canAddItem() {
return used_slots != max_slots;
}
public boolean addItem(ItemStack item) {
if (!canAddItem()) return false;
inventory.set(used_slots, item);
used_slots++;
return true;
}
public ItemStack removeItem() {
if (!canRemoveItem()) return ItemStack.EMPTY;
used_slots--;
// get the item
ItemStack stack = inventory.get(used_slots);
// erase it
inventory.set(used_slots, ItemStack.EMPTY);
// return it
return stack;
}
public boolean isSlotOccupied(int slot) {
if (slot < 0 || slot > 5) return false;
return inventory.get(slot) != ItemStack.EMPTY;
}
@Override
public void readNbt(NbtCompound tag) {
super.readNbt(tag);
this.inventory = DefaultedList.ofSize(max_slots, ItemStack.EMPTY);
Inventories.readNbt(tag, this.inventory);
this.last_interacted_slot = tag.getInt("last_interacted_slot");
// load the used_slots field
for (ItemStack item : this.inventory) {
if (item != ItemStack.EMPTY) {
used_slots++;
}
}
}
@Override
public void writeNbt(NbtCompound tag) {
Inventories.writeNbt(tag, this.inventory);
tag.putInt("last_interacted_slot", this.last_interacted_slot);
super.writeNbt(tag);
}
}

View File

@ -0,0 +1,10 @@
package dev.coredoes.cherrybackports.util;
import net.minecraft.item.Item;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class ItemCommonTags {
public static final TagKey<Item> BOOKS = TagKey.of(Registry.ITEM_KEY, new Identifier("c", "books"));
}

View File

@ -0,0 +1,812 @@
{
"multipart": [
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf",
"uvlock": true,
"y": 90
},
"when": {
"facing": "east"
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_right",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_2_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_right",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_2_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_mid",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_4_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_mid",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_4_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_left",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_0_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_left",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_0_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_right",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_5_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_right",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_5_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_left",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_3_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_left",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_3_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_mid",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_1_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_mid",
"y": 90
},
"when": {
"AND": [
{
"facing": "east"
},
{
"slot_1_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf",
"uvlock": true,
"y": 270
},
"when": {
"facing": "west"
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_right",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_2_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_right",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_2_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_mid",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_4_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_mid",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_4_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_left",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_0_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_left",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_0_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_right",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_5_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_right",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_5_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_left",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_3_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_left",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_3_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_mid",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_1_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_mid",
"y": 270
},
"when": {
"AND": [
{
"facing": "west"
},
{
"slot_1_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf",
"uvlock": true,
"y": 180
},
"when": {
"facing": "south"
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_right",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_2_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_right",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_2_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_mid",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_4_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_mid",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_4_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_left",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_0_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_left",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_0_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_right",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_5_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_right",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_5_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_left",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_3_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_left",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_3_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_mid",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_1_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_mid",
"y": 180
},
"when": {
"AND": [
{
"facing": "south"
},
{
"slot_1_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf",
"uvlock": true,
"y": 0
},
"when": {
"facing": "north"
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_right",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_2_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_right",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_2_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_mid",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_4_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_mid",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_4_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_left",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_0_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_left",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_0_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_right",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_5_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_right",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_5_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_bottom_left",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_3_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_bottom_left",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_3_occupied": "false"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_occupied_slot_top_mid",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_1_occupied": "true"
}
]
}
},
{
"apply": {
"model": "cherrybackports:block/chiseled_bookshelf_empty_slot_top_mid",
"y": 0
},
"when": {
"AND": [
{
"facing": "north"
},
{
"slot_1_occupied": "false"
}
]
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,22 @@
{
"parent": "block/block",
"textures": {
"top": "cherrybackports:block/chiseled_bookshelf_top",
"side": "cherrybackports:block/chiseled_bookshelf_side",
"particle": "#top"
},
"elements": [
{
"name": "chiseled_bookshelf_body",
"from": [0, 0, 0],
"to": [16, 16, 16],
"faces": {
"east": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "east"},
"south": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "south"},
"west": {"uv": [0, 0, 16, 16], "texture": "#side", "cullface": "west"},
"up": {"uv": [0, 0, 16, 16], "texture": "#top", "cullface": "up"},
"down": {"uv": [0, 0, 16, 16], "texture": "#top", "cullface": "down"}
}
}
]
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_bottom_left",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_empty"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_bottom_mid",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_empty"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_bottom_right",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_empty"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_top_left",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_empty"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_top_mid",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_empty"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_top_right",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_empty"
}
}

View File

@ -0,0 +1,24 @@
{
"parent": "block/block",
"textures": {
"top": "block/chiseled_bookshelf_top",
"side": "block/chiseled_bookshelf_side",
"front": "block/chiseled_bookshelf_empty",
"particle": "#top"
},
"elements": [
{
"name": "chiseled_bookshelf_body",
"from": [0, 0, 0],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#front"},
"east": {"uv": [0, 0, 16, 16], "texture": "#side"},
"south": {"uv": [0, 0, 16, 16], "texture": "#side"},
"west": {"uv": [0, 0, 16, 16], "texture": "#side"},
"up": {"uv": [0, 0, 16, 16], "texture": "#top"},
"down": {"uv": [0, 0, 16, 16], "texture": "#top"}
}
}
]
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_bottom_left",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_occupied"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_bottom_mid",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_occupied"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_bottom_right",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_occupied"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_top_left",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_occupied"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_top_mid",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_occupied"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "cherrybackports:block/template_chiseled_bookshelf_slot_top_right",
"textures": {
"texture": "cherrybackports:block/chiseled_bookshelf_occupied"
}
}

View File

@ -0,0 +1,31 @@
{
"textures": {
"texture": "#texture"
},
"elements": [
{
"from": [
10,
0,
0
],
"to": [
16,
8,
0
],
"faces": {
"north": {
"uv": [
0,
8,
6,
16
],
"texture": "#texture",
"cullface": "north"
}
}
}
]
}

View File

@ -0,0 +1,31 @@
{
"textures": {
"texture": "#texture"
},
"elements": [
{
"from": [
5,
0,
0
],
"to": [
10,
8,
0
],
"faces": {
"north": {
"uv": [
6,
8,
11,
16
],
"texture": "#texture",
"cullface": "north"
}
}
}
]
}

View File

@ -0,0 +1,31 @@
{
"textures": {
"texture": "#texture"
},
"elements": [
{
"from": [
0,
0,
0
],
"to": [
5,
8,
0
],
"faces": {
"north": {
"uv": [
11,
8,
16,
16
],
"texture": "#texture",
"cullface": "north"
}
}
}
]
}

View File

@ -0,0 +1,31 @@
{
"textures": {
"texture": "#texture"
},
"elements": [
{
"from": [
10,
8,
0
],
"to": [
16,
16,
0
],
"faces": {
"north": {
"uv": [
0,
0,
6,
8
],
"texture": "#texture",
"cullface": "north"
}
}
}
]
}

View File

@ -0,0 +1,31 @@
{
"textures": {
"texture": "#texture"
},
"elements": [
{
"from": [
5,
8,
0
],
"to": [
10,
16,
0
],
"faces": {
"north": {
"uv": [
6,
0,
11,
8
],
"texture": "#texture",
"cullface": "north"
}
}
}
]
}

View File

@ -0,0 +1,31 @@
{
"textures": {
"texture": "#texture"
},
"elements": [
{
"from": [
0,
8,
0
],
"to": [
5,
16,
0
],
"faces": {
"north": {
"uv": [
11,
0,
16,
8
],
"texture": "#texture",
"cullface": "north"
}
}
}
]
}

View File

@ -0,0 +1,3 @@
{
"parent": "cherrybackports:block/chiseled_bookshelf"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

View File

@ -0,0 +1,13 @@
{
"required": true,
"minVersion": "0.8",
"package": "dev.coredoes.cherrybackports.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@ -0,0 +1,10 @@
{
"replace": false,
"values": [
"minecraft:book",
"minecraft:enchanted_book",
"minecraft:knowledge_book",
"minecraft:writable_book",
"minecraft:written_book"
]
}

View File

@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "cherrybackports:chiseled_bookshelf"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View File

@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"SSS",
"PPP"
],
"key": {
"P": {
"tag": "minecraft:planks"
},
"S": {
"tag": "minecraft:wooden_slabs"
}
},
"result": {
"item": "cherrybackports:chiseled_bookshelf"
}
}

View File

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"cherrybackports:chiseled_bookshelf"
]
}

View File

@ -0,0 +1,35 @@
{
"schemaVersion": 1,
"id": "cherrybackports",
"version": "${version}",
"name": "Cherry Backports",
"description": "A mod backporting 1.20 blocks and features to 1.19.2 so we can play with them",
"authors": [
"c0repwn3r"
],
"contact": {
"homepage": "https://coredoes.dev/cherrybackports",
"sources": "https://git.e3t.cc/~core/cherrybackports"
},
"license": "Proprietary",
"icon": "assets/cherrybackports/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"dev.coredoes.cherrybackports.CherryBackports"
]
},
"mixins": [
"cherrybackports.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.22",
"fabric-api": "*",
"minecraft": "~1.19.2",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
}
}