Compare commits
34 Commits
be6472cc79
...
1.21.4
Author | SHA1 | Date | |
---|---|---|---|
92e9c996b9 | |||
dd50ff0376 | |||
d2fd497f26 | |||
a6f8645c68 | |||
2be7c16e8b | |||
ccbb15f7c4 | |||
05a93b5ab0 | |||
327c92a81c | |||
29067365ca | |||
1ae193ada7 | |||
151fd022c4 | |||
deb338f2c8 | |||
61d2a0b137 | |||
35148c2159 | |||
ef29652e07 | |||
ee448ae34d | |||
69df0e5850 | |||
4988a91e70 | |||
8808df1cf1 | |||
963002570d | |||
2c95b5e374 | |||
1d3dba1b02 | |||
c7ea933494 | |||
563febe36f | |||
38a244b023 | |||
868e71eb10 | |||
2a106c9a03 | |||
1d0f7f0f05 | |||
52a97dc2c1 | |||
5916cc5cc2 | |||
4e58bede4b | |||
130b2db727 | |||
c993621bdb | |||
b89ab99928 |
53
README.md
53
README.md
@ -8,18 +8,17 @@ As a challenge I'm trying to make it as user-friendly as possible.
|
||||
|
||||
## Server Side
|
||||
|
||||
### Features
|
||||
- Custom join message
|
||||

|
||||

|
||||
- Custom quit message
|
||||

|
||||

|
||||
- Custom chat message
|
||||

|
||||

|
||||
- Tab list dimension indicator
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
- Config
|
||||
- Configurable messages
|
||||
- Feature toggle
|
||||
@ -29,8 +28,14 @@ As a challenge I'm trying to make it as user-friendly as possible.
|
||||
- Open/close EC block while opening/closing SEC
|
||||
- Play open & close sounds
|
||||
- Vein miner
|
||||

|
||||
- Configurable animation (tick delay)
|
||||
- Leaves veinmineable using shears
|
||||
Code inspired by Inferis!
|
||||

|
||||
- Chat Calculator
|
||||
- Check if operator is present before calculating
|
||||
- Replenish
|
||||
|
||||
|
||||
### Commands
|
||||
- /spectator | Essentially server-side free-cam, you get put in spectator and are able to fly around, once you use the command again you get put back to where you were.
|
||||
@ -43,38 +48,34 @@ As a challenge I'm trying to make it as user-friendly as possible.
|
||||

|
||||
- Remove game fog (lava, water, etc.)
|
||||
- All types individually toggleable
|
||||
- Mod Menu integration
|
||||
- Automatic config adaption (currently booleans only)
|
||||
- Remove darkness effect
|
||||
- Toggleable
|
||||
- Keybinding for /spectator
|
||||
|
||||
# Currently working on
|
||||
|
||||
## Client Side
|
||||
|
||||
- [x] Render block entities from a longer range
|
||||
- [x] Toggleable via GUI
|
||||
- [x] Configurable value
|
||||
- [x] In GUI
|
||||
- [x] Rework Mod Menu integration to be more flexible
|
||||
- Render block entities from a longer range
|
||||
- Toggleable via GUI
|
||||
- Configurable value
|
||||
- In GUI
|
||||
- Mod Menu integration
|
||||
DISCLAIMER: this is NOT perfect and still needs to be reworked, I'm just too lazy right now...
|
||||
- The following types are accepted:
|
||||
- String
|
||||
- Boolean
|
||||
- Float
|
||||
- Integer
|
||||
- [x] Chat Calculator
|
||||
- [x] Check if operator is present before calculating
|
||||
- Zoom
|
||||
- Configurable
|
||||
- Smooth zoom
|
||||
- Initial zoom value
|
||||
- Zoom step value
|
||||
- Scroll to zoom further
|
||||
|
||||
# To-do
|
||||
|
||||
## General
|
||||
- Rework config system
|
||||
- Store server settings in world folder for better singleplayer use
|
||||
- Store server settings in world folder for better singleplayer use
|
||||
|
||||
## Client side
|
||||
- Zoom
|
||||
- Configurable
|
||||
|
||||
## Server Side
|
||||
- Telekinesis
|
||||
|
@ -4,8 +4,8 @@ org.gradle.parallel=true
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/develop
|
||||
minecraft_version=1.21.5
|
||||
yarn_mappings=1.21.5+build.1
|
||||
minecraft_version=1.21.4
|
||||
yarn_mappings=1.21.4+build.8
|
||||
loader_version=0.16.10
|
||||
|
||||
# Mod Properties
|
||||
@ -14,6 +14,6 @@ maven_group=wtf.hak.survivalfabric
|
||||
archives_base_name=survivalfabric
|
||||
|
||||
# Dependencies
|
||||
fabric_version=0.119.5+1.21.5
|
||||
fabric_version=0.119.0+1.21.4
|
||||
|
||||
modmenu_version=14.0.0-rc.2
|
||||
modmenu_version=13.0.3
|
@ -4,7 +4,8 @@ import net.fabricmc.api.ClientModInitializer;
|
||||
import wtf.hak.survivalfabric.config.client.ClientConfigManager;
|
||||
import wtf.hak.survivalfabric.features.AngleViewer;
|
||||
import wtf.hak.survivalfabric.features.RemoveDarknessEffect;
|
||||
import wtf.hak.survivalfabric.features.SFKeyBindings;
|
||||
import wtf.hak.survivalfabric.features.CameraShortcut;
|
||||
import wtf.hak.survivalfabric.features.Zoom;
|
||||
|
||||
public class SurvivalFabricClient implements ClientModInitializer {
|
||||
|
||||
@ -17,7 +18,7 @@ public class SurvivalFabricClient implements ClientModInitializer {
|
||||
// Features
|
||||
AngleViewer.register();
|
||||
RemoveDarknessEffect.register();
|
||||
SFKeyBindings.register();
|
||||
|
||||
CameraShortcut.register();
|
||||
Zoom.register();
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package wtf.hak.survivalfabric.config.client;
|
||||
|
||||
public class ClientConfig {
|
||||
public String configVersion = "1.0";
|
||||
public String configVersion = "1.1";
|
||||
|
||||
public boolean renderNetherFog = false;
|
||||
public boolean renderOverworldFog = false;
|
||||
@ -13,4 +13,8 @@ public class ClientConfig {
|
||||
public boolean lockTeleportHeadMovement = true;
|
||||
public boolean manipulateBlockEntityDistance = true;
|
||||
public int blockEntityRange = 512;
|
||||
public boolean smoothCamera = true;
|
||||
public float initialZoom = 20f;
|
||||
public boolean scrollToZoom = true;
|
||||
public float zoomStep = 2.5f;
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class SFKeyBindings {
|
||||
public class CameraShortcut {
|
||||
|
||||
private static final KeyBinding CAMERA_BIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.survivalfabric.camera", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_PERIOD, "category.survivalfabric.survivalfabric"));
|
||||
|
||||
public static void register() {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if(client.player != null) {
|
||||
if (client.player != null) {
|
||||
if (CAMERA_BIND.wasPressed()) {
|
||||
client.player.networkHandler.sendChatCommand("camera");
|
||||
}
|
63
src/client/java/wtf/hak/survivalfabric/features/Zoom.java
Normal file
63
src/client/java/wtf/hak/survivalfabric/features/Zoom.java
Normal file
@ -0,0 +1,63 @@
|
||||
package wtf.hak.survivalfabric.features;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.text.Text;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
import static wtf.hak.survivalfabric.config.client.ClientConfigManager.getConfig;
|
||||
|
||||
public class Zoom {
|
||||
|
||||
private static final KeyBinding ZOOM_BIND = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.survivalfabric.zoom", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, "category.survivalfabric.survivalfabric"));
|
||||
|
||||
private static boolean SHOULD_ZOOM = false;
|
||||
private static int ZOOM_STEP = 0;
|
||||
|
||||
@Unique
|
||||
private static boolean initialSmoothZoom;
|
||||
|
||||
public static void register() {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
|
||||
if (ZOOM_BIND.isPressed() && !SHOULD_ZOOM) {
|
||||
if(getConfig().smoothCamera) {
|
||||
initialSmoothZoom = MinecraftClient.getInstance().options.smoothCameraEnabled;
|
||||
MinecraftClient.getInstance().options.smoothCameraEnabled = true;
|
||||
}
|
||||
SHOULD_ZOOM = true;
|
||||
} else if (!ZOOM_BIND.isPressed() && SHOULD_ZOOM) {
|
||||
SHOULD_ZOOM = false;
|
||||
ZOOM_STEP = 0;
|
||||
if(getConfig().smoothCamera) {
|
||||
MinecraftClient.getInstance().options.smoothCameraEnabled = initialSmoothZoom;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isZooming() {
|
||||
return SHOULD_ZOOM;
|
||||
}
|
||||
|
||||
public static float getZoomFov() {
|
||||
return getConfig().initialZoom - -ZOOM_STEP * getConfig().zoomStep;
|
||||
}
|
||||
|
||||
public static void modifyStep(int step) {
|
||||
ZOOM_STEP += step;
|
||||
|
||||
// Clamp the zoom level so the FOV stays within [1, 110]
|
||||
float zoomFov = getZoomFov();
|
||||
if (zoomFov < 1) {
|
||||
ZOOM_STEP = Math.round((1 - getConfig().initialZoom) / getConfig().zoomStep) + 1;
|
||||
} else if (zoomFov > 110) {
|
||||
ZOOM_STEP = Math.round((110 - getConfig().initialZoom) / getConfig().zoomStep);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import static wtf.hak.survivalfabric.config.client.ClientConfigManager.getConfig;
|
||||
|
||||
@Mixin(value = BackgroundRenderer.class, priority = 910)
|
||||
public abstract class BackgroundRendererMixin {
|
||||
public class BackgroundRendererMixin {
|
||||
|
||||
@Unique
|
||||
private static final Fog EMPTY_FOG = new Fog(-8.0f, 1_000_000.0F, FogShape.CYLINDER, 0, 0, 0, 0);
|
||||
|
@ -13,7 +13,7 @@ public interface BlockEntityRendererMixin<T extends BlockEntity> {
|
||||
|
||||
@Inject(method = "getRenderDistance", at = @At("HEAD"), cancellable = true)
|
||||
private void getRenderDistance(CallbackInfoReturnable<Integer> cir) {
|
||||
if(ClientConfigManager.getConfig().manipulateBlockEntityDistance)
|
||||
if (ClientConfigManager.getConfig().manipulateBlockEntityDistance)
|
||||
cir.setReturnValue(ClientConfigManager.getConfig().blockEntityRange);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package wtf.hak.survivalfabric.mixin.client;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import wtf.hak.survivalfabric.features.Zoom;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class GameRendererMixin {
|
||||
|
||||
/**
|
||||
* Modify Zoom FOV
|
||||
*/
|
||||
@ModifyReturnValue(method = "getFov", at = @At("RETURN"))
|
||||
private float modifyFovWithZoom(float fov, @Local(argsOnly = true) float tickDelta) {
|
||||
return Zoom.isZooming() ? Zoom.getZoomFov() : fov;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package wtf.hak.survivalfabric.mixin.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.Mouse;
|
||||
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;
|
||||
import wtf.hak.survivalfabric.features.Zoom;
|
||||
|
||||
import static wtf.hak.survivalfabric.config.client.ClientConfigManager.getConfig;
|
||||
|
||||
@Mixin(Mouse.class)
|
||||
public class MouseMixin {
|
||||
|
||||
/**
|
||||
* Scrolling listener for zooming
|
||||
*/
|
||||
@Inject(method = "onMouseScroll", at = @At("HEAD"), cancellable = true)
|
||||
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) {
|
||||
if (Zoom.isZooming() && getConfig().scrollToZoom) {
|
||||
if (MinecraftClient.getInstance().player != null) {
|
||||
if (vertical > 0)
|
||||
Zoom.modifyStep(-1);
|
||||
else
|
||||
Zoom.modifyStep(1);
|
||||
}
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,7 +5,9 @@
|
||||
"client": [
|
||||
"BackgroundRendererMixin",
|
||||
"BlockEntityRendererMixin",
|
||||
"EntityMixin"
|
||||
"EntityMixin",
|
||||
"GameRendererMixin",
|
||||
"MouseMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
@ -12,6 +12,7 @@ import wtf.hak.survivalfabric.commands.SlimeChunkCommand;
|
||||
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
||||
import wtf.hak.survivalfabric.features.sharedenderchest.SharedEnderChest;
|
||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerEvents;
|
||||
import wtf.hak.survivalfabric.utils.Scheduler;
|
||||
|
||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||
|
||||
@ -23,6 +24,7 @@ public class SurvivalFabric implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Scheduler.initialize();
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SpectatorCommand.register(dispatcher, "spectator", "s", "S", "camera", "c", "C"));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ReloadConfigCommand.register(dispatcher, "reloadsurvivalconfig"));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SlimeChunkCommand.register(dispatcher, "slimechunk", "sc"));
|
||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public class Config {
|
||||
|
||||
public String configVersion = "1.0";
|
||||
public String configVersion = "1.1";
|
||||
|
||||
public boolean joinMessageEnabled = true;
|
||||
public String joinMessage = "§8[§a+§8] §7%s";
|
||||
@ -37,9 +37,12 @@ public class Config {
|
||||
|
||||
public boolean veinMinerEnabled = true;
|
||||
public int maxVeinSize = 99999;
|
||||
public long veinAnimationTicks = 0;
|
||||
|
||||
public boolean chatCalcEnabled = true;
|
||||
|
||||
public boolean replenishEnabled = false;
|
||||
|
||||
public ScreenHandlerType<GenericContainerScreenHandler> screenHandlerType() {
|
||||
return switch (sharedEnderChestRows) {
|
||||
case 1 -> ScreenHandlerType.GENERIC_9X1;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package wtf.hak.survivalfabric.features.veinminer.drills;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.PlainTextContent;
|
||||
@ -8,27 +10,77 @@ import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import wtf.hak.survivalfabric.features.veinminer.Drill;
|
||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||
import wtf.hak.survivalfabric.utils.Scheduler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static wtf.hak.survivalfabric.SurvivalFabric.LOGGER;
|
||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||
|
||||
public class DrillBase implements Drill {
|
||||
|
||||
protected VeinMinerSession session;
|
||||
protected TagKey<Block> tag;
|
||||
|
||||
public DrillBase(VeinMinerSession session) {
|
||||
public DrillBase(VeinMinerSession session, TagKey<Block> tag) {
|
||||
this.session = session;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(BlockState blockId) {
|
||||
return false;
|
||||
public boolean canHandle(BlockState blockState) {
|
||||
return blockState.isIn(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drill(BlockPos blockPos) {
|
||||
return false;
|
||||
public boolean drill(BlockPos startPos) {
|
||||
handleBlock(session.world.getBlockState(startPos).getBlock(), new HashSet<>(), startPos, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleBlock(Block initialBlock, Set<BlockPos> history, BlockPos pos, int brokenBlocks) {
|
||||
if (brokenBlocks < getConfig().maxVeinSize) {
|
||||
history.add(pos);
|
||||
if (tryBreakBlock(pos)) {
|
||||
brokenBlocks++;
|
||||
int finalBrokenBlocks = brokenBlocks;
|
||||
|
||||
// Put everything in a list to avoid scheduling a lot of tasks.
|
||||
Set<BlockPos> toBreak = new HashSet<>();
|
||||
collectAdjacentBlocks(pos, history, initialBlock, toBreak);
|
||||
|
||||
long delay = getConfig().veinAnimationTicks;
|
||||
|
||||
// Use final or effectively final variables for lambda
|
||||
final int[] finalBrokenBlocksArr = {finalBrokenBlocks};
|
||||
|
||||
if (delay <= 0) {
|
||||
handleBlocksInBatch(toBreak, initialBlock, history, finalBrokenBlocksArr[0]);
|
||||
} else {
|
||||
Scheduler.get().scheduleTask(() -> handleBlocksInBatch(toBreak, initialBlock, history, finalBrokenBlocksArr[0]), delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectAdjacentBlocks(BlockPos pos, Set<BlockPos> history, Block initialBlock, Set<BlockPos> toBreak) {
|
||||
forXYZ(pos, 1, new ForXYZHandler() {
|
||||
@Override
|
||||
public void handle(BlockPos newPos) {
|
||||
if (!history.contains(newPos) && session.world.getBlockState(newPos).getBlock() == initialBlock) {
|
||||
toBreak.add(newPos);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleBlocksInBatch(Set<BlockPos> toBreak, Block initialBlock, Set<BlockPos> history, int finalBrokenBlocks) {
|
||||
for (BlockPos newPos : toBreak) {
|
||||
handleBlock(initialBlock, history, newPos, finalBrokenBlocks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,9 +90,12 @@ public class DrillBase implements Drill {
|
||||
}
|
||||
|
||||
protected void forXYZ(BlockPos pos, int max, ForXYZHandler handler) {
|
||||
forXYZ(pos, max, handlerPos -> {
|
||||
handler.handle(handlerPos);
|
||||
return 0;
|
||||
forXYZ(pos, max, new ForXYZCounter() {
|
||||
@Override
|
||||
public int handle(BlockPos pos) {
|
||||
handler.handle(pos);
|
||||
return 1; // Accumulate one count for each position processed
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
@ -49,14 +104,17 @@ public class DrillBase implements Drill {
|
||||
}
|
||||
|
||||
protected void forXYZ(BlockPos pos, int max, ForXYZHandler handler, boolean forceVertical) {
|
||||
forXYZ(pos, max, handlerPos -> {
|
||||
handler.handle(handlerPos);
|
||||
return 0;
|
||||
forXYZ(pos, max, new ForXYZCounter() {
|
||||
@Override
|
||||
public int handle(BlockPos pos) {
|
||||
handler.handle(pos);
|
||||
return 1; // Accumulate one count for each position processed
|
||||
}
|
||||
}, forceVertical);
|
||||
}
|
||||
|
||||
protected int forXYZ(BlockPos pos, int max, ForXYZCounter handler, boolean forceVertical) {
|
||||
ArrayList<Integer> offsets = new ArrayList<Integer>();
|
||||
Set<Integer> offsets = new HashSet<>();
|
||||
for (int d = 0; d <= max; ++d) {
|
||||
offsets.add(d);
|
||||
if (d != -d) {
|
||||
@ -64,39 +122,21 @@ public class DrillBase implements Drill {
|
||||
}
|
||||
}
|
||||
|
||||
String[] order = new String[]{"x", "y", "z"};
|
||||
if (forceVertical) {
|
||||
order = new String[]{"y", "x", "z"};
|
||||
} else {
|
||||
ServerPlayerEntity player = session.player;
|
||||
boolean majorPitchChange = player.getPitch() < -45.0 || player.getPitch() > 45.0;
|
||||
boolean majorYawChange = (player.getYaw() > 45.0 && player.getYaw() < 135.0) || (player.getYaw() < -45.0 && player.getYaw() > -135.0);
|
||||
if (majorPitchChange) {
|
||||
if (majorYawChange) {
|
||||
order = new String[]{"y", "z", "x"};
|
||||
} else {
|
||||
order = new String[]{"y", "x", "z"};
|
||||
}
|
||||
} else {
|
||||
if (majorYawChange) {
|
||||
order = new String[]{"z", "y", "x"};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String[] order = determineOrder(forceVertical);
|
||||
int counter = 0;
|
||||
|
||||
for (int i1 : offsets) {
|
||||
for (int i2 : offsets) {
|
||||
for (int i3 : offsets) {
|
||||
int ix = order[0] == "x" ? i1 : order[1] == "x" ? i2 : i3;
|
||||
int iy = order[0] == "y" ? i1 : order[1] == "y" ? i2 : i3;
|
||||
int iz = order[0] == "z" ? i1 : order[1] == "z" ? i2 : i3;
|
||||
int ix = order[0].equals("x") ? i1 : order[1].equals("x") ? i2 : i3;
|
||||
int iy = order[0].equals("y") ? i1 : order[1].equals("y") ? i2 : i3;
|
||||
int iz = order[0].equals("z") ? i1 : order[1].equals("z") ? i2 : i3;
|
||||
|
||||
int px = pos.getX() + ix;
|
||||
int py = pos.getY() + iy;
|
||||
int pz = pos.getZ() + iz;
|
||||
|
||||
counter += handler.handle(new BlockPos(px, py, pz));
|
||||
counter += handler.handle(new BlockPos(px, py, pz)); // Works with ForXYZCounter, returning an int
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -104,6 +144,29 @@ public class DrillBase implements Drill {
|
||||
return counter;
|
||||
}
|
||||
|
||||
protected String[] determineOrder(boolean forceVertical) {
|
||||
if (forceVertical) {
|
||||
return new String[]{"y", "x", "z"};
|
||||
} else {
|
||||
ServerPlayerEntity player = session.player;
|
||||
boolean majorPitchChange = player.getPitch() < -45.0 || player.getPitch() > 45.0;
|
||||
boolean majorYawChange = (player.getYaw() > 45.0 && player.getYaw() < 135.0) || (player.getYaw() < -45.0 && player.getYaw() > -135.0);
|
||||
|
||||
if (majorPitchChange) {
|
||||
if (majorYawChange) {
|
||||
return new String[]{"y", "z", "x"};
|
||||
} else {
|
||||
return new String[]{"y", "x", "z"};
|
||||
}
|
||||
} else {
|
||||
if (majorYawChange) {
|
||||
return new String[]{"z", "y", "x"};
|
||||
}
|
||||
}
|
||||
}
|
||||
return new String[]{"x", "y", "z"};
|
||||
}
|
||||
|
||||
protected boolean tryBreakBlock(BlockPos blockPos) {
|
||||
session.addPosition(blockPos);
|
||||
boolean success = isRightTool(blockPos) && session.player.interactionManager.tryBreakBlock(blockPos);
|
||||
|
@ -1,62 +1,22 @@
|
||||
package wtf.hak.survivalfabric.features.veinminer.drills;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||
|
||||
public class LeavesDrill extends DrillBase {
|
||||
|
||||
public static final TagKey<Block> leavesTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "leaves"));
|
||||
|
||||
public LeavesDrill(VeinMinerSession session) {
|
||||
super(session);
|
||||
super(session, TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "leaves")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(BlockState blockState) {
|
||||
return blockState.isIn(leavesTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drill(BlockPos startPos) {
|
||||
ServerWorld world = session.world;
|
||||
Block initialBlock = world.getBlockState(startPos).getBlock();
|
||||
int brokenLeaves = 0;
|
||||
ArrayDeque<BlockPos> pending = new ArrayDeque<BlockPos>();
|
||||
pending.add(startPos);
|
||||
|
||||
while (!pending.isEmpty() && brokenLeaves < getConfig().maxVeinSize) {
|
||||
BlockPos leavesPos = pending.remove();
|
||||
Block leavesBlock = world.getBlockState(leavesPos).getBlock();
|
||||
if (tryBreakBlock(leavesPos)) {
|
||||
if (leavesBlock == initialBlock) {
|
||||
brokenLeaves += 1;
|
||||
}
|
||||
|
||||
if (leavesBlock == initialBlock) {
|
||||
// look around current block
|
||||
forXYZ(leavesPos, 1, newPos -> {
|
||||
BlockState newBlockState = world.getBlockState(newPos);
|
||||
Block newBlock = newBlockState.getBlock();
|
||||
boolean isSameOreBlock = newBlock == leavesBlock;
|
||||
if (!pending.contains(newPos) && isSameOreBlock) {
|
||||
pending.add(newPos);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
public boolean isRightTool(BlockPos pos) {
|
||||
var blockState = session.world.getBlockState(pos);
|
||||
return session.player.getMainHandStack().isSuitableFor(blockState) || session.player.getMainHandStack().getItem() == Items.SHEARS;
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +1,14 @@
|
||||
package wtf.hak.survivalfabric.features.veinminer.drills;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||
|
||||
public class OreDrill extends DrillBase {
|
||||
|
||||
public static final TagKey<Block> oreTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "ore"));
|
||||
|
||||
public OreDrill(VeinMinerSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(BlockState blockState) {
|
||||
return blockState.isIn(oreTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drill(BlockPos startPos) {
|
||||
ServerWorld world = session.world;
|
||||
Block initialBlock = world.getBlockState(startPos).getBlock();
|
||||
int brokenOre = 0;
|
||||
ArrayDeque<BlockPos> pending = new ArrayDeque<BlockPos>();
|
||||
pending.add(startPos);
|
||||
|
||||
while (!pending.isEmpty() && brokenOre < getConfig().maxVeinSize) {
|
||||
BlockPos orePos = pending.remove();
|
||||
Block oreBlock = world.getBlockState(orePos).getBlock();
|
||||
if (tryBreakBlock(orePos)) {
|
||||
if (oreBlock == initialBlock) {
|
||||
brokenOre += 1;
|
||||
}
|
||||
|
||||
if (oreBlock == initialBlock) {
|
||||
// look around current block
|
||||
forXYZ(orePos, 1, newPos -> {
|
||||
BlockState newBlockState = world.getBlockState(newPos);
|
||||
Block newBlock = newBlockState.getBlock();
|
||||
boolean isSameOreBlock = newBlock == oreBlock;
|
||||
if (!pending.contains(newPos) && isSameOreBlock) {
|
||||
pending.add(newPos);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
super(session, TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "ore")));
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +1,14 @@
|
||||
package wtf.hak.survivalfabric.features.veinminer.drills;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||
|
||||
public class WoodDrill extends DrillBase {
|
||||
|
||||
public static final TagKey<Block> woodTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "wood"));
|
||||
|
||||
public WoodDrill(VeinMinerSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandle(BlockState blockState) {
|
||||
return blockState.isIn(woodTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drill(BlockPos startPos) {
|
||||
ServerWorld world = session.world;
|
||||
int broken = 0;
|
||||
ArrayDeque<BlockPos> pendingLogs = new ArrayDeque<>();
|
||||
ArrayDeque<BlockPos> logBlocks = new ArrayDeque<>();
|
||||
pendingLogs.add(startPos);
|
||||
|
||||
String leavesBlockId = Registries.BLOCK.getId(world.getBlockState(startPos).getBlock()).toString().replace("_log", "_leaves");
|
||||
|
||||
while (!pendingLogs.isEmpty() && broken < getConfig().maxVeinSize) {
|
||||
BlockPos woodPos = pendingLogs.remove();
|
||||
Block woodBlock = world.getBlockState(woodPos).getBlock();
|
||||
|
||||
if (tryBreakBlock(woodPos)) {
|
||||
logBlocks.add(woodPos);
|
||||
broken += 1;
|
||||
|
||||
// look around current block
|
||||
forXYZ(woodPos, 1, newPos -> {
|
||||
Block newBlock = world.getBlockState(newPos).getBlock();
|
||||
if (newBlock == woodBlock && !pendingLogs.contains(newPos)) {
|
||||
pendingLogs.add(newPos);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayDeque<BlockPos> pendingLeaves = logBlocks;
|
||||
while (!pendingLeaves.isEmpty() && broken < getConfig().maxVeinSize) {
|
||||
broken += forXYZ(pendingLeaves.remove(), 1, newPos -> {
|
||||
int brokenLeaves = 0;
|
||||
Block newBlock = world.getBlockState(newPos).getBlock();
|
||||
String newBlockId = Registries.BLOCK.getId(newBlock).toString();
|
||||
if (newBlockId.equals(leavesBlockId)) {
|
||||
if (tryBreakBlock(newPos)) {
|
||||
brokenLeaves += 1;
|
||||
}
|
||||
}
|
||||
return brokenLeaves;
|
||||
}, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isLeaf(Block block) {
|
||||
return Registries.BLOCK.getId(block).toString().endsWith("_leaves");
|
||||
super(session, TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "wood")));
|
||||
}
|
||||
|
||||
}
|
64
src/main/java/wtf/hak/survivalfabric/mixin/BlockMixin.java
Normal file
64
src/main/java/wtf/hak/survivalfabric/mixin/BlockMixin.java
Normal file
@ -0,0 +1,64 @@
|
||||
package wtf.hak.survivalfabric.mixin;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.CropBlock;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.HoeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.World;
|
||||
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.CallbackInfoReturnable;
|
||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(Block.class)
|
||||
public abstract class BlockMixin {
|
||||
|
||||
@Inject(method = "onBreak", at = @At("HEAD"), cancellable = true)
|
||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir) {
|
||||
if (world.isClient()) return;
|
||||
|
||||
if (state.getBlock() instanceof CropBlock && ConfigManager.getConfig().replenishEnabled) {
|
||||
ItemStack mainHand = player.getStackInHand(Hand.MAIN_HAND);
|
||||
if (mainHand.getItem() instanceof HoeItem) {
|
||||
Item seedItem = state.getBlock().asItem();
|
||||
Block seedBlock = state.getBlock();
|
||||
List<ItemStack> drops = Block.getDroppedStacks(state, (ServerWorld) world, pos, null, player, mainHand);
|
||||
if (removeIfAvailable(drops, seedItem)) {
|
||||
if (!player.isCreative()) {
|
||||
for (ItemStack drop : drops) {
|
||||
Block.dropStack(world, pos, drop);
|
||||
}
|
||||
player.incrementStat(Stats.USED.getOrCreateStat(seedItem));
|
||||
mainHand.damage(1, player, EquipmentSlot.MAINHAND);
|
||||
}
|
||||
world.getServer().executeSync(() -> world.setBlockState(pos, seedBlock.getDefaultState()));
|
||||
cir.setReturnValue(Blocks.AIR.getDefaultState());
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean removeIfAvailable(List<ItemStack> drops, Item item) {
|
||||
for (ItemStack drop : drops) {
|
||||
if (drop.getItem() == item) {
|
||||
drop.decrement(1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -22,6 +22,9 @@ import java.util.Set;
|
||||
@Mixin(PlayerManager.class)
|
||||
public abstract class PlayerManagerMixin {
|
||||
|
||||
/**
|
||||
* Send join message to joined player
|
||||
*/
|
||||
@Inject(method = {"onPlayerConnect"}, at = {@At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V")})
|
||||
public void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
|
||||
if (ConfigManager.getConfig().joinMessageEnabled && !player.getServer().isSingleplayer()) {
|
||||
@ -30,6 +33,9 @@ public abstract class PlayerManagerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify join message broadcasted to server
|
||||
*/
|
||||
@ModifyArg(method = {"onPlayerConnect"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||
private Text onPlayerConnect(Text text) {
|
||||
if (ConfigManager.getConfig().joinMessageEnabled) {
|
||||
@ -39,6 +45,9 @@ public abstract class PlayerManagerMixin {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player out of specator mode if necessary
|
||||
*/
|
||||
@Inject(method = {"remove"}, at = {@At("HEAD")})
|
||||
public void onPlayerLeave(ServerPlayerEntity player, CallbackInfo ci) {
|
||||
if (SpectatorCommand.spectating.containsKey(player)) {
|
||||
@ -48,6 +57,9 @@ public abstract class PlayerManagerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify chat messages
|
||||
*/
|
||||
@Inject(method = {"broadcast(Lnet/minecraft/network/message/SignedMessage;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V"}, at = {@At("HEAD")}, cancellable = true)
|
||||
private void onBroadcast(SignedMessage message, ServerPlayerEntity sender, MessageType.Parameters parameters, CallbackInfo ci) {
|
||||
if (sender != null) {
|
||||
|
@ -8,8 +8,11 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public abstract class ServerPlayNetworkHandlerMixin {
|
||||
public class ServerPlayNetworkHandlerMixin {
|
||||
|
||||
/**
|
||||
* Modify quit message
|
||||
*/
|
||||
@ModifyArg(method = {"cleanUp"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
|
||||
private Text quitMessage(Text text) {
|
||||
if (ConfigManager.getConfig().quitMessageEnabled) {
|
||||
|
@ -10,8 +10,11 @@ import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
public abstract class ServerPlayerEntityMixin {
|
||||
public class ServerPlayerEntityMixin {
|
||||
|
||||
/**
|
||||
* Change player list name if enabled
|
||||
*/
|
||||
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
|
||||
private void changePlayerListName(CallbackInfoReturnable<Text> cir) {
|
||||
if (ConfigManager.getConfig().dimensionIndicatorEnabled) {
|
||||
|
@ -12,6 +12,9 @@ import wtf.hak.survivalfabric.utils.PacketUtils;
|
||||
@Mixin(ServerWorld.class)
|
||||
public class ServerWorldMixin {
|
||||
|
||||
/**
|
||||
* Update List Names if needed
|
||||
*/
|
||||
@Inject(method = "onDimensionChanged", at = {@At("HEAD")})
|
||||
public void onDimensionChange(Entity entity, CallbackInfo ci) {
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
|
@ -3,6 +3,18 @@ package wtf.hak.survivalfabric.utils;
|
||||
public class MathUtils {
|
||||
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
public static boolean hasSupportedOperator(String msg) {
|
||||
return msg.contains("+") || msg.contains("-") || msg.contains("*") || msg.contains("/");
|
||||
}
|
||||
|
45
src/main/java/wtf/hak/survivalfabric/utils/Scheduler.java
Normal file
45
src/main/java/wtf/hak/survivalfabric/utils/Scheduler.java
Normal file
@ -0,0 +1,45 @@
|
||||
package wtf.hak.survivalfabric.utils;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Scheduler {
|
||||
|
||||
private static Scheduler INSTANCE;
|
||||
|
||||
private final Map<Runnable, Long> tasks = new ConcurrentHashMap<>();
|
||||
|
||||
public Scheduler() {
|
||||
ServerTickEvents.END_SERVER_TICK.register((server) -> {
|
||||
for(Runnable task : tasks.keySet()) {
|
||||
long delay = tasks.get(task);
|
||||
if(delay <= 0) {
|
||||
task.run();
|
||||
tasks.remove(task);
|
||||
} else {
|
||||
tasks.put(task, delay-1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scheduleTask(Runnable task) {
|
||||
scheduleTask(task, 0L);
|
||||
}
|
||||
|
||||
public void scheduleTask(Runnable task, long delay) {
|
||||
tasks.put(task, delay);
|
||||
}
|
||||
|
||||
public static Scheduler get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static Scheduler initialize() {
|
||||
INSTANCE = new Scheduler();
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -17,5 +17,6 @@
|
||||
"key.survivalfabric.angle14": "204.98 / -41.68",
|
||||
"key.survivalfabric.angle15": "244.97 / -41.71",
|
||||
"category.survivalfabric.survivalfabric": "Survival Fabric",
|
||||
"key.survivalfabric.camera": "/camera"
|
||||
"key.survivalfabric.camera": "/camera",
|
||||
"key.survivalfabric.zoom": "Zoom"
|
||||
}
|
@ -38,7 +38,7 @@
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.10",
|
||||
"minecraft": "~1.21.5",
|
||||
"minecraft": "~1.21.4",
|
||||
"java": ">=21",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
|
@ -3,6 +3,7 @@
|
||||
"package": "wtf.hak.survivalfabric.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"BlockMixin",
|
||||
"PlayerManagerMixin",
|
||||
"ServerPlayerEntityMixin",
|
||||
"ServerPlayNetworkHandlerMixin",
|
||||
|
Reference in New Issue
Block a user