This commit is contained in:
commit
c4a2e8e529
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
# gradle
|
||||
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
|
||||
# eclipse
|
||||
|
||||
*.launch
|
||||
|
||||
# idea
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# vscode
|
||||
|
||||
.settings/
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# fabric
|
||||
|
||||
run/
|
19
Jenkinsfile
vendored
Normal file
19
Jenkinsfile
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'openjdk:8-jdk'
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh './gradlew build'
|
||||
}
|
||||
post {
|
||||
success {
|
||||
archiveArtifacts artifacts: 'build/libs/*', fingerprint: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 TheBrokenRail
|
||||
|
||||
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.
|
49
README.md
Normal file
49
README.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Twine
|
||||
A simple survival mod for Minecraft encouraging a nomadic lifestyle.
|
||||
|
||||
## Backpacks
|
||||
A backpack can only hold one type of item or only hold unstackable items.
|
||||
|
||||
### Small Backpack Recipe
|
||||
<table>
|
||||
<tr><th>Stick</th><th>Leather</th><th>Stick</th></tr>
|
||||
<tr><th>Leather</th><th>Iron Ingot</th><th>Leather</th></tr>
|
||||
<tr><th>Stick</th><th>Leather</th><th>Stick</th></tr>
|
||||
</table>
|
||||
|
||||
### Large Backpack Recipe
|
||||
Combine a Small Backpack with a Gold Ingot in the Smithing Table.
|
||||
|
||||
### Dye Backpack Recipe
|
||||
Combine a Backpack with a dye in the Crafting Table.
|
||||
|
||||
## Glowing Obsidian
|
||||
Glowing Obsidian heals monsters and hurts everything else. It naturally generates in small patches underground.
|
||||
|
||||
### Recipe
|
||||
<table>
|
||||
<tr><th></th><th>Redstone</th><th></th></tr>
|
||||
<tr><th>Redstone</th><th>Obsidian</th><th>Redstone</th></tr>
|
||||
<tr><th></th><th>Redstone</th><th></th></tr>
|
||||
</table>
|
||||
|
||||
## Difficulty Stages
|
||||
|
||||
### Stage 1
|
||||
- Normal Gameplay
|
||||
|
||||
### Stage 2
|
||||
|
||||
### Stage 3
|
||||
- Hostile Mobs Attack Passive Mobs
|
||||
|
||||
### Stage 4
|
||||
- Villages Kick You Out (Using Iron Golems)
|
||||
|
||||
### Stage 5
|
||||
- Neural Mobs Are Always Hostile
|
||||
|
||||
### Stage 6
|
||||
|
||||
### Technical Details
|
||||
Each player has a 6-element long list in their data. Each element in the list has a chunk position and time value. Every tick the player will first, find the stage element its current position is in, and increase the time value of that stage element. If the time value when increased is over 24,000 ticks the next stage element will have its chunk set to the players current position, have its time value reset, the old stage element will have the next stage element's old chunk, and have its time value reset. To determine if a player is in a stage element, it checks if the player is within 16 chunks of the stage element's chunk, it starts searching at the last element, ending at the first. The "global" stage element of a chunk can be found by searching every player for their stage element for the chunk and then picking the highest value.
|
76
build.gradle
Normal file
76
build.gradle
Normal file
@ -0,0 +1,76 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.4-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "Ladysnake Libs"
|
||||
url = 'https://dl.bintray.com/ladysnake/libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier "sources"
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url "/data/maven"
|
||||
}
|
||||
}
|
||||
}
|
17
gradle.properties
Normal file
17
gradle.properties
Normal file
@ -0,0 +1,17 @@
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.16-pre5
|
||||
yarn_build = 1
|
||||
fabric_loader_version = 0.8.7+build.201
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
maven_group = com.thebrokenrail
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_api_version = 0.12.1+build.361-1.16
|
||||
cardinal_components_version = 2.4.0-nightly.1.16-pre4
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#Fri Jun 12 20:49:10 EDT 2020
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
183
gradlew
vendored
Executable file
183
gradlew
vendored
Executable file
@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or 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 UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$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 "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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
|
||||
;;
|
||||
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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
103
gradlew.bat
vendored
Normal file
103
gradlew.bat
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
@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 init
|
||||
|
||||
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 init
|
||||
|
||||
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
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
: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 %CMD_LINE_ARGS%
|
||||
|
||||
: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
|
12
settings.gradle
Normal file
12
settings.gradle
Normal file
@ -0,0 +1,12 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "twine"
|
47
src/main/java/com/thebrokenrail/twine/Twine.java
Normal file
47
src/main/java/com/thebrokenrail/twine/Twine.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.thebrokenrail.twine;
|
||||
|
||||
import com.thebrokenrail.twine.block.GlowingObsidianBlock;
|
||||
import com.thebrokenrail.twine.item.BackpackItem;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public class Twine implements ModInitializer {
|
||||
public static final String NAMESPACE = "twine";
|
||||
|
||||
public static final GlowingObsidianBlock GLOWING_OBSIDIAN = new GlowingObsidianBlock();
|
||||
|
||||
public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(new Identifier(NAMESPACE, "item_group"), () -> new ItemStack(GLOWING_OBSIDIAN));
|
||||
|
||||
public static final Identifier BACKPACK_SCREEN = new Identifier(NAMESPACE, "backpack");
|
||||
public static final Item SMALL_BACKPACK = new BackpackItem(false);
|
||||
public static final Item LARGE_BACKPACK = new BackpackItem(true);
|
||||
|
||||
public static final int STAGE_COUNT = 6;
|
||||
public static final int STAGE_TIME = 24000;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ContainerProviderRegistry.INSTANCE.registerFactory(BACKPACK_SCREEN, (i, identifier, playerEntity, buf) -> {
|
||||
boolean large = buf.readBoolean();
|
||||
Hand hand = buf.readEnumConstant(Hand.class);
|
||||
int rows = large ? 6 : 3;
|
||||
ItemStack stack = playerEntity.getStackInHand(hand);
|
||||
return new GenericContainerScreenHandler(ScreenHandlerType.STONECUTTER, i, playerEntity.inventory, new BackpackItem.ItemInventory(9 * rows, stack, hand), rows);
|
||||
});
|
||||
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "small_backpack"), SMALL_BACKPACK);
|
||||
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "large_backpack"), LARGE_BACKPACK);
|
||||
|
||||
Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "glowing_obsidian"), GLOWING_OBSIDIAN);
|
||||
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "glowing_obsidian"), new BlockItem(GLOWING_OBSIDIAN, new Item.Settings().group(ITEM_GROUP)));
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.thebrokenrail.twine.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.entity.AreaEffectCloudEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.mob.Monster;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GlowingObsidianBlock extends Block {
|
||||
public GlowingObsidianBlock() {
|
||||
super(Settings.of(Material.STONE, MaterialColor.BLACK).requiresTool().strength(50.0F, 1200.0F).lightLevel(state -> 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSteppedOn(World world, BlockPos pos, Entity entity) {
|
||||
super.onSteppedOn(world, pos, entity);
|
||||
if (entity instanceof LivingEntity && entity.age % 5 == 0) {
|
||||
final float amount = 1f;
|
||||
if (entity instanceof Monster) {
|
||||
((LivingEntity) entity).heal(amount);
|
||||
} else {
|
||||
entity.damage(DamageSource.MAGIC, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.thebrokenrail.twine.client;
|
||||
|
||||
import com.thebrokenrail.twine.Twine;
|
||||
import com.thebrokenrail.twine.item.BackpackItem;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
|
||||
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.DyeableItem;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class TwineClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ScreenProviderRegistry.INSTANCE.registerFactory(Twine.BACKPACK_SCREEN, screenHandler -> {
|
||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
assert player != null;
|
||||
return new GenericContainerScreen((GenericContainerScreenHandler) screenHandler, player.inventory, ((BackpackItem.ItemInventory) ((GenericContainerScreenHandler) screenHandler).getInventory()).getHolder().getName());
|
||||
});
|
||||
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> tintIndex > 0 ? -1 : ((DyeableItem) stack.getItem()).getColor(stack), Twine.SMALL_BACKPACK, Twine.LARGE_BACKPACK);
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.thebrokenrail.twine.component;
|
||||
|
||||
import com.thebrokenrail.twine.Twine;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.PersistentState;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StageDataComponent extends PersistentState {
|
||||
public StageDataComponent(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
public static class StageData {
|
||||
public int x;
|
||||
public int z;
|
||||
public long time = 0;
|
||||
}
|
||||
|
||||
private final Map<UUID, StageData[]> data = new HashMap<>();
|
||||
|
||||
public StageData[] getData(UUID uuid) {
|
||||
return data.computeIfAbsent(uuid, k -> new StageData[Twine.STAGE_COUNT]);
|
||||
}
|
||||
|
||||
private static final int CHUNK_RADIUS = 16;
|
||||
private static final String STAGE_DATA_ID = "twine_stage_data";
|
||||
|
||||
public static int findStageOfChunk(ChunkPos pos, StageDataComponent.StageData[] data) {
|
||||
for (int i = Twine.STAGE_COUNT - 1; i >= 0; i--) {
|
||||
StageDataComponent.StageData stage = data[i];
|
||||
if (stage != null && Math.abs(stage.x - pos.x) <= CHUNK_RADIUS && Math.abs(stage.z - pos.z) <= CHUNK_RADIUS) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
data[0] = new StageDataComponent.StageData();
|
||||
data[0].x = pos.x;
|
||||
data[0].z = pos.z;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int findStageOfChunk(ChunkPos pos) {
|
||||
Collection<StageData[]> values = data.values();
|
||||
int stage = 0;
|
||||
for (StageData[] value : values) {
|
||||
stage = Math.max(stage, findStageOfChunk(pos, value));
|
||||
}
|
||||
return stage;
|
||||
}
|
||||
|
||||
public static StageDataComponent getFromWorld(ServerWorld world) {
|
||||
return world.getPersistentStateManager().getOrCreate(() -> new StageDataComponent(STAGE_DATA_ID), STAGE_DATA_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag compoundTag) {
|
||||
data.clear();
|
||||
Tag uuidTag = compoundTag.get("Data");
|
||||
if (uuidTag instanceof ListTag) {
|
||||
for (int i = 0 ; i < ((ListTag) uuidTag).size(); i++) {
|
||||
CompoundTag obj = ((ListTag) uuidTag).getCompound(i);
|
||||
UUID uuid = obj.getUuid("UUID");
|
||||
|
||||
Tag tag = obj.get("Stages");
|
||||
StageData[] newData = new StageData[Twine.STAGE_COUNT];
|
||||
if (tag instanceof ListTag) {
|
||||
for (int k = 0; k < ((ListTag) tag).size(); k++) {
|
||||
Tag newTag = ((ListTag) tag).get(k);
|
||||
if (newTag instanceof CompoundTag) {
|
||||
StageData stage = new StageData();
|
||||
stage.x = ((CompoundTag) newTag).getInt("X");
|
||||
stage.z = ((CompoundTag) newTag).getInt("Z");
|
||||
stage.time = ((CompoundTag) newTag).getLong("Time");
|
||||
newData[((CompoundTag) newTag).getInt("Index")] = stage;
|
||||
}
|
||||
}
|
||||
data.put(uuid, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag compoundTag) {
|
||||
ListTag list = new ListTag();
|
||||
for (Map.Entry<UUID, StageData[]> entry : data.entrySet()) {
|
||||
CompoundTag obj = new CompoundTag();
|
||||
obj.putUuid("UUID", entry.getKey());
|
||||
ListTag newList = new ListTag();
|
||||
for (int i = 0; i < Twine.STAGE_COUNT; i++) {
|
||||
if (entry.getValue()[i] != null) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("X", entry.getValue()[i].x);
|
||||
tag.putInt("Z", entry.getValue()[i].z);
|
||||
tag.putLong("Time", entry.getValue()[i].time);
|
||||
tag.putInt("Index", i);
|
||||
newList.add(tag);
|
||||
}
|
||||
}
|
||||
obj.put("Stages", newList);
|
||||
list.add(obj);
|
||||
}
|
||||
compoundTag.put("Data", list);
|
||||
return compoundTag;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.thebrokenrail.twine.entity;
|
||||
|
||||
import com.thebrokenrail.twine.component.StageDataComponent;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.goal.FollowTargetGoal;
|
||||
import net.minecraft.entity.mob.Angerable;
|
||||
import net.minecraft.entity.mob.HostileEntity;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.passive.PassiveEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
public class FollowPassiveEntityGoal extends FollowTargetGoal<LivingEntity> {
|
||||
public FollowPassiveEntityGoal(MobEntity mob) {
|
||||
super(mob, LivingEntity.class, 10, false, false, entity -> {
|
||||
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) mob.getEntityWorld());
|
||||
ChunkPos chunkPos = new ChunkPos(mob.getBlockPos());
|
||||
int stage = component.findStageOfChunk(chunkPos);
|
||||
|
||||
return entity instanceof PassiveEntity || (entity instanceof PlayerEntity && stage >= 4);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean canStart() {
|
||||
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) mob.getEntityWorld());
|
||||
ChunkPos chunkPos = new ChunkPos(mob.getBlockPos());
|
||||
int stage = component.findStageOfChunk(chunkPos);
|
||||
|
||||
return mob instanceof HostileEntity && (!(mob instanceof Angerable) || stage >= 4) && stage >= 2 && super.canStart();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.thebrokenrail.twine.entity;
|
||||
|
||||
import com.thebrokenrail.twine.Twine;
|
||||
import net.minecraft.entity.ai.goal.MoveToTargetPosGoal;
|
||||
import net.minecraft.entity.mob.MobEntityWithAi;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
|
||||
public class StandOnGlowingObsidian extends MoveToTargetPosGoal {
|
||||
public StandOnGlowingObsidian(MobEntityWithAi mob) {
|
||||
super(mob, 1d, 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTargetPos(WorldView world, BlockPos pos) {
|
||||
Chunk chunk = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.FULL, false);
|
||||
if (chunk == null) {
|
||||
return false;
|
||||
} else {
|
||||
return chunk.getBlockState(pos).isOf(Twine.GLOWING_OBSIDIAN) && chunk.getBlockState(pos.up()).isAir() && chunk.getBlockState(pos.up(2)).isAir();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canStart() {
|
||||
return super.canStart() && (mob.getHealth() / mob.getMaxHealth()) <= 0.5;
|
||||
}
|
||||
}
|
134
src/main/java/com/thebrokenrail/twine/item/BackpackItem.java
Normal file
134
src/main/java/com/thebrokenrail/twine/item/BackpackItem.java
Normal file
@ -0,0 +1,134 @@
|
||||
package com.thebrokenrail.twine.item;
|
||||
|
||||
import com.thebrokenrail.twine.Twine;
|
||||
import com.thebrokenrail.twine.component.StageDataComponent;
|
||||
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.DyeableItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BackpackItem extends Item implements DyeableItem {
|
||||
public static class ItemInventory implements Inventory {
|
||||
private final int size;
|
||||
private final ItemStack stack;
|
||||
private final Hand hand;
|
||||
private final DefaultedList<ItemStack> inv;
|
||||
|
||||
public ItemInventory(int size, ItemStack stack, Hand hand) {
|
||||
this.size = size;
|
||||
this.stack = stack;
|
||||
this.hand = hand;
|
||||
inv = getInv();
|
||||
}
|
||||
|
||||
public ItemStack getHolder() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
private DefaultedList<ItemStack> getInv() {
|
||||
DefaultedList<ItemStack> list = DefaultedList.ofSize(size, ItemStack.EMPTY);
|
||||
Inventories.fromTag(stack.getOrCreateTag(), list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void setInv(DefaultedList<ItemStack> list) {
|
||||
Inventories.toTag(stack.getOrCreateTag(), list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (ItemStack item : inv) {
|
||||
if (item != ItemStack.EMPTY) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack(int slot) {
|
||||
return inv.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot, int amount) {
|
||||
return inv.get(slot).split(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot) {
|
||||
ItemStack item = inv.get(slot);
|
||||
return item.split(item.getCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
inv.set(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
setInv(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(PlayerEntity player) {
|
||||
return player.getStackInHand(hand) == stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
inv.set(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean large;
|
||||
|
||||
public BackpackItem(boolean large) {
|
||||
super(new Settings().maxCount(1).group(Twine.ITEM_GROUP));
|
||||
this.large = large;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
||||
ItemStack stack = user.getStackInHand(hand);
|
||||
if (!world.isClient()) {
|
||||
ContainerProviderRegistry.INSTANCE.openContainer(Twine.BACKPACK_SCREEN, user, buf -> {
|
||||
buf.writeBoolean(large);
|
||||
buf.writeEnumConstant(hand);
|
||||
});
|
||||
|
||||
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) world);
|
||||
ChunkPos chunkPos = new ChunkPos(user.getBlockPos());
|
||||
|
||||
int stage = component.findStageOfChunk(chunkPos);
|
||||
user.sendMessage(new LiteralText("Global Stage: " + stage), false);
|
||||
|
||||
StageDataComponent.StageData[] personalData = component.getData(user.getUuid());
|
||||
int personalStage = StageDataComponent.findStageOfChunk(chunkPos, personalData);
|
||||
user.sendMessage(new LiteralText("Personal Stage: " + personalStage), false);
|
||||
user.sendMessage(new LiteralText("Personal Center Chunk X: " + personalData[personalStage].x + " Personal Center Chunk Z: " + personalData[personalStage].z), false);
|
||||
user.sendMessage(new LiteralText("Time To Personal Stage Increase: " + (Twine.STAGE_TIME - personalData[personalStage].time) + " Ticks"), false);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.CONSUME, stack);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.thebrokenrail.twine.mixin;
|
||||
|
||||
import com.thebrokenrail.twine.Twine;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
import net.minecraft.world.gen.decorator.RangeDecoratorConfig;
|
||||
import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.OreFeatureConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(DefaultBiomeFeatures.class)
|
||||
public class MixinDefaultBiomeFeatures {
|
||||
@Inject(at = @At("RETURN"), method = "addMineables")
|
||||
private static void addMineables(Biome biome, CallbackInfo info) {
|
||||
biome.addFeature(GenerationStep.Feature.UNDERGROUND_ORES, Feature.ORE.configure(new OreFeatureConfig(OreFeatureConfig.Target.NATURAL_STONE, Twine.GLOWING_OBSIDIAN.getDefaultState(), 14)).createDecoratedFeature(Decorator.COUNT_RANGE.configure(new RangeDecoratorConfig(8, 0, 0, 32))));
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.thebrokenrail.twine.mixin;
|
||||
|
||||
import com.thebrokenrail.twine.component.StageDataComponent;
|
||||
import com.thebrokenrail.twine.entity.FollowPassiveEntityGoal;
|
||||
import com.thebrokenrail.twine.entity.StandOnGlowingObsidian;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.ai.goal.FollowTargetGoal;
|
||||
import net.minecraft.entity.ai.goal.GoalSelector;
|
||||
import net.minecraft.entity.mob.*;
|
||||
import net.minecraft.entity.passive.IronGolemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Mixin(MobEntity.class)
|
||||
public class MixinMobEntity {
|
||||
@Shadow
|
||||
@Final
|
||||
protected GoalSelector targetSelector;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
protected GoalSelector goalSelector;
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "<init>")
|
||||
public void initGoals(EntityType<? extends MobEntity> entityType, World world, CallbackInfo info) {
|
||||
if (world != null && !world.isClient()) {
|
||||
if (this instanceof Monster) {
|
||||
if ((Object) this instanceof MobEntityWithAi) {
|
||||
goalSelector.add(1, new StandOnGlowingObsidian((MobEntityWithAi) (Object) this));
|
||||
}
|
||||
targetSelector.add(2, new FollowPassiveEntityGoal((MobEntity) (Object) this));
|
||||
} else if ((Object) this instanceof IronGolemEntity) {
|
||||
targetSelector.add(3, new FollowTargetGoal<>((IronGolemEntity) (Object) this, PlayerEntity.class, 10, true, false, entity -> {
|
||||
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) ((IronGolemEntity) (Object) this).getEntityWorld());
|
||||
ChunkPos chunkPos = new ChunkPos(((IronGolemEntity) (Object) this).getBlockPos());
|
||||
int stage = component.findStageOfChunk(chunkPos);
|
||||
|
||||
return stage >= 3 && !((IronGolemEntity) (Object) this).isPlayerCreated();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.thebrokenrail.twine.mixin;
|
||||
|
||||
import com.thebrokenrail.twine.Twine;
|
||||
import com.thebrokenrail.twine.component.StageDataComponent;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
public abstract class MixinServerPlayerEntity {
|
||||
@Shadow
|
||||
public abstract ServerWorld getServerWorld();
|
||||
|
||||
@Unique
|
||||
private ChunkPos getChunkPos() {
|
||||
return new ChunkPos(((ServerPlayerEntity) (Object) this).getBlockPos());
|
||||
}
|
||||
|
||||
@Unique
|
||||
private long lastTime = -1L;
|
||||
|
||||
@Inject(at = @At("RETURN"), method = "tick")
|
||||
public void tick(CallbackInfo info) {
|
||||
StageDataComponent component = StageDataComponent.getFromWorld(getServerWorld());
|
||||
StageDataComponent.StageData[] data = component.getData(((ServerPlayerEntity) (Object) this).getUuid());
|
||||
int stage = StageDataComponent.findStageOfChunk(getChunkPos(), data);
|
||||
StageDataComponent.StageData stageObj = data[stage];
|
||||
if (lastTime != -1) {
|
||||
long diff = Math.max(0, getServerWorld().getTime() - lastTime);
|
||||
if (diff > 5) {
|
||||
System.out.println(diff);
|
||||
}
|
||||
stageObj.time = stageObj.time + Math.max(0, getServerWorld().getTime() - lastTime);
|
||||
}
|
||||
lastTime = getServerWorld().getTime();
|
||||
if (stageObj.time >= 24000 && stage + 1 < Twine.STAGE_COUNT) {
|
||||
StageDataComponent.StageData old = data[stage + 1];
|
||||
if (old != null) {
|
||||
old.time = 0;
|
||||
}
|
||||
StageDataComponent.StageData newData = new StageDataComponent.StageData();
|
||||
ChunkPos pos = getChunkPos();
|
||||
newData.x = pos.x;
|
||||
newData.z = pos.z;
|
||||
data[stage + 1] = newData;
|
||||
data[stage] = old;
|
||||
}
|
||||
component.markDirty();
|
||||
}
|
||||
}
|
36
src/main/java/com/thebrokenrail/twine/mixin/MixinSlot.java
Normal file
36
src/main/java/com/thebrokenrail/twine/mixin/MixinSlot.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.thebrokenrail.twine.mixin;
|
||||
|
||||
import com.thebrokenrail.twine.item.BackpackItem;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Slot.class)
|
||||
public class MixinSlot {
|
||||
@Shadow
|
||||
@Final
|
||||
public Inventory inventory;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "canInsert", cancellable = true)
|
||||
public void canInsert(ItemStack stack, CallbackInfoReturnable<Boolean> info) {
|
||||
if (inventory instanceof BackpackItem.ItemInventory) {
|
||||
if (stack.getItem() instanceof BackpackItem) {
|
||||
info.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < inventory.size(); i++) {
|
||||
ItemStack item = inventory.getStack(i);
|
||||
if (item != ItemStack.EMPTY && (item.getItem() != stack.getItem() && (item.getMaxCount() != 1 || stack.getMaxCount() != 1))) {
|
||||
info.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "twine:block/glowing_obsidian"
|
||||
}
|
||||
}
|
||||
}
|
6
src/main/resources/assets/twine/lang/en_us.json
Normal file
6
src/main/resources/assets/twine/lang/en_us.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"item.twine.large_backpack": "Large Backpack",
|
||||
"item.twine.small_backpack": "Small Backpack",
|
||||
"itemGroup.twine.item_group": "Twine",
|
||||
"block.twine.glowing_obsidian": "Glowing Obsidian"
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:block/cube_all",
|
||||
"textures": {
|
||||
"all": "twine:block/glowing_obsidian"
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "twine:block/glowing_obsidian"
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "twine:item/backpack",
|
||||
"layer1": "twine:item/backpack_overlay_large"
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "twine:item/backpack",
|
||||
"layer1": "twine:item/backpack_overlay_small"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
src/main/resources/assets/twine/textures/item/backpack.png
Normal file
BIN
src/main/resources/assets/twine/textures/item/backpack.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 942 B |
Binary file not shown.
After Width: | Height: | Size: 529 B |
Binary file not shown.
After Width: | Height: | Size: 536 B |
@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "twine:glowing_obsidian"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:match_tool",
|
||||
"predicate": {
|
||||
"enchantments": [
|
||||
{
|
||||
"enchantment": "minecraft:silk_touch",
|
||||
"levels": {
|
||||
"min": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
20
src/main/resources/data/twine/recipes/glowing_obsidian.json
Normal file
20
src/main/resources/data/twine/recipes/glowing_obsidian.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
" R ",
|
||||
"ROR",
|
||||
" R "
|
||||
],
|
||||
"key": {
|
||||
"R": {
|
||||
"item": "minecraft:redstone"
|
||||
},
|
||||
"O": {
|
||||
"item": "minecraft:obsidian"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "twine:glowing_obsidian",
|
||||
"count": 1
|
||||
}
|
||||
}
|
12
src/main/resources/data/twine/recipes/large_backpack.json
Normal file
12
src/main/resources/data/twine/recipes/large_backpack.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "minecraft:smithing",
|
||||
"base": {
|
||||
"item": "twine:small_backpack"
|
||||
},
|
||||
"addition": {
|
||||
"item": "minecraft:gold_ingot"
|
||||
},
|
||||
"result": {
|
||||
"item": "twine:large_backpack"
|
||||
}
|
||||
}
|
23
src/main/resources/data/twine/recipes/small_backpack.json
Normal file
23
src/main/resources/data/twine/recipes/small_backpack.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"SLS",
|
||||
"LIL",
|
||||
"SLS"
|
||||
],
|
||||
"key": {
|
||||
"S": {
|
||||
"item": "minecraft:stick"
|
||||
},
|
||||
"L": {
|
||||
"item": "minecraft:leather"
|
||||
},
|
||||
"I": {
|
||||
"item": "minecraft:iron_ingot"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "twine:small_backpack",
|
||||
"count": 1
|
||||
}
|
||||
}
|
34
src/main/resources/fabric.mod.json
Normal file
34
src/main/resources/fabric.mod.json
Normal file
@ -0,0 +1,34 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "twine",
|
||||
"version": "${version}",
|
||||
"name": "Twine",
|
||||
"description": "A simple survival mod for Minecraft encouraging a nomadic lifestyle.",
|
||||
"authors": [
|
||||
"TheBrokenRail"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://thebrokenrail.com/",
|
||||
"sources": "https://gitea.thebrokenrail.com/TheBrokenRail/Twine.git",
|
||||
"issues": "https://gitea.thebrokenrail.com/TheBrokenRail/Twine/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"icon": "assets/twine/icon.png",
|
||||
"environment": "*",
|
||||
"mixins": [
|
||||
"twine.mixins.json"
|
||||
],
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"com.thebrokenrail.twine.Twine"
|
||||
],
|
||||
"client": [
|
||||
"com.thebrokenrail.twine.client.TwineClient"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
}
|
||||
}
|
15
src/main/resources/twine.mixins.json
Normal file
15
src/main/resources/twine.mixins.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.thebrokenrail.twine.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinDefaultBiomeFeatures",
|
||||
"MixinMobEntity",
|
||||
"MixinServerPlayerEntity",
|
||||
"MixinSlot"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user