optimize code

This commit is contained in:
Rasmus Moorats 2022-04-07 11:57:25 +03:00
parent 14d58eb3dd
commit 454a1968f2
Signed by: xx
GPG key ID: FE14255A6AE7241C
4 changed files with 34 additions and 44 deletions
LICENSE
src/main
java/ee/nns/hiddenhydration
resources

24
LICENSE Normal file
View file

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

View file

@ -1,21 +0,0 @@
package ee.nns.hiddenhydration;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HiddenHydration implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("hiddenhydration");
@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.
LOGGER.info("Hidden Hydration loaded");
}
}

View file

@ -1,6 +1,5 @@
package ee.nns.hiddenhydration.mixin;
import ee.nns.hiddenhydration.HiddenHydration;
import net.minecraft.block.FarmlandBlock;
import net.minecraft.tag.FluidTags;
import net.minecraft.util.math.BlockPos;
@ -8,29 +7,23 @@ import net.minecraft.world.WorldView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Iterator;
@Mixin(FarmlandBlock.class)
public class HiddenHydrationMixin {
@Redirect(
method = "randomTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Ljava/util/Random;)V",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/block/FarmlandBlock;isWaterNearby(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z"
)
)
@Redirect(method = "randomTick(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Ljava/util/Random;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FarmlandBlock;isWaterNearby(Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;)Z"))
boolean isWaterNearbyInjected(WorldView world, BlockPos pos) {
Iterator var2 = BlockPos.iterate(pos.add(-4, -1, -4), pos.add(4, 1, 4)).iterator();
Iterator i = BlockPos.iterate(pos.add(-4, -1, -4), pos.add(4, 1, 4)).iterator();
BlockPos blockPos;
do {
if (!var2.hasNext()) {
return false;
}
BlockPos blockPos;
do {
if (!i.hasNext()) {
return false;
}
blockPos = (BlockPos)var2.next();
} while(!world.getFluidState(blockPos).isIn(FluidTags.WATER));
blockPos = (BlockPos) i.next();
} while (!world.getFluidState(blockPos).isIn(FluidTags.WATER));
return true;
}

View file

@ -12,13 +12,10 @@
"sources": "https://koodirepo.ee/xx/hidden-hydration"
},
"license": "CC0-1.0",
"license": "Unlicense",
"environment": "*",
"entrypoints": {
"main": [
"ee.nns.hiddenhydration.HiddenHydration"
]
},
"mixins": [
"hiddenhydration.mixins.json"
@ -29,8 +26,5 @@
"fabric": "*",
"minecraft": "1.18.x",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
}
}