diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3fa8f86 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/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##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +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=SC2039,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=SC2039,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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/gradlew.bat @@ -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 diff --git a/src/client/java/modchest/REServerModClient.java b/src/client/java/modchest/REServerModClient.java index 2ae7013..a67e3a6 100644 --- a/src/client/java/modchest/REServerModClient.java +++ b/src/client/java/modchest/REServerModClient.java @@ -1,17 +1,18 @@ package modchest; -import modchest.networking.modNetworkingClient; +import modchest.util.clientInitializer; import net.fabricmc.api.ClientModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class REServerModClient implements ClientModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger("modchest"); // Erster Error Logger + @Override public void onInitializeClient() { // This entrypoint is suitable for setting up client-specific logic, such as rendering. - - modNetworkingClient.registerC2SPackets(); //Identifier unter denen der Client zuhoert werden registriert + clientInitializer.renderer(); + clientInitializer.networking(); LOGGER.info("Modchest-Client successfully loaded!"); } diff --git a/src/client/java/modchest/networking/modNetworkingClient.java b/src/client/java/modchest/networking/modNetworkingClient.java index b30a978..0e08f34 100644 --- a/src/client/java/modchest/networking/modNetworkingClient.java +++ b/src/client/java/modchest/networking/modNetworkingClient.java @@ -9,7 +9,8 @@ public class modNetworkingClient { //Identifier werden eingeführt public static final Identifier request_respawn = new Identifier(REServerMod.MOD_ID, "request_respawn"); //alle Identifier muessen leider IMMER auf Client und Server (doppelt) eingefuehrt werden public static final Identifier start_sleeping_call_buttons = new Identifier(REServerMod.MOD_ID, "start_sleeping_call_buttons"); public static final Identifier death_multi_respawn_buttons = new Identifier(REServerMod.MOD_ID, "death_call_respawn_buttons"); - public static void registerC2SPackets() { //Identifier fuer packets werden registriert (Identifier die der Server aufruft um beim CLient was auszufuehren) + + public static void registerS2CPackets() { //Identifier fuer packets werden registriert (Identifier die der Server aufruft um beim Client was auszufuehren) ClientPlayNetworking.registerGlobalReceiver(request_respawn, respawnRequestS2CPacket::receive); //was der Client dann machen soll steht in der receive Methode } } diff --git a/src/client/java/modchest/util/clientInitializer.java b/src/client/java/modchest/util/clientInitializer.java new file mode 100644 index 0000000..3370f3b --- /dev/null +++ b/src/client/java/modchest/util/clientInitializer.java @@ -0,0 +1,30 @@ +package modchest.util; + +import modchest.block.modBlocks; +import modchest.networking.modNetworkingClient; +import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; +import net.minecraft.client.render.RenderLayer; + +public class clientInitializer { + public static void itemGroups() { + //modItemGroup.modchest(); // Item Gruppe fürs Creative-Inventar wird erstellt; In dieser Gruppe sollen + // dann alle Items und Blöcke dieser Mod angezeigt werden + } + + public static void itemsAndBlocks() { + //modItems.setItems(); // die Items werden erstellt + //modBlocks.setBlocks(); // Hier werden die Blöcke erstellt + //modBlockEntities.registerBlockEntities(); // Die Interaktionsmenüs für die Blöcke werden erstellt + } + + public static void events() { //Events, bei denen custom Code ausgefuehrt wird, werden eingefuehrt + } + + public static void networking() { //Identifier unter denen der Server zuhoert werden registriert + modNetworkingClient.registerS2CPackets(); //Identifier unter denen der Client zuhoert werden registriert + } + + public static void renderer() { //Grafikrenderer werden aufgerufen + BlockRenderLayerMap.INSTANCE.putBlock(modBlocks.denk_mal_block, RenderLayer.getTranslucent()); //denk_mal_block bekommt die Faehigkeit, transparente Grafiken zu haben + } +} diff --git a/src/main/java/modchest/block/custom/denkMalBlock.java b/src/main/java/modchest/block/custom/denkMalBlock.java new file mode 100644 index 0000000..ff8a436 --- /dev/null +++ b/src/main/java/modchest/block/custom/denkMalBlock.java @@ -0,0 +1,150 @@ +package modchest.block.custom; + +import modchest.util.denkMalBlockUtil; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.block.*; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import net.minecraft.world.explosion.Explosion; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; + +import static modchest.block.modBlocks.denk_mal_block_placeholder; + +public class denkMalBlock extends BlockWithEntity { //Item soll nicht craftable sein + public static BooleanProperty POWERED = BooleanProperty.of("powered"); //speichert ob der Block ein Redstonesignal erhaelt + + public denkMalBlock(FabricBlockSettings fabricBlockSettings) { + super(fabricBlockSettings); + setDefaultState(getDefaultState().with(POWERED, false)); //Block ist beim platzieren immer aus + } + + @Override + public BlockRenderType getRenderType(BlockState state) { //ruft auf, die Grafik zu rendern + return BlockRenderType.MODEL; + } + + private static VoxelShape SHAPE = BlockWithEntity.createCuboidShape(0, 0, 0, 16, 32, 16); //Erstellt eine approximation des Koerpers; braucht weniger Leistung als ein Volles Rendern + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { //Beschreibt die tatsaechlichen Konturen + return SHAPE; + } + + + @Nullable + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return null; + } + + @Override + public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { //damit man durch den Glasteil des blockes sehen kann + return true; + } + + @Override //Block soll nicht gedroped werden + public boolean shouldDropItemsOnExplosion(Explosion explosion) { + return false; + } + + @Override + public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { //platziert den placeholder block oben drauf, weil es in miencraft keine 2 hohen Bloecke gibt + super.onPlaced(world, pos, state, placer, itemStack); + if (!world.isClient) { + world.setBlockState(pos.up(1), denk_mal_block_placeholder.getDefaultState(), Block.NOTIFY_ALL); //platziert den placeholder Block ueber sich selbst + world.updateNeighbors(pos, Blocks.AIR); + state.updateNeighbors(world, pos, Block.NOTIFY_ALL); + } + } + + @Override + public void onBroken(WorldAccess world, BlockPos pos, BlockState state) { //entfernt sich aus der Liste der zu ueberpruefenden bloecke + denkMalBlockUtil data = new denkMalBlockUtil(); + world.setBlockState(pos.up(1), Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL); //entfernt den Placeholder block ueber sich + int[] temp = new int[3]; + temp[0] = pos.getX(); + temp[1] = pos.getY(); + temp[2] = pos.getZ(); + data.removeBlock(temp); //entfernt sich aus der liste der Abbauverhindernden Bloecke + + } + + //CODE ZUM UEBERPREUFEN OB MIT REDSTONE GEPOWERED + + @Override + @Nullable + public BlockState getPlacementState(ItemPlacementContext ctx) { + return (BlockState) this.getDefaultState().with(POWERED, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())); + } + + @Override + public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { + if (world.isClient) { + return; + } + boolean bl = state.get(POWERED); + + if (bl != world.isReceivingRedstonePower(pos)) { + if (bl) { + world.createAndScheduleBlockTick(pos, this, 4); + } else { + world.setBlockState(pos, (BlockState) state.cycle(POWERED), Block.NOTIFY_LISTENERS); + changePositionList(state, world, pos); + } + } + } + + @Override + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (state.get(POWERED).booleanValue() && !world.isReceivingRedstonePower(pos)) { + world.setBlockState(pos, (BlockState) state.cycle(POWERED), Block.NOTIFY_LISTENERS); + changePositionList(state, world, pos); + } + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(POWERED); + } + + //CODE ZUM UEBERÜREUFEN OB MIT REDSTONE GEPOWERED ZUENDE + + private void changePositionList(BlockState state, World world, BlockPos pos) { //aendert ob der Block in der Liste der Bloecke steht, die das abbauen verhindern + denkMalBlockUtil data = new denkMalBlockUtil(); + if (!world.isClient) { + int[] temp = new int[3]; + temp[0] = pos.getX(); + temp[1] = pos.getY(); + temp[2] = pos.getZ(); + int[] range = new int[3]; //noch ist die range auf 20 Bloecke, soll aber spaeter via ein Entity vom Spieler veraendert werden koenneny + range[0] = 20; + range[1] = 20; + range[2] = 20; + if (!state.get(POWERED)) { + data.addBlock(temp, range); + } else { + data.removeBlock(temp); + } + } + } + + @Mutable + @Final protected BlockPos worldPosition; + public void setCMPos(BlockPos newPos) { + worldPosition = newPos; + } +} diff --git a/src/main/java/modchest/block/custom/denkMalBlockPlaceholder.java b/src/main/java/modchest/block/custom/denkMalBlockPlaceholder.java new file mode 100644 index 0000000..4faef0d --- /dev/null +++ b/src/main/java/modchest/block/custom/denkMalBlockPlaceholder.java @@ -0,0 +1,37 @@ +package modchest.block.custom; + +import modchest.REServerMod; +import modchest.util.denkMalBlockUtil; +import net.minecraft.block.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.WorldAccess; + +import java.util.Arrays; + +import static modchest.block.modBlocks.denk_mal_block_placeholder; + +public class denkMalBlockPlaceholder extends Block { //Block der simuliert, dass der DenkMalBLock 2 Bloecke hoch waere + public denkMalBlockPlaceholder(Settings settings) { + super(settings); + } + + @Override + public BlockRenderType getRenderType(BlockState state) { //Grafik kommt vom DenkMalBLock, dieser Block muss also unsichtbar sein + return BlockRenderType.INVISIBLE; + } + + + @Override + public void onBroken(WorldAccess world, BlockPos pos, BlockState state) { //Loescht den eigentlichen DenkMalBlock + denkMalBlockUtil data = new denkMalBlockUtil(); //denkMalBLockUtil holt sich alle infos von der static dataSaverIO Klasse + world.setBlockState(pos.down(1), Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL); //unter diesem Block wird Luft platziert + int[] temp = new int[3]; + temp[0] = pos.getX(); + temp[1] = (pos.getY()-1); + temp[2] = pos.getZ(); + data.removeBlock(temp); //Loescht den denkMalBLock aus der Liste der abbauverhindernden Bloecke + } +} diff --git a/src/main/java/modchest/block/custom/steeringWheelBlock.java b/src/main/java/modchest/block/custom/steeringWheelBlock.java index af19f07..c814823 100644 --- a/src/main/java/modchest/block/custom/steeringWheelBlock.java +++ b/src/main/java/modchest/block/custom/steeringWheelBlock.java @@ -25,15 +25,13 @@ public class steeringWheelBlock extends BlockWithEntity implements BlockEntityPr super(settings); } - - /* stuff benötigt um das Interaktionsmenü zu laden!*/ @Override - public BlockRenderType getRenderType(BlockState state) { + public BlockRenderType getRenderType(BlockState state) {//ruft auf, die Grafik zu rendern return BlockRenderType.MODEL; } @Override - public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { //Aufgerufen bei blockstate veraenderung, z.B. restonestaerke if (state.getBlock() != newState.getBlock()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof steeringWheelEntity) { @@ -44,6 +42,7 @@ public class steeringWheelBlock extends BlockWithEntity implements BlockEntityPr } } + /* stuff benötigt um das Interaktionsmenü zu laden!*/ @Override //wird bei einem rechtsklick aufgerufen (ersellt das Blockentity) public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!world.isClient) { diff --git a/src/main/java/modchest/block/modBlocks.java b/src/main/java/modchest/block/modBlocks.java index 4d5a135..551bb04 100644 --- a/src/main/java/modchest/block/modBlocks.java +++ b/src/main/java/modchest/block/modBlocks.java @@ -1,5 +1,8 @@ package modchest.block; import modchest.block.custom.gridBlock; + +import modchest.block.custom.denkMalBlock; +import modchest.block.custom.denkMalBlockPlaceholder; import modchest.block.custom.steeringWheelBlock; import modchest.item.modItemGroup; import modchest.REServerMod; @@ -16,6 +19,8 @@ import net.minecraft.util.registry.Registry; public class modBlocks { public static Block steering_wheel; // Block wird erstellt public static Block grid_block; + public static Block denk_mal_block; + public static Block denk_mal_block_placeholder; public static void setBlocks() {// Block wird definiert steering_wheel = registerBlock("steering_wheel", @@ -26,19 +31,25 @@ public class modBlocks { new gridBlock(FabricBlockSettings.of(Material.WOOD).strength(1.0f).requiresTool()), modItemGroup.modchest); + denk_mal_block = registerBlock("denk_mal_block", + new denkMalBlock(FabricBlockSettings.of(Material.METAL).strength(4.0f).requiresTool().luminance((state) -> state.get(denkMalBlock.POWERED) ? 5 : 0).nonOpaque()), + modItemGroup.modchest); + + denk_mal_block_placeholder = registerBlockWithoutItem("denk_mal_block_placeholder", + new denkMalBlockPlaceholder(FabricBlockSettings.of(Material.METAL).strength(4.0f).requiresTool().nonOpaque())); + } - - - - private static Block registerBlock(String name, Block block, ItemGroup group) { // Nicht verändern! Fügt die oben - // definierten Blöcke dem Register - // hinzu + private static Block registerBlock(String name, Block block, ItemGroup group) { // Nicht verändern! Fügt die oben definierten Blöcke dem Register hinzu Registry.register(Registry.ITEM, new Identifier(REServerMod.MOD_ID, name), new BlockItem(block, new FabricItemSettings().group(group))); return Registry.register(Registry.BLOCK, new Identifier(REServerMod.MOD_ID, name), block); } + private static Block registerBlockWithoutItem(String name, Block block) { // Nicht verändern! Fügt die oben definierten Blöcke dem Register hinzu + return Registry.register(Registry.BLOCK, new Identifier(REServerMod.MOD_ID, name), block); + } + public static void registerModBlocks() { // Error Logger halt... REServerMod.LOGGER.info("Registering ModBlocks for " + REServerMod.MOD_ID); } diff --git a/src/main/java/modchest/event/playerBreakBlockEvents.java b/src/main/java/modchest/event/playerBreakBlockEvents.java new file mode 100644 index 0000000..1fabcf5 --- /dev/null +++ b/src/main/java/modchest/event/playerBreakBlockEvents.java @@ -0,0 +1,18 @@ +package modchest.event; + +import modchest.util.denkMalBlockUtil; +import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +public class playerBreakBlockEvents implements PlayerBlockBreakEvents.Before { + @Override + public boolean beforeBlockBreak(World world, PlayerEntity player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity) { + denkMalBlockUtil util = new denkMalBlockUtil(); + return util.allowBlocks(world, player, pos); + } +} diff --git a/src/main/java/modchest/item/custom/denkMalItem.java b/src/main/java/modchest/item/custom/denkMalItem.java new file mode 100644 index 0000000..94c1df4 --- /dev/null +++ b/src/main/java/modchest/item/custom/denkMalItem.java @@ -0,0 +1,56 @@ +package modchest.item.custom; + +import net.fabricmc.fabric.api.item.v1.FabricItemSettings; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.World; +import oshi.annotation.concurrent.ThreadSafe; + +import static modchest.block.modBlocks.denk_mal_block; + +public class denkMalItem extends Item { + World thisWorld; + boolean used = false; + + public denkMalItem(FabricItemSettings fabricItemSettings) { + super(fabricItemSettings); + } + + public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { + if (thisWorld != null) { + if (entity.getType().toString().equals("entity.minecraft.elder_guardian")) { + user.sendMessage(Text.of(String.valueOf(Registry.BLOCK.getId(denk_mal_block)))); + entity.kill(); + if (!entity.isAlive()) { + BlockPos pos = new BlockPos((int) entity.getPos().getX(), ((int) entity.getPos().getY()), (int) entity.getPos().getZ()); + try { + BlockState state = denk_mal_block.getDefaultState(); + thisWorld.setBlockState(pos, state, Block.NOTIFY_ALL); + } catch (Exception e) { + user.sendMessage((Text) e); + } + } + return ActionResult.SUCCESS; + + } + } + return ActionResult.PASS; + } + + public TypedActionResult use(World world, PlayerEntity user, Hand hand) { //wird vor useOnEntity aufgerufen + thisWorld = world; + return TypedActionResult.pass(user.getStackInHand(hand)); + } +} diff --git a/src/main/java/modchest/item/modItems.java b/src/main/java/modchest/item/modItems.java index 92e9596..5bd86a2 100644 --- a/src/main/java/modchest/item/modItems.java +++ b/src/main/java/modchest/item/modItems.java @@ -1,6 +1,7 @@ package modchest.item; import modchest.REServerMod; +import modchest.item.custom.denkMalItem; import modchest.item.custom.piratesCoinItem; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.item.Item; @@ -9,19 +10,22 @@ import net.minecraft.util.registry.Registry; //Liste der Items die hinzugefügt werden, ausgenommen Blöcke public class modItems { - public static Item shipblock; // shipblock wird erstellt, sollte man mal umbenenne. Ist eine Zutat die man für - // das steering_wheel braucht zum craften, mehr macht es bisher nicht - public static Item pirates_coin; // pirates Coin wird erstellt; definition siehe ./custom/piratesCoinItem da ist - // im detail erklärt was das Item machen soll + private static Item shipblock; // shipblock wird erstellt, sollte man mal umbenenne. Ist eine Zutat die man für + // das steering_wheel braucht zum craften, mehr macht es bisher nicht + private static Item pirates_coin; // pirates Coin wird erstellt; definition siehe ./custom/piratesCoinItem da ist + // im detail erklärt was das Item machen soll + private static Item denk_mal_item; public static void setItems() { // Items werden beschrieben, bzw. dem Register hinzugefügt shipblock = registerItem("shipblock", new Item(new FabricItemSettings().group(modItemGroup.modchest))); pirates_coin = registerItem("pirates_coin", new piratesCoinItem(new FabricItemSettings().group(modItemGroup.modchest).maxCount(16))); + denk_mal_item = registerItem("denk_mal_item", + new denkMalItem(new FabricItemSettings().group(modItemGroup.modchest).maxCount(1))); } private static Item registerItem(String name, Item item) { // Methode, die die Items dann letztendlich hinzufügt; - // nicht bearbeiten ist eine generische MEthode + // nicht bearbeiten ist eine generische MEthode return Registry.register(Registry.ITEM, new Identifier(REServerMod.MOD_ID, name), item); } diff --git a/src/main/java/modchest/mixin/LevelStorageMixin.java b/src/main/java/modchest/mixin/LevelStorageMixin.java new file mode 100644 index 0000000..b878262 --- /dev/null +++ b/src/main/java/modchest/mixin/LevelStorageMixin.java @@ -0,0 +1,29 @@ +package modchest.mixin; + +import modchest.REServerMod; +import modchest.util.interfaces.LevelStorageInterface; +import net.minecraft.world.level.storage.LevelStorage; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import net.minecraft.world.level.storage.LevelStorage.Session; + +import java.io.File; + +@Mixin(Session.class) +public abstract class LevelStorageMixin implements LevelStorageInterface { + + @Final + @Shadow + LevelStorage.LevelSave directory; + + public File getFile() { //gibt den Dateipfad zurueck + File dateiPfad = null; + try { + dateiPfad = directory.path().toFile(); //Versucht den Dateipfad einzulesen; weil es sehr frueh kommt besonders abgesichert + } catch (Exception e) { + REServerMod.LOGGER.info("Error when trying to read File path: {}", e.toString()); + } + return dateiPfad; + } +} \ No newline at end of file diff --git a/src/main/java/modchest/mixin/MinecraftServerMixin.java b/src/main/java/modchest/mixin/MinecraftServerMixin.java new file mode 100644 index 0000000..9060d51 --- /dev/null +++ b/src/main/java/modchest/mixin/MinecraftServerMixin.java @@ -0,0 +1,49 @@ +package modchest.mixin; + +import modchest.REServerMod; +import modchest.util.interfaces.LevelStorageInterface; +import modchest.util.dataSaverIO; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.storage.LevelStorage; +import org.spongepowered.asm.mixin.Final; +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; + +import java.io.File; + +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + @Shadow + @Final + protected LevelStorage.Session session; + @Unique + dataSaverIO dataSaver = new dataSaverIO(); + + @Inject(method = "prepareStartRegion", at = @At("TAIL")) + private void prepareStartRegion(CallbackInfo ci) { //wird beim Start des Servers aufgerufen + dataSaver.resetData(); //stellt sicher, dass keine Daten von einer Welt in eine andere "leaken" in dem es alle Daten loescht + LevelStorageInterface levelStorage = (LevelStorageInterface) session; //castet session mit dem Interface, damit custom Methoden verwendet werden koennen + try { + File file; + file = levelStorage.getFile(); //holt sich den Dateipfad + if (file != null) { + dataSaver.writeFilePath(file); //schreibt den Dateipfad der Welt fuer das dataSaverIO + dataSaver.readFile(); //holt die Daten von der Festplatte in den RAM + } else { + REServerMod.LOGGER.info("file is zero"); + } + } catch (Exception e) { + REServerMod.LOGGER.info("file could not be read with Exception: {}", e.toString()); + } + } + + @Inject(method = "shutdown", at = @At("HEAD")) + private void shutdown(CallbackInfo ci) { //is called when server shuts down + dataSaver.saveFile(); //Saves the Serverdata + } +} + diff --git a/src/main/java/modchest/mixin/ServerPlayerEntityMixin.java b/src/main/java/modchest/mixin/ServerPlayerEntityMixin.java index 635dbb7..2a73889 100644 --- a/src/main/java/modchest/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/modchest/mixin/ServerPlayerEntityMixin.java @@ -1,7 +1,7 @@ package modchest.mixin; import modchest.REServerMod; -import modchest.util.ServerPlayerEntityInterface; +import modchest.util.interfaces.ServerPlayerEntityInterface; import net.minecraft.nbt.NbtCompound; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; @@ -10,8 +10,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Arrays; - @Mixin(ServerPlayerEntity.class) public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInterface { @Unique @@ -39,7 +37,7 @@ public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInter REServerMod.LOGGER.info("Error while saving custom NBt-Data: " + e); } } else { - REServerMod.LOGGER.info("write failed! This probably means, that the player hasn't set a custom spanpoint yet"); + REServerMod.LOGGER.info("write failed! This probably means, that the player hasn't set a custom spawnpoint yet"); } } diff --git a/src/main/java/modchest/mixin/bedBlock.java b/src/main/java/modchest/mixin/bedBlockMixin.java similarity index 98% rename from src/main/java/modchest/mixin/bedBlock.java rename to src/main/java/modchest/mixin/bedBlockMixin.java index a995ba4..ec20832 100644 --- a/src/main/java/modchest/mixin/bedBlock.java +++ b/src/main/java/modchest/mixin/bedBlockMixin.java @@ -5,7 +5,6 @@ import modchest.util.setAndGetMultiButtonsSpawn; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -14,12 +13,11 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Arrays; import java.util.List; import java.util.Objects; @Mixin(BedBlock.class) -public class bedBlock { +public class bedBlockMixin { @Inject(method = "onBreak", at = @At("HEAD")) public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci) { //Ueberprueft, wenn ein Bett zerstoert wird, ob jemand dieses Bett als Spawnpunkt hat diff --git a/src/main/java/modchest/mixin/flintAndSteelItemMixin.java b/src/main/java/modchest/mixin/flintAndSteelItemMixin.java new file mode 100644 index 0000000..b64ad73 --- /dev/null +++ b/src/main/java/modchest/mixin/flintAndSteelItemMixin.java @@ -0,0 +1,41 @@ +package modchest.mixin; + +import modchest.REServerMod; +import modchest.util.denkMalBlockUtil; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.FlintAndSteelItem; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.util.ActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +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.CallbackInfoReturnable; + +@Mixin(FlintAndSteelItem.class) +public class flintAndSteelItemMixin { + + @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) + public void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { + if(!callPlaceable(context)) { + cir.setReturnValue(ActionResult.FAIL); + } + } + + @Unique + private boolean callPlaceable(ItemUsageContext context) { + try { + PlayerEntity player = context.getPlayer(); + World world = context.getWorld(); + BlockPos pos = context.getBlockPos(); + denkMalBlockUtil util = new denkMalBlockUtil(); + return util.allowBlocks(world, player, pos); + } catch (Exception e) { + REServerMod.LOGGER.info("Exception in variables: " + e.toString()); + } + return false; + } + +} diff --git a/src/main/java/modchest/mixin/itemMixin.java b/src/main/java/modchest/mixin/itemMixin.java new file mode 100644 index 0000000..61f1886 --- /dev/null +++ b/src/main/java/modchest/mixin/itemMixin.java @@ -0,0 +1,41 @@ +package modchest.mixin; + +import modchest.REServerMod; +import modchest.util.denkMalBlockUtil; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.util.ActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +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.CallbackInfoReturnable; + +@Mixin(Item.class) +public class itemMixin { + + @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) + public void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { + if(!callPlaceable(context)) { + cir.setReturnValue(ActionResult.FAIL); + } + } + + @Unique + private boolean callPlaceable(ItemUsageContext context) { + try { + PlayerEntity player = context.getPlayer(); + World world = context.getWorld(); + BlockPos pos = context.getBlockPos(); + denkMalBlockUtil util = new denkMalBlockUtil(); + return util.allowBlocks(world, player, pos); + } catch (Exception e) { + REServerMod.LOGGER.info("Exception in variables: " + e.toString()); + } + return false; + } + +} diff --git a/src/main/java/modchest/mixin/playerPlaceBlockMixin.java b/src/main/java/modchest/mixin/playerPlaceBlockMixin.java new file mode 100644 index 0000000..a33512b --- /dev/null +++ b/src/main/java/modchest/mixin/playerPlaceBlockMixin.java @@ -0,0 +1,34 @@ +package modchest.mixin; + +import modchest.util.denkMalBlockUtil; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.util.ActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +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.CallbackInfoReturnable; + +@Mixin(BlockItem.class) +public class playerPlaceBlockMixin { + @Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", at = @At("HEAD"), cancellable = true) + public void canPlace(ItemPlacementContext context, CallbackInfoReturnable cir) { + if(!callPlaceable(context)) { + cir.setReturnValue(ActionResult.FAIL); + } + } + + @Unique + private boolean callPlaceable(ItemPlacementContext context) { + PlayerEntity player = context.getPlayer(); + World world = context.getWorld(); + BlockPos pos = context.getBlockPos(); + + denkMalBlockUtil util = new denkMalBlockUtil(); + return util.allowBlocks(world, player, pos); + } +} diff --git a/src/main/java/modchest/networking/modNetworkingServer.java b/src/main/java/modchest/networking/modNetworkingServer.java index 64f771d..c680b33 100644 --- a/src/main/java/modchest/networking/modNetworkingServer.java +++ b/src/main/java/modchest/networking/modNetworkingServer.java @@ -11,7 +11,7 @@ public class modNetworkingServer { //Identifier werden eingeführt public static final Identifier start_sleeping_call_buttons = new Identifier(REServerMod.MOD_ID, "start_sleeping_call_buttons"); public static final Identifier death_multi_respawn_buttons = new Identifier(REServerMod.MOD_ID, "death_call_respawn_buttons"); - public static void registerS2CPackets() { //Identifier fuer packets werden registriert (Identifier die der Client aufruft um beim Server was auszufuehren) + public static void registerC2SPackets() { //Identifier fuer packets werden registriert (Identifier die der Client aufruft um beim Server was auszufuehren) ServerPlayNetworking.registerGlobalReceiver(start_sleeping_call_buttons, setNewRespawnsC2SPacket::receive); //was der Server dann machen soll steht in der receive Methode ServerPlayNetworking.registerGlobalReceiver(death_multi_respawn_buttons, deathScreenMultiButtonsC2SPacket::receive); diff --git a/src/main/java/modchest/util/dataSaverIO.java b/src/main/java/modchest/util/dataSaverIO.java new file mode 100644 index 0000000..7e2ba40 --- /dev/null +++ b/src/main/java/modchest/util/dataSaverIO.java @@ -0,0 +1,68 @@ +package modchest.util; + +import modchest.REServerMod; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtIo; + +import java.io.*; + +public class dataSaverIO { //Speichert alles mod-relevanten Serverdaten ab + private static File reServerFile = null; + private static NbtCompound reServerNbt = null; + + public dataSaverIO() {} + + void readFromFile() { //laedt die Daten der Datei; macht der Server bereits automatisch, danke mixin! + try { + reServerNbt = NbtIo.read(reServerFile); //liest die Datei + if (reServerNbt == null) { //sollte der Nbt-Tag noch nciht existieren, wird er erstellt + reServerNbt = new NbtCompound(); + } + } catch (IOException e) { //sollte das IO einen Fehler haben, sollte aber nie vorkommen, wird die mod versuchen es zu fixen, indem sie einen neuen NbtTag erstellt und mit dem weiter arbeitet + REServerMod.LOGGER.error("Error when trying to read from file: " + String.valueOf(e) + " trying to fix it by making a new Nbt"); + reServerNbt = new NbtCompound(); + } catch (Exception e) { //alle anderen exception, versucht er genau so zu fixen. Loescht alle alten Daten, aber besser, als das die Mod garnicht mehr geht + reServerNbt = new NbtCompound(); + } + } + + void writeToFile() { //speichert den Nbt-Tag als Datei ab; macht der Server auch automatisch + reServerNbt.putInt("NullSafety", 1); //gibt manchmal Probleme wenn nichts im Nbt-Tag steht, deswegen wird hin und wieder mal eine NullSafety abgespeichert + try { + if (reServerNbt != null) { //stellt sicher, das auch wirklich wirklich was im NbtTag steht vor dem abspeichern + NbtIo.write(reServerNbt, reServerFile); + } + } catch (Exception e) { + REServerMod.LOGGER.error("Error when trying to write to file: " + String.valueOf(e)); + } + } + + public void writeToNbt(NbtCompound nbt) { //ueberschreibt den ServerNbt-Tag, pass auf, dass du nicht sachen von anderen Teilen der mods vergisst mit zu kopieren! + reServerNbt = nbt; + } + + public NbtCompound getFromNbt() { //uebergibt den servernbt + if (reServerNbt == null) { //sollte der server-nbt-tag noch nciht existieren, wird er neu erstellt + REServerMod.LOGGER.error("ServerNbt ist null in getFromNbt!"); //eigentlich sollte es nicht auftreten... + reServerNbt = new NbtCompound(); + } + return reServerNbt; + } + + public void readFile() { //public version, den servernbt von der Datei einzulesen + readFromFile(); + } + + public void saveFile() { //moeglichkeit, die datei force-abzuspeichern + writeToFile(); + } + + public void writeFilePath(File file) { //setzt den Pfad fuer den Server-Nbt-Tag wird vom server dank mixin automatisch gesetzt + reServerFile = new File(file, "REServerMod" + ".dat"); + } + + public void resetData() { //resets the data of this class + reServerFile = null; + reServerNbt = new NbtCompound(); + } +} \ No newline at end of file diff --git a/src/main/java/modchest/util/denkMalBlockUtil.java b/src/main/java/modchest/util/denkMalBlockUtil.java new file mode 100644 index 0000000..da9bac4 --- /dev/null +++ b/src/main/java/modchest/util/denkMalBlockUtil.java @@ -0,0 +1,84 @@ +package modchest.util; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import java.util.Arrays; +import java.util.Set; + +import static java.lang.Math.abs; + +public class denkMalBlockUtil extends dataSaverIO{ + + public denkMalBlockUtil() {} + + + public void addBlock(int[] pos, int[] range) { //fuegt bloecke der Liste an abbauverhindernden Bloecke hinzu + NbtCompound tempNbt = new NbtCompound(); //Nbt in dem die Blockdaten gespeichert werden + NbtCompound nbt = returnLoadedNbt(); //holt sich den denkmalblock nbt + tempNbt.putIntArray("position", pos); + tempNbt.putIntArray("range", range); + nbt.put(Arrays.toString(pos), tempNbt); //speichert die daten des neuen Blocks ab + saveInNbt(nbt); //speichert den editierten denkmalblock-nbt ab + } + + public void removeBlock(int[] posString) { //loescht bloecke aus Liste an abbauverhindernden Bloecken + NbtCompound nbt = returnLoadedNbt(); //holt sich den denkmalblock nbt + nbt.remove(Arrays.toString(posString)); //entfernt diesen block + saveInNbt(nbt); //speichert den editierten denkmalblock-nbt ab + } + + private NbtCompound returnLoadedNbt() { //gibt den denkmalblock nbt zurueck + NbtCompound nbt = getFromNbt(); //laedt den gesamten reServerNbt + nbt = (NbtCompound) nbt.get("denkmalblock");//nimmt den denkmalblocknbt und laedt diesen + if (nbt == null) { //sollte der nbt noch nicht existieren wird er erstellt + nbt = new NbtCompound(); + } + return nbt; + } + + private void saveInNbt(NbtCompound nbt) { //speichert den denkmalblock nbt im reServerNbt ab + NbtCompound reServerNbt = getFromNbt(); //holt den reServerNbt + reServerNbt.put("denkmalblock", nbt); //schreibt den denkmalblock nbt ab + writeToNbt(reServerNbt); //schreibt den editierten reServerNbt + } + + public boolean allowBlocks(World world, PlayerEntity player, BlockPos pos) { + if (world.getRegistryKey() == World.OVERWORLD) { + if (!player.isCreative()) { + NbtCompound nbt = returnLoadedNbt(); + Set set = nbt.getKeys(); + String[] keys = set.toArray(new String[0]);//erzeugt einen String-Array mit allen keys + + for (String key : keys) { + if (inRange((NbtCompound) nbt.get(key), pos)) { + if (!world.isClient) { + player.sendMessage(Text.of("Can't change Blocks here! This area is protected!")); + } + return false; + } + } + } + } + return true; + } + + private boolean inRange(NbtCompound nbt, BlockPos pos) { + int[] denkPos = nbt.getIntArray("position"); + int[] denkRange = nbt.getIntArray("range"); + int[] blockPos = new int[3]; + blockPos[0] = pos.getX(); + blockPos[1] = pos.getY(); + blockPos[2] = pos.getZ(); + for(int i = 0; i < 3; i++) { + int dif = (denkPos[i] - blockPos[i]); + if (abs(dif) > denkRange[i]) { + return false; + } + } + return true; + } +} diff --git a/src/main/java/modchest/util/initializer.java b/src/main/java/modchest/util/initializer.java index 6308369..7ad0cb5 100644 --- a/src/main/java/modchest/util/initializer.java +++ b/src/main/java/modchest/util/initializer.java @@ -3,10 +3,12 @@ package modchest.util; import modchest.block.entity.modBlockEntities; import modchest.block.modBlocks; import modchest.event.playerAfterRespawnEvent; +import modchest.event.playerBreakBlockEvents; import modchest.item.modItemGroup; import modchest.item.modItems; import modchest.networking.modNetworkingServer; import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; +import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; public class initializer { public static void itemGroups() { @@ -22,9 +24,15 @@ public class initializer { public static void events() { //Events, bei denen custom Code ausgefuehrt wird, werden eingefuehrt ServerPlayerEvents.AFTER_RESPAWN.register(new playerAfterRespawnEvent()); + PlayerBlockBreakEvents.BEFORE.register(new playerBreakBlockEvents()); } public static void networking() { //Identifier unter denen der Server zuhoert werden registriert - modNetworkingServer.registerS2CPackets(); + modNetworkingServer.registerC2SPackets(); + } + + public static void renderer() { + //BlockRenderLayerMap.INSTANCE.putBlock(modBlocks.denk_mal_block, RenderLayer.getTranslucent()); + } } diff --git a/src/main/java/modchest/util/interfaces/LevelStorageInterface.java b/src/main/java/modchest/util/interfaces/LevelStorageInterface.java new file mode 100644 index 0000000..420d02d --- /dev/null +++ b/src/main/java/modchest/util/interfaces/LevelStorageInterface.java @@ -0,0 +1,7 @@ +package modchest.util.interfaces; + +import java.io.File; + +public interface LevelStorageInterface { //Interface, damit der Server den Pfad holen kann + File getFile(); +} diff --git a/src/main/java/modchest/util/ServerPlayerEntityInterface.java b/src/main/java/modchest/util/interfaces/ServerPlayerEntityInterface.java similarity index 57% rename from src/main/java/modchest/util/ServerPlayerEntityInterface.java rename to src/main/java/modchest/util/interfaces/ServerPlayerEntityInterface.java index 2f43ab9..36e11dd 100644 --- a/src/main/java/modchest/util/ServerPlayerEntityInterface.java +++ b/src/main/java/modchest/util/interfaces/ServerPlayerEntityInterface.java @@ -1,8 +1,6 @@ -package modchest.util; +package modchest.util.interfaces; import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.network.ServerPlayerEntity; -import org.spongepowered.asm.mixin.Unique; public interface ServerPlayerEntityInterface { NbtCompound getDataSaver(); diff --git a/src/main/java/modchest/util/setAndGetMultiButtonsSpawn.java b/src/main/java/modchest/util/setAndGetMultiButtonsSpawn.java index 7ee7e51..19e1554 100644 --- a/src/main/java/modchest/util/setAndGetMultiButtonsSpawn.java +++ b/src/main/java/modchest/util/setAndGetMultiButtonsSpawn.java @@ -1,8 +1,8 @@ package modchest.util; import modchest.REServerMod; +import modchest.util.interfaces.ServerPlayerEntityInterface; import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; diff --git a/src/main/resources/assets/modchest/blockstates/denk_mal_block.json b/src/main/resources/assets/modchest/blockstates/denk_mal_block.json new file mode 100644 index 0000000..8ddebca --- /dev/null +++ b/src/main/resources/assets/modchest/blockstates/denk_mal_block.json @@ -0,0 +1,10 @@ +{ + "variants": { + "powered=false": { + "model": "modchest:block/denk_mal_block_aus" + }, + "powered=true": { + "model": "modchest:block/denk_mal_block_an" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/modchest/blockstates/denk_mal_block_placeholder.json b/src/main/resources/assets/modchest/blockstates/denk_mal_block_placeholder.json new file mode 100644 index 0000000..3ee1c2c --- /dev/null +++ b/src/main/resources/assets/modchest/blockstates/denk_mal_block_placeholder.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "modchest:block/denk_mal_block_placeholder" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/modchest/models/block/denk_mal_block_an.json b/src/main/resources/assets/modchest/models/block/denk_mal_block_an.json new file mode 100644 index 0000000..ac919e1 --- /dev/null +++ b/src/main/resources/assets/modchest/models/block/denk_mal_block_an.json @@ -0,0 +1,89 @@ +{ + "parent": "block/cube_all", + "credit": "Made with Blockbench", + "texture_size": [64, 64], + "textures": { + "1": "modchest:block/denk_mal_block", + "2": "modchest:block/denk_mal_block_kern_an", + "3": "modchest:block/denk_mal_block_basis", + "particle": "modchest:block/denk_mal_block_kern_aus" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 16, 16], + "faces": { + "north": {"uv": [0, 0, 4, 4], "texture": "#3"}, + "east": {"uv": [0, 4, 4, 8], "texture": "#3"}, + "south": {"uv": [4, 0, 8, 4], "texture": "#3"}, + "west": {"uv": [4, 4, 8, 8], "texture": "#3"}, + "up": {"uv": [4, 12, 0, 8], "texture": "#3"}, + "down": {"uv": [12, 0, 8, 4], "texture": "#3"} + } + }, + { + "from": [0, 16, 0], + "to": [16, 32, 16], + "faces": { + "north": {"uv": [0, 0, 4, 4], "texture": "#1"}, + "east": {"uv": [0, 4, 4, 8], "texture": "#1"}, + "south": {"uv": [4, 0, 8, 4], "texture": "#1"}, + "west": {"uv": [4, 4, 8, 8], "texture": "#1"}, + "up": {"uv": [4, 12, 0, 8], "texture": "#1"}, + "down": {"uv": [12, 0, 8, 4], "texture": "#1"} + } + }, + { + "from": [3, 18, 3], + "to": [13, 29, 13], + "faces": { + "north": {"uv": [0, 0, 5, 5.5], "texture": "#2"}, + "east": {"uv": [5, 0, 10, 5.5], "texture": "#2"}, + "south": {"uv": [0, 5.5, 5, 11], "texture": "#2"}, + "west": {"uv": [5, 5.5, 10, 11], "texture": "#2"}, + "up": {"uv": [15, 5, 10, 0], "texture": "#2"}, + "down": {"uv": [15, 5, 10, 10], "texture": "#2"} + } + } + ], + "display": { + "thirdperson_righthand": { + "scale": [0.5, 0.5, 0.5] + }, + "thirdperson_lefthand": { + "scale": [0.5, 0.5, 0.5] + }, + "firstperson_righthand": { + "rotation": [1, 0, 0], + "translation": [2.5, -1.5, 0], + "scale": [0.5, 0.5, 0.5] + }, + "firstperson_lefthand": { + "translation": [2.5, -1.5, 0], + "scale": [0.5, 0.5, 0.5] + }, + "ground": { + "scale": [0.5, 0.5, 0.5] + }, + "gui": { + "translation": [0, -3.25, 0], + "scale": [0.5, 0.5, 0.5] + }, + "head": { + "translation": [0, 11.5, 0], + "scale": [0.5, 0.5, 0.5] + }, + "fixed": { + "translation": [0, -1.75, 0], + "scale": [0.5, 0.5, 0.5] + } + }, + "groups": [ + { + "name": "VoxelShapes", + "origin": [8, 8, 8], + "color": 0, + "children": [0, 1, 2] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/modchest/models/block/denk_mal_block_aus.json b/src/main/resources/assets/modchest/models/block/denk_mal_block_aus.json new file mode 100644 index 0000000..49bd344 --- /dev/null +++ b/src/main/resources/assets/modchest/models/block/denk_mal_block_aus.json @@ -0,0 +1,89 @@ +{ + "parent": "block/cube_all", + "credit": "Made with Blockbench", + "texture_size": [64, 64], + "textures": { + "1": "modchest:block/denk_mal_block", + "2": "modchest:block/denk_mal_block_kern_aus", + "3": "modchest:block/denk_mal_block_basis", + "particle": "modchest:block/denk_mal_block_kern_aus" + }, + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 16, 16], + "faces": { + "north": {"uv": [0, 0, 4, 4], "texture": "#3"}, + "east": {"uv": [0, 4, 4, 8], "texture": "#3"}, + "south": {"uv": [4, 0, 8, 4], "texture": "#3"}, + "west": {"uv": [4, 4, 8, 8], "texture": "#3"}, + "up": {"uv": [4, 12, 0, 8], "texture": "#3"}, + "down": {"uv": [12, 0, 8, 4], "texture": "#3"} + } + }, + { + "from": [0, 16, 0], + "to": [16, 32, 16], + "faces": { + "north": {"uv": [0, 0, 4, 4], "texture": "#1"}, + "east": {"uv": [0, 4, 4, 8], "texture": "#1"}, + "south": {"uv": [4, 0, 8, 4], "texture": "#1"}, + "west": {"uv": [4, 4, 8, 8], "texture": "#1"}, + "up": {"uv": [4, 12, 0, 8], "texture": "#1"}, + "down": {"uv": [12, 0, 8, 4], "texture": "#1"} + } + }, + { + "from": [3, 18, 3], + "to": [13, 29, 13], + "faces": { + "north": {"uv": [0, 0, 5, 5.5], "texture": "#2"}, + "east": {"uv": [5, 0, 10, 5.5], "texture": "#2"}, + "south": {"uv": [0, 5.5, 5, 11], "texture": "#2"}, + "west": {"uv": [5, 5.5, 10, 11], "texture": "#2"}, + "up": {"uv": [15, 5, 10, 0], "texture": "#2"}, + "down": {"uv": [15, 5, 10, 10], "texture": "#2"} + } + } + ], + "display": { + "thirdperson_righthand": { + "scale": [0.5, 0.5, 0.5] + }, + "thirdperson_lefthand": { + "scale": [0.5, 0.5, 0.5] + }, + "firstperson_righthand": { + "rotation": [1, 0, 0], + "translation": [2.5, -1.5, 0], + "scale": [0.5, 0.5, 0.5] + }, + "firstperson_lefthand": { + "translation": [2.5, -1.5, 0], + "scale": [0.5, 0.5, 0.5] + }, + "ground": { + "scale": [0.5, 0.5, 0.5] + }, + "gui": { + "translation": [0, -3.25, 0], + "scale": [0.5, 0.5, 0.5] + }, + "head": { + "translation": [0, 11.5, 0], + "scale": [0.5, 0.5, 0.5] + }, + "fixed": { + "translation": [0, -1.75, 0], + "scale": [0.5, 0.5, 0.5] + } + }, + "groups": [ + { + "name": "VoxelShapes", + "origin": [8, 8, 8], + "color": 0, + "children": [0, 1, 2] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/modchest/models/block/denk_mal_block_placeholder.json b/src/main/resources/assets/modchest/models/block/denk_mal_block_placeholder.json new file mode 100644 index 0000000..fe5d622 --- /dev/null +++ b/src/main/resources/assets/modchest/models/block/denk_mal_block_placeholder.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "particle": "modchest:block/denk_mal_block" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/modchest/models/item/denk_mal_block.json b/src/main/resources/assets/modchest/models/item/denk_mal_block.json new file mode 100644 index 0000000..463b561 --- /dev/null +++ b/src/main/resources/assets/modchest/models/item/denk_mal_block.json @@ -0,0 +1,3 @@ +{ + "parent": "modchest:block/denk_mal_block_aus" +} \ No newline at end of file diff --git a/src/main/resources/assets/modchest/textures/block/denk_mal_block.png b/src/main/resources/assets/modchest/textures/block/denk_mal_block.png new file mode 100644 index 0000000..8db9cf0 Binary files /dev/null and b/src/main/resources/assets/modchest/textures/block/denk_mal_block.png differ diff --git a/src/main/resources/assets/modchest/textures/block/denk_mal_block_basis.png b/src/main/resources/assets/modchest/textures/block/denk_mal_block_basis.png new file mode 100644 index 0000000..36763a6 Binary files /dev/null and b/src/main/resources/assets/modchest/textures/block/denk_mal_block_basis.png differ diff --git a/src/main/resources/assets/modchest/textures/block/denk_mal_block_kern_an.png b/src/main/resources/assets/modchest/textures/block/denk_mal_block_kern_an.png new file mode 100644 index 0000000..0335f71 Binary files /dev/null and b/src/main/resources/assets/modchest/textures/block/denk_mal_block_kern_an.png differ diff --git a/src/main/resources/assets/modchest/textures/block/denk_mal_block_kern_aus.png b/src/main/resources/assets/modchest/textures/block/denk_mal_block_kern_aus.png new file mode 100644 index 0000000..1133eb5 Binary files /dev/null and b/src/main/resources/assets/modchest/textures/block/denk_mal_block_kern_aus.png differ diff --git a/src/main/resources/reservermod.mixins.json b/src/main/resources/reservermod.mixins.json index 62856ee..c132e08 100644 --- a/src/main/resources/reservermod.mixins.json +++ b/src/main/resources/reservermod.mixins.json @@ -3,8 +3,13 @@ "package": "modchest.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ServerPlayerEntityMixin", - "bedBlock" + "bedBlockMixin", + "flintAndSteelItemMixin", + "itemMixin", + "LevelStorageMixin", + "MinecraftServerMixin", + "playerPlaceBlockMixin", + "ServerPlayerEntityMixin" ], "injectors": { "defaultRequire": 1