commit 179f90624255fc8f591927d66c735203e771139c Author: npc-strider Date: Fri Dec 11 20:14:22 2020 +0800 first commit, everything is functional. note that this has been built on the examplemod diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..31c38ee --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +# Automatically build the project and run any configured tests for every push +# and submitted pull request. This can help catch issues that only occur on +# certain platforms or Java versions, and provides a first line of defence +# against bad commits. + +name: build +on: [pull_request, push] + +jobs: + build: + strategy: + matrix: + # Use these Java versions + java: [ + 1.8, # Minimum supported by Minecraft + 11, # Current Java LTS + 15 # Latest version + ] + # and run on both Linux and Windows + os: [ubuntu-20.04, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: checkout repository + uses: actions/checkout@v2 + - name: validate gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: setup jdk ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: make gradle wrapper executable + if: ${{ runner.os != 'Windows' }} + run: chmod +x ./gradlew + - name: build + run: ./gradlew build + - name: capture build artifacts + if: ${{ runner.os == 'Linux' && matrix.java == '11' }} # Only upload artifacts built from LTS java on one OS + uses: actions/upload-artifact@v2 + with: + name: Artifacts + path: build/libs/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05b8964 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +*.wim +etc/ + +# gradle + +.gradle/ +build/ +out/ +classes/ + +# eclipse + +*.launch + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# macos + +*.DS_Store + +# fabric + +run/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..83a4511 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Old beacon + +This is my first ever 'real' minecraft mod. + +Adds the old beacon graphics, which had the small netherstar in the center, from the 12w36a snapshot (barring the lightning bolt style beam). + +When the beacon is idle the star is blue - this is a feature added by me but if you want to stay true to the original graphics disable it in the config file located at `config/oldbeacon.cfg`, and set `idle_anim=true` to `idle_anim=false` + +If you want to change the beacon base so it's like the old style, feel free to use a resource pack. I can't add the old base as an option through the config, as far as I know. I may bundle the resource pack with this mod later. + +Note that this mod will potentially conflict with ONLY mods that change the beacon rendering code, because I used override mixins for everything. \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f7784b9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,82 @@ +plugins { + id 'fabric-loom' version '0.5-SNAPSHOT' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group + +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}" + + // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. + // You may need to force-disable transitiveness on them. +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(JavaCompile).configureEach { + // 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 + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + + // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too + // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. + // We'll use that if it's available, but otherwise we'll use the older option. + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release = targetVersion + } +} + +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}"} + } +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + // add all the jars that should be included when publishing to maven + artifact(remapJar) { + builtBy remapJar + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } + } + } + + // Select the repositories you want to publish to + // To publish to maven local, no extra repositories are necessary. Just use the task `publishToMavenLocal`. + repositories { + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..d39abce --- /dev/null +++ b/gradle.properties @@ -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.4 + yarn_mappings=1.16.4+build.6 + loader_version=0.10.6+build.214 + +# Mod Properties + mod_version = 1.0.0 + maven_group = io.github.npc_strider.oldbeacon + archives_base_name = fabric-test + +# Dependencies + # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api + fabric_version=0.25.1+build.416-1.16 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c 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..be52383 --- /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-6.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/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" "$@" 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..5b60df3 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + jcenter() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/io/github/npc_strider/oldbeacon/OldBeacon.java b/src/main/java/io/github/npc_strider/oldbeacon/OldBeacon.java new file mode 100644 index 0000000..58c211e --- /dev/null +++ b/src/main/java/io/github/npc_strider/oldbeacon/OldBeacon.java @@ -0,0 +1,57 @@ +package io.github.npc_strider.oldbeacon; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; + +import net.fabricmc.api.ModInitializer; + +public class OldBeacon implements ModInitializer { + public static final String MOD_ID = "oldbeacon"; + + public static Boolean IDLE_ANIM; + + @Override + public void onInitialize() { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + // System.out.println("Load"+MOD_ID); + + //Config file stuff. + Properties p = new Properties(); + Path file = Paths.get("config/oldbeacon.cfg"); + InputStream is = null; + try { + is = new FileInputStream(file.toString()); + try { + p.load(is); + } catch (IOException ex) { + System.out.println("Old beacon: cannot read config!"); + ex.printStackTrace(); + } + } catch (FileNotFoundException ex) { + List lines = Arrays.asList( + "# default: true. Beacon has a blue star when it is not emitting a beam.", + "idle_anim=true" + ); + try { + Files.write(file, lines, StandardCharsets.UTF_8); + } catch (Exception ex_) { + System.out.println("Old beacon: could not write new config file! Do you have sufficient permissions to write the file?"); + ex_.printStackTrace(); + } + } + IDLE_ANIM = p.getProperty("idle_anim").toLowerCase().trim().equals("true") ? true : false; + }; + +} \ No newline at end of file diff --git a/src/main/java/io/github/npc_strider/oldbeacon/OldBeaconClient.java b/src/main/java/io/github/npc_strider/oldbeacon/OldBeaconClient.java new file mode 100644 index 0000000..0e839b8 --- /dev/null +++ b/src/main/java/io/github/npc_strider/oldbeacon/OldBeaconClient.java @@ -0,0 +1,12 @@ +// package io.github.npc_strider.oldbeacon; + +// import net.fabricmc.api.ClientModInitializer; +// import net.fabricmc.api.EnvType; +// import net.fabricmc.api.Environment; + +// @Environment(EnvType.CLIENT) +// public class OldBeaconClient implements ClientModInitializer { +// @Override +// public void onInitializeClient() { +// } +// } diff --git a/src/main/java/io/github/npc_strider/oldbeacon/mixin/BeaconMixin.java b/src/main/java/io/github/npc_strider/oldbeacon/mixin/BeaconMixin.java new file mode 100644 index 0000000..092ea95 --- /dev/null +++ b/src/main/java/io/github/npc_strider/oldbeacon/mixin/BeaconMixin.java @@ -0,0 +1,179 @@ +package io.github.npc_strider.oldbeacon.mixin; + +import net.minecraft.block.entity.BeaconBlockEntity; +import net.minecraft.client.model.ModelPart; +import net.minecraft.client.render.OverlayTexture; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer; +import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.util.math.Vector3f; +import net.minecraft.entity.boss.BossBar.Color; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Quaternion; + +import java.util.LinkedList; +import java.util.List; + +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.Coerce; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import io.github.npc_strider.oldbeacon.OldBeacon; + +@Mixin(BeaconBlockEntityRenderer.class) +public class BeaconMixin { + @Shadow static final Identifier BEAM_TEXTURE = new Identifier("textures/entity/beacon_beam.png"); + // @Shadow static final Identifier BEAM_TEXTURE = new Identifier("textures/misc/beam.png"); //Not going to bother trying to reimplement the old beacon beam + @Shadow private static void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, float f, long l, int i, int j, float[] fs) {}; + + private static final boolean IDLE_ANIM = OldBeacon.IDLE_ANIM; + private static final float d = 0.1F; // Really not sure what coefficient to use - decompiled source has 0.05F but visually it looks too small. Original of 0.4F in endcrystal is too much. + private static final Identifier NETHER_STAR_TEXTURE = new Identifier("textures/misc/beacon.png"); + private static final RenderLayer NETHER_STAR = RenderLayer.getEntityCutoutNoCull(NETHER_STAR_TEXTURE); // Originally 'END_CRYSTAL' + private static final float SINE_45_DEGREES = (float)Math.sin(0.7853981633974483D); + private ModelPart core = new ModelPart(64, 32, 32, 0).addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + private ModelPart frame = new ModelPart(64, 32, 0, 0).addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + private ModelPart bottom = new ModelPart(64, 32, 0, 16).addCuboid(-6.0F, 0.0F, -6.0F, 12.0F, 4.0F, 12.0F); + + // @Inject( + // at = @At("HEAD"), + // method = "BeaconBlockEntityRenderer()V" + // ) + // public BeaconBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) { + // this.frame = new ModelPart(64, 32, 0, 0); + // this.frame.addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + // this.core = new ModelPart(64, 32, 32, 0); + // this.core.addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + // this.bottom = new ModelPart(64, 32, 0, 16); + // this.bottom.addCuboid(-6.0F, 0.0F, -6.0F, 12.0F, 4.0F, 12.0F); + // } + + // Yeah for some reason this is a thing; have to ignore the error when debugging. + @Inject( + at = @At("HEAD"), + method = "BeaconBlockEntityRenderer()V" + ) + public BeaconBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) { + super(blockEntityRenderDispatcher); + this.frame = new ModelPart(64, 32, 0, 0).addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + this.core = new ModelPart(64, 32, 32, 0).addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + this.bottom = new ModelPart(64, 32, 0, 16).addCuboid(-6.0F, 0.0F, -6.0F, 12.0F, 4.0F, 12.0F); + // this.frame = new ModelPart(64, 32, 0, 0).addCuboid(0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 8.0F); + // this.core = new ModelPart(64, 32, 32, 0).addCuboid(0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 8.0F); + // this.bottom = new ModelPart(64, 32, 0, 16).addCuboid(-2.0F, 4.0F, -2.0F, 12.0F, 4.0F, 12.0F); + }; + + //Why am I not using injects ? + // I'm using overrides for the render for several reasons + // 1. Not many mods will modify the vanilla beacon renderer - if they did then it's probably because they want to change its graphics. + // If they are changing its graphics, then why bother using this mod? The graphics would conflict if the mixins worked together. + // 2. This modification seems so complex that using injection isn't worth it anymore. + // I was considering using it but once I started making changes to the beacon beam renderer pretty much everything within render is changed, so might as well override it. + public void render(BeaconBlockEntity beaconBlockEntity, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) { + // long l = beaconBlockEntity.getWorld().getTime(); + // List list = beaconBlockEntity.getBeamSegments(); + // int k = 0; + + // for(int m = 0; m < list.size(); ++m) { + // BeaconBlockEntity.BeamSegment beamSegment = (BeaconBlockEntity.BeamSegment)list.get(m); + // render(matrixStack, vertexConsumerProvider, f, l, k, m == list.size() - 1 ? 1024 : beamSegment.getHeight(), new float[]{1.0F, 1.0F, 0.0F} /*beamSegment.getColor()*/); + // k += beamSegment.getHeight(); + // } + + VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(NETHER_STAR); + + float scale = 1.0F; // Original in EndCrystalEntityRenderer: 2.0F + float[] ccolor = new float[]{1.0F, 1.0F, 1.0F, 1.0F}; + float[] fcolor = new float[]{1.0F, 1.0F, 1.0F, 1.0F}; + if (beaconBlockEntity.getBeamSegments().size() == 0 & IDLE_ANIM == true) { //This is if the beacon is INACTIVE. + scale = 0.7F; + fcolor = new float[]{0.65F, 1.0F, 1.0F, 0.05F}; //Alpha doesn't work?? + ccolor = new float[]{0.1F, 0.5F, 1.0F, 0.05F}; //Alpha doesn't work?? + }; + + matrixStack.push(); + long tick = beaconBlockEntity.getWorld().getTime(); // Unfortunately the block has no time (endcrystals have endCrystalAge), so all block have the same animations + float h = OldBeacon_getYOffset(tick, tickDelta) - (1.75F - d - 0.075F);//(h)eight offset of crystal //tickDelta ensures smooth animation (Not capped to 20fps/ 1 frame per tick.) + float phase = (/*(float)BeaconBlockEntity.endCrystalAge +*/ tick + tickDelta) * 3.0F; //phase or angle - results in rotational motion + // float phase = ((float)BeaconBlockEntity.endCrystalAge + g) * 3.0F; + matrixStack.push(); + // matrixStack.scale(2.0F, 2.0F, 2.0F); + matrixStack.scale(scale, scale, scale); + matrixStack.translate(0.5D/scale, /*-0.5D*/ -0.2D/scale, 0.5D/scale); + int k = OverlayTexture.DEFAULT_UV; + // if (BeaconBlockEntity.getShowBottom()) { //Originally code for the bedrock 'base' of end crystals. + // this.bottom.render(matrixStack, vertexConsumer, i, k); + // } + + // Below here is graphical stuff. Don't mess with it - idk how tf quaternions rotations even work! + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(phase)); + matrixStack.translate(0.0D, (double)(1.5F + h / 2.0F)/scale, 0.0D); + matrixStack.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); + this.frame.render(matrixStack, vertexConsumer, i, k, fcolor[0], fcolor[1], fcolor[2], fcolor[3]); + float l = 0.875F; //Not sure why this number - don't want to hear about it. + matrixStack.scale(l, l, l); + matrixStack.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(phase)); + this.frame.render(matrixStack, vertexConsumer, i, k, fcolor[0], fcolor[1], fcolor[2], fcolor[3]); + matrixStack.scale(l, l, l); + matrixStack.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); + matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(phase)); + this.core.render(matrixStack, vertexConsumer, i, k, ccolor[0], ccolor[1], ccolor[2], ccolor[3]); + matrixStack.pop(); + matrixStack.pop(); + // BlockPos blockPos = BeaconBlockEntity.getBeamTarget(); //Originally code for the ender dragon beam which goes from crystal to dragon. + // if (blockPos != null) { + // float m = (float)blockPos.getX() + 0.5F; + // float n = (float)blockPos.getY() + 0.5F; + // float o = (float)blockPos.getZ() + 0.5F; + // float p = (float)((double)m - BeaconBlockEntity.getX()); + // float q = (float)((double)n - BeaconBlockEntity.getY()); + // float r = (float)((double)o - BeaconBlockEntity.getZ()); + // matrixStack.translate((double)p, (double)q, (double)r); + // EnderDragonEntityRenderer.renderCrystalBeam(-p, -q + h, -r, g, BeaconBlockEntity.endCrystalAge, matrixStack, vertexConsumerProvider, i); + // } + + + float tr = 0.5F + 0.075F; //Translate beam so it's inside of the star. + matrixStack.translate(0.0D, tr, 0.0D); // Make sure beam starts inside of star, not below it. + matrixStack.scale(1.0F, (1.0F-tr), 1.0F); + int x = 0; + List list = new LinkedList<>(beaconBlockEntity.getBeamSegments()); //Need a linkedlist because I'm adding a new beam segment + if (list.size() > 0 ) { + list.add(0, new BeaconBlockEntity.BeamSegment(new float[]{1.0F, 1.0F, 1.0F})); + // Adding a new beam segment which is only inside of the beacon block to account for the transformations. Cannot simply subtract a float height and shift (j is an int) so we need to be a bit clever. + // The next beam become a 'buffer beam' which is also special as it's truncated (m == 2) + } + + for(int m = 0; m < list.size(); ++m) { + BeaconBlockEntity.BeamSegment beamSegment = (BeaconBlockEntity.BeamSegment)list.get(m); + int j_ = beamSegment.getHeight(); + if (m == 1){ //hacky stuff to ensure glass blocks tint the beam at the start, not in the middle of the glass (if we only transformed it up by 0.5F) + matrixStack.scale(1.0F, 1.0F/(1.0F-tr), 1.0F); //Scale up the next beam segment so it's 1 block tall again + matrixStack.translate(0.0D, -tr, 0.0D); //Re-translate the beam so it's aligned to the grid. + j_--; // This covers the case where the tint block is immediately above the beacon (=> height of 0) + } else if (m == 2){ + matrixStack.translate(0.0D, -1.0F, 0.0D); // Need to cover the truncated height of the previous beam segment (j_--) + } + render(matrixStack, vertexConsumerProvider, tickDelta, tick, x, m == list.size() - 1 ? 1024 : j_, beamSegment.getColor()); + x += beamSegment.getHeight(); + } + + // super.render(beaconBlockEntity, f, g, matrixStack, vertexConsumerProvider, i); + } + + private static float OldBeacon_getYOffset(/*BeaconBlockEntity crystal,*/long tick, float tickDelta) { + float f = /*(float)crystal.endCrystalAge +*/tick + tickDelta; + float g = MathHelper.sin(f * 0.2F) / 2.0F + 0.5F; + g = (g * g + g) * d; + return g /*- 1.4F*/; // Center of the beacon. Again, not sure of the official constant used. (1.75F is the real center, but it clips due to its oscillation). Moved the constant to the result. + } + +} \ No newline at end of file diff --git a/src/main/java/io/github/npc_strider/oldbeacon/mixin/TestMixin.java b/src/main/java/io/github/npc_strider/oldbeacon/mixin/TestMixin.java new file mode 100644 index 0000000..44ec008 --- /dev/null +++ b/src/main/java/io/github/npc_strider/oldbeacon/mixin/TestMixin.java @@ -0,0 +1,20 @@ +package io.github.npc_strider.oldbeacon.mixin; + +import net.minecraft.client.gui.screen.TitleScreen; +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(TitleScreen.class) +public class TestMixin { + private String splashText; + @Inject( + at = @At("HEAD"), + method = "init()V" + ) + private void init(CallbackInfo info) { + System.out.println("This line is printed by an example mod mixin!"); + this.splashText = "Hello world! This text has been injected via a MIXIN."; + } +} diff --git a/src/main/resources/assets/minecraft/models/block/beacon.json b/src/main/resources/assets/minecraft/models/block/beacon.json new file mode 100644 index 0000000..8bae197 --- /dev/null +++ b/src/main/resources/assets/minecraft/models/block/beacon.json @@ -0,0 +1,35 @@ +{ "parent": "block/block", + "ambientocclusion": false, + "textures": { + "particle": "block/glass", + "glass": "block/glass", + "obsidian": "block/obsidian", + "beacon": "block/glass" + }, + "elements": [ + { "__comment": "Glass shell", + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" } + } + }, + { "__comment": "Obsidian base", + "from": [ 2, 0.1, 2 ], + "to": [ 14, 3, 14 ], + "faces": { + "down": { "uv": [ 2, 2, 14, 14 ], "texture": "#obsidian" }, + "up": { "uv": [ 2, 2, 14, 14 ], "texture": "#obsidian" }, + "north": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }, + "south": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }, + "west": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }, + "east": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" } + } + } + ] +} diff --git a/src/main/resources/assets/minecraft/models/block/beacon_oldbase.json b/src/main/resources/assets/minecraft/models/block/beacon_oldbase.json new file mode 100644 index 0000000..cd92764 --- /dev/null +++ b/src/main/resources/assets/minecraft/models/block/beacon_oldbase.json @@ -0,0 +1,37 @@ +{ + "__comment": "README/ATTENTION: If you want the old beacon base (full 1x1 flat obsidian), rename beacon.json to something else (beacon_old.json) and this to beacon.json. I can't use a mod setting to change this model AFAIK.", + "parent": "block/block", + "ambientocclusion": false, + "textures": { + "particle": "block/glass", + "glass": "block/glass", + "obsidian": "block/obsidian", + "beacon": "block/glass" + }, + "elements": [ + { "__comment": "Glass shell", + "from": [ 0, 3, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "north": { "uv": [ 0, 0, 16, 10 ], "texture": "#glass" }, + "south": { "uv": [ 0, 0, 16, 10 ], "texture": "#glass" }, + "west": { "uv": [ 0, 0, 16, 10 ], "texture": "#glass" }, + "east": { "uv": [ 0, 0, 16, 10 ], "texture": "#glass" } + } + }, + { "__comment": "Obsidian base", + "from": [ 0, 0, 0 ], + "to": [ 16, 3, 16 ], + "faces": { + "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#obsidian" }, + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#obsidian" }, + "north": { "uv": [ 0, 13, 16, 16 ], "texture": "#obsidian" }, + "south": { "uv": [ 0, 13, 16, 16 ], "texture": "#obsidian" }, + "west": { "uv": [ 0, 13, 16, 16 ], "texture": "#obsidian" }, + "east": { "uv": [ 0, 13, 16, 16 ], "texture": "#obsidian" } + } + } + ] +} diff --git a/src/main/resources/assets/minecraft/models/item/beacon.json b/src/main/resources/assets/minecraft/models/item/beacon.json new file mode 100644 index 0000000..daf1e5b --- /dev/null +++ b/src/main/resources/assets/minecraft/models/item/beacon.json @@ -0,0 +1,43 @@ +{ "parent": "minecraft:block/beacon", + "textures": { + "star": "misc/star" + }, + "elements": [ + { "__comment": "Glass shell", + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }, + "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" } + } + }, + { "__comment": "Obsidian base", + "from": [ 2, 0.1, 2 ], + "to": [ 14, 3, 14 ], + "faces": { + "down": { "uv": [ 2, 2, 14, 14 ], "texture": "#obsidian" }, + "up": { "uv": [ 2, 2, 14, 14 ], "texture": "#obsidian" }, + "north": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }, + "south": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }, + "west": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }, + "east": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" } + } + }, + { "__comment": "Star", + "from": [ 6, 6, 6 ], + "to": [ 10, 10, 10 ], + "faces": { + "down": { "uv": [ 0, 0, 4, 4 ], "texture": "#star" }, + "up": { "uv": [ 0, 0, 4, 4 ], "texture": "#star" }, + "north": { "uv": [ 0, 0, 4, 4 ], "texture": "#star" }, + "south": { "uv": [ 0, 0, 4, 4 ], "texture": "#star" }, + "west": { "uv": [ 0, 0, 4, 4 ], "texture": "#star" }, + "east": { "uv": [ 0, 0, 4, 4 ], "texture": "#star" } + } + } + ] +} diff --git a/src/main/resources/assets/minecraft/textures/misc/beacon.png b/src/main/resources/assets/minecraft/textures/misc/beacon.png new file mode 100644 index 0000000..076d9e0 Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/misc/beacon.png differ diff --git a/src/main/resources/assets/minecraft/textures/misc/beam.png b/src/main/resources/assets/minecraft/textures/misc/beam.png new file mode 100644 index 0000000..565029d Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/misc/beam.png differ diff --git a/src/main/resources/assets/minecraft/textures/misc/star.png b/src/main/resources/assets/minecraft/textures/misc/star.png new file mode 100644 index 0000000..5e92aaf Binary files /dev/null and b/src/main/resources/assets/minecraft/textures/misc/star.png differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..2271c64 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "modid", + "version": "${version}", + + "name": "Example Mod", + "description": "This is an example description! Tell everyone what your mod is about!", + "authors": [ + "Me!" + ], + "contact": { + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" + }, + + "license": "CC0-1.0", + "icon": "assets/modid/icon.png", + + "environment": "*", + "entrypoints": { + "main": [ + "io.github.npc_strider.oldbeacon.OldBeacon" + ] + }, + "mixins": [ + "modid.mixins.json" + ], + + "depends": { + "fabricloader": ">=0.7.4", + "fabric": "*", + "minecraft": "1.16.x" + }, + "suggests": { + "another-mod": "*" + } +} diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/modid.mixins.json new file mode 100644 index 0000000..898f862 --- /dev/null +++ b/src/main/resources/modid.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "io.github.npc_strider.oldbeacon.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + ], + "client": [ + "TestMixin", + "BeaconMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}