Code cleanup
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
package wtf.hak.survivalfabric;
|
package wtf.hak.survivalfabric;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
|
||||||
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
|
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
|
||||||
@ -24,9 +23,9 @@ public class SurvivalFabric implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SpectatorCommand.register(dispatcher, new String[] { "spectator", "s", "S", "camera", "c", "C", }));
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SpectatorCommand.register(dispatcher, "spectator", "s", "S", "camera", "c", "C"));
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ReloadConfigCommand.register(dispatcher, new String[] { "reloadsurvivalconfig" }));
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> ReloadConfigCommand.register(dispatcher, "reloadsurvivalconfig"));
|
||||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SlimeChunkCommand.register(dispatcher, new String[] { "slimechunk", "sc" }));
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SlimeChunkCommand.register(dispatcher, "slimechunk", "sc"));
|
||||||
|
|
||||||
if (getConfig().sharedEnderChestEnabled)
|
if (getConfig().sharedEnderChestEnabled)
|
||||||
new SharedEnderChest().onInitialize();
|
new SharedEnderChest().onInitialize();
|
||||||
@ -35,8 +34,7 @@ public class SurvivalFabric implements ModInitializer {
|
|||||||
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
|
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
|
||||||
if (player instanceof ServerPlayerEntity serverPlayer) {
|
if (player instanceof ServerPlayerEntity serverPlayer) {
|
||||||
return VeinMinerEvents.beforeBlockBreak(world, serverPlayer, pos, state);
|
return VeinMinerEvents.beforeBlockBreak(world, serverPlayer, pos, state);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,11 +6,9 @@ import net.minecraft.server.command.CommandManager;
|
|||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.random.CheckedRandom;
|
|
||||||
import net.minecraft.util.math.random.ChunkRandom;
|
import net.minecraft.util.math.random.ChunkRandom;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
|
||||||
|
|
||||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||||
|
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
package wtf.hak.survivalfabric.features.sharedenderchest;
|
package wtf.hak.survivalfabric.features.sharedenderchest;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.EnderChestBlock;
|
import net.minecraft.block.EnderChestBlock;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@ -24,11 +17,14 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.*;
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.WorldSavePath;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
import static wtf.hak.survivalfabric.SurvivalFabric.LOGGER;
|
import static wtf.hak.survivalfabric.SurvivalFabric.LOGGER;
|
||||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||||
|
|
||||||
@ -38,6 +34,51 @@ public class SharedEnderChest implements ServerLifecycleEvents.ServerStopping, S
|
|||||||
|
|
||||||
private long ticksUntilSave = -20;
|
private long ticksUntilSave = -20;
|
||||||
|
|
||||||
|
public static void saveInventory(MinecraftServer server) {
|
||||||
|
File inventoryFile = getFile(server);
|
||||||
|
NbtCompound nbt = new NbtCompound();
|
||||||
|
DefaultedList<ItemStack> inventoryItemStacks = DefaultedList.ofSize(getConfig().sharedEnderChestRows * 9, ItemStack.EMPTY);
|
||||||
|
Inventories.writeNbt(nbt, sharedInventory.getList(inventoryItemStacks), server.getRegistryManager());
|
||||||
|
try (FileOutputStream inventoryFileOutputStream = new FileOutputStream(inventoryFile);
|
||||||
|
DataOutputStream inventoryFileDataOutput = new DataOutputStream(inventoryFileOutputStream)) {
|
||||||
|
inventoryFile.createNewFile();
|
||||||
|
NbtIo.writeCompressed(nbt, inventoryFileDataOutput);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Error while saving Shared Ender Chest: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void openSharedEnderChest(PlayerEntity player, World world, BlockPos pos) {
|
||||||
|
fakeEnderChestOpen(world, pos, true);
|
||||||
|
sharedInventory.openedEnderChests.put(player, pos);
|
||||||
|
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((int_1, playerInventory, playerEntity) ->
|
||||||
|
new GenericContainerScreenHandler(getConfig().screenHandlerType(), int_1, playerInventory, sharedInventory, getConfig().sharedEnderChestRows), Text.of(getConfig().sharedEnderChestName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playEnderChestOpenSound(World world, BlockPos pos) {
|
||||||
|
world.playSound(null, pos, SoundEvents.BLOCK_ENDER_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void playEnderChestCloseSound(World world, BlockPos pos) {
|
||||||
|
world.playSound(null, pos, SoundEvents.BLOCK_ENDER_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fakeEnderChestOpen(World world, BlockPos pos, boolean open) {
|
||||||
|
if (!(world.getBlockState(pos).getBlock() instanceof EnderChestBlock)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (open)
|
||||||
|
playEnderChestOpenSound(world, pos);
|
||||||
|
else
|
||||||
|
playEnderChestCloseSound(world, pos);
|
||||||
|
world.addSyncedBlockEvent(pos, Blocks.ENDER_CHEST, 1, open ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getFile(MinecraftServer server) {
|
||||||
|
return server.getSavePath(WorldSavePath.ROOT).resolve("sharedenderchest.sav").toFile();
|
||||||
|
}
|
||||||
|
|
||||||
public void onServerStarted(MinecraftServer server) {
|
public void onServerStarted(MinecraftServer server) {
|
||||||
File inventoryFile = getFile(server);
|
File inventoryFile = getFile(server);
|
||||||
if (inventoryFile.exists()) {
|
if (inventoryFile.exists()) {
|
||||||
@ -56,19 +97,6 @@ public class SharedEnderChest implements ServerLifecycleEvents.ServerStopping, S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveInventory(MinecraftServer server) {
|
|
||||||
File inventoryFile = getFile(server);
|
|
||||||
NbtCompound nbt = new NbtCompound();
|
|
||||||
DefaultedList<ItemStack> inventoryItemStacks = DefaultedList.ofSize(getConfig().sharedEnderChestRows * 9, ItemStack.EMPTY);
|
|
||||||
Inventories.writeNbt(nbt, sharedInventory.getList(inventoryItemStacks), server.getRegistryManager());
|
|
||||||
try (FileOutputStream inventoryFileOutputStream = new FileOutputStream(inventoryFile);
|
|
||||||
DataOutputStream inventoryFileDataOutput = new DataOutputStream(inventoryFileOutputStream)) {
|
|
||||||
inventoryFile.createNewFile();
|
|
||||||
NbtIo.writeCompressed(nbt, inventoryFileDataOutput);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("Error while saving Shared Ender Chest: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void onServerStopping(MinecraftServer server) {
|
public void onServerStopping(MinecraftServer server) {
|
||||||
saveInventory(server);
|
saveInventory(server);
|
||||||
}
|
}
|
||||||
@ -112,36 +140,4 @@ public class SharedEnderChest implements ServerLifecycleEvents.ServerStopping, S
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void openSharedEnderChest(PlayerEntity player, World world, BlockPos pos) {
|
|
||||||
fakeEnderChestOpen(world, pos, true);
|
|
||||||
sharedInventory.openedEnderChests.put(player, pos);
|
|
||||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((int_1, playerInventory, playerEntity) ->
|
|
||||||
new GenericContainerScreenHandler(getConfig().screenHandlerType(), int_1, playerInventory, sharedInventory, getConfig().sharedEnderChestRows), Text.of(getConfig().sharedEnderChestName)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void playEnderChestOpenSound(World world, BlockPos pos) {
|
|
||||||
world.playSound(null, pos, SoundEvents.BLOCK_ENDER_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void playEnderChestCloseSound(World world, BlockPos pos) {
|
|
||||||
world.playSound(null, pos, SoundEvents.BLOCK_ENDER_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fakeEnderChestOpen(World world, BlockPos pos, boolean open) {
|
|
||||||
if (!(world.getBlockState(pos).getBlock() instanceof EnderChestBlock)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(open)
|
|
||||||
playEnderChestOpenSound(world, pos);
|
|
||||||
else
|
|
||||||
playEnderChestCloseSound(world, pos);
|
|
||||||
world.addSyncedBlockEvent(pos, Blocks.ENDER_CHEST, 1, open ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static File getFile(MinecraftServer server) {
|
|
||||||
return server.getSavePath(WorldSavePath.ROOT).resolve("sharedenderchest.sav").toFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -12,8 +12,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class SharedInventory implements Inventory {
|
public class SharedInventory implements Inventory {
|
||||||
|
|
||||||
private final DefaultedList<ItemStack> stacks;
|
|
||||||
public final Map<PlayerEntity, BlockPos> openedEnderChests = new HashMap<>();
|
public final Map<PlayerEntity, BlockPos> openedEnderChests = new HashMap<>();
|
||||||
|
private final DefaultedList<ItemStack> stacks;
|
||||||
|
|
||||||
public SharedInventory(int inventoryRows) {
|
public SharedInventory(int inventoryRows) {
|
||||||
this.stacks = DefaultedList.ofSize(inventoryRows * 9, ItemStack.EMPTY);
|
this.stacks = DefaultedList.ofSize(inventoryRows * 9, ItemStack.EMPTY);
|
||||||
|
@ -5,6 +5,8 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
|
|
||||||
public interface Drill {
|
public interface Drill {
|
||||||
boolean canHandle(BlockState blockState);
|
boolean canHandle(BlockState blockState);
|
||||||
|
|
||||||
boolean isRightTool(BlockPos pos);
|
boolean isRightTool(BlockPos pos);
|
||||||
|
|
||||||
boolean drill(BlockPos blockPos);
|
boolean drill(BlockPos blockPos);
|
||||||
}
|
}
|
@ -24,8 +24,7 @@ public class VeinMinerEvents {
|
|||||||
boolean shouldContinue = !mine(session);
|
boolean shouldContinue = !mine(session);
|
||||||
session.finish();
|
session.finish();
|
||||||
return shouldContinue;
|
return shouldContinue;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package wtf.hak.survivalfabric.features.veinminer;
|
package wtf.hak.survivalfabric.features.veinminer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class VeinMinerSession {
|
public class VeinMinerSession {
|
||||||
private static final ArrayList<VeinMinerSession> sessions = new ArrayList<>();
|
private static final ArrayList<VeinMinerSession> sessions = new ArrayList<>();
|
||||||
|
|
||||||
@ -16,6 +16,14 @@ public class VeinMinerSession {
|
|||||||
public Set<BlockPos> positions;
|
public Set<BlockPos> positions;
|
||||||
public BlockPos initialPos;
|
public BlockPos initialPos;
|
||||||
|
|
||||||
|
private VeinMinerSession(ServerPlayerEntity player, ServerWorld world, BlockPos initialPos) {
|
||||||
|
this.player = player;
|
||||||
|
this.world = world;
|
||||||
|
this.initialPos = initialPos;
|
||||||
|
this.positions = new HashSet<>();
|
||||||
|
positions.add(initialPos);
|
||||||
|
}
|
||||||
|
|
||||||
public static VeinMinerSession sessionForPlayer(ServerPlayerEntity player) {
|
public static VeinMinerSession sessionForPlayer(ServerPlayerEntity player) {
|
||||||
for (var session : sessions) {
|
for (var session : sessions) {
|
||||||
if (session.player == player) {
|
if (session.player == player) {
|
||||||
@ -44,14 +52,6 @@ public class VeinMinerSession {
|
|||||||
sessions.remove(session);
|
sessions.remove(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VeinMinerSession(ServerPlayerEntity player, ServerWorld world, BlockPos initialPos) {
|
|
||||||
this.player = player;
|
|
||||||
this.world = world;
|
|
||||||
this.initialPos = initialPos;
|
|
||||||
this.positions = new HashSet<>();
|
|
||||||
positions.add(initialPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPosition(BlockPos pos) {
|
public void addPosition(BlockPos pos) {
|
||||||
positions.add(pos);
|
positions.add(pos);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package wtf.hak.survivalfabric.features.veinminer.drills;
|
package wtf.hak.survivalfabric.features.veinminer.drills;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
import net.minecraft.text.PlainTextContent;
|
import net.minecraft.text.PlainTextContent;
|
||||||
@ -11,6 +9,8 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import wtf.hak.survivalfabric.features.veinminer.Drill;
|
import wtf.hak.survivalfabric.features.veinminer.Drill;
|
||||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static wtf.hak.survivalfabric.SurvivalFabric.LOGGER;
|
import static wtf.hak.survivalfabric.SurvivalFabric.LOGGER;
|
||||||
|
|
||||||
public class DrillBase implements Drill {
|
public class DrillBase implements Drill {
|
||||||
@ -37,14 +37,6 @@ public class DrillBase implements Drill {
|
|||||||
return session.player.getMainHandStack().isSuitableFor(blockState);
|
return session.player.getMainHandStack().isSuitableFor(blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected interface ForXYZHandler {
|
|
||||||
public void handle(BlockPos pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected interface ForXYZCounter {
|
|
||||||
public int handle(BlockPos pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void forXYZ(BlockPos pos, int max, ForXYZHandler handler) {
|
protected void forXYZ(BlockPos pos, int max, ForXYZHandler handler) {
|
||||||
forXYZ(pos, max, handlerPos -> {
|
forXYZ(pos, max, handlerPos -> {
|
||||||
handler.handle(handlerPos);
|
handler.handle(handlerPos);
|
||||||
@ -75,20 +67,17 @@ public class DrillBase implements Drill {
|
|||||||
String[] order = new String[]{"x", "y", "z"};
|
String[] order = new String[]{"x", "y", "z"};
|
||||||
if (forceVertical) {
|
if (forceVertical) {
|
||||||
order = new String[]{"y", "x", "z"};
|
order = new String[]{"y", "x", "z"};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ServerPlayerEntity player = session.player;
|
ServerPlayerEntity player = session.player;
|
||||||
boolean majorPitchChange = player.getPitch() < -45.0 || player.getPitch() > 45.0;
|
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);
|
boolean majorYawChange = (player.getYaw() > 45.0 && player.getYaw() < 135.0) || (player.getYaw() < -45.0 && player.getYaw() > -135.0);
|
||||||
if (majorPitchChange) {
|
if (majorPitchChange) {
|
||||||
if (majorYawChange) {
|
if (majorYawChange) {
|
||||||
order = new String[]{"y", "z", "x"};
|
order = new String[]{"y", "z", "x"};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
order = new String[]{"y", "x", "z"};
|
order = new String[]{"y", "x", "z"};
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (majorYawChange) {
|
if (majorYawChange) {
|
||||||
order = new String[]{"z", "y", "x"};
|
order = new String[]{"z", "y", "x"};
|
||||||
}
|
}
|
||||||
@ -130,4 +119,12 @@ public class DrillBase implements Drill {
|
|||||||
session.player.sendMessage(text);
|
session.player.sendMessage(text);
|
||||||
LOGGER.info(message);
|
LOGGER.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected interface ForXYZHandler {
|
||||||
|
void handle(BlockPos pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected interface ForXYZCounter {
|
||||||
|
int handle(BlockPos pos);
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,12 +15,12 @@ import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
|||||||
|
|
||||||
public class LeavesDrill extends DrillBase {
|
public class LeavesDrill extends DrillBase {
|
||||||
|
|
||||||
|
public static final TagKey<Block> leavesTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "leaves"));
|
||||||
|
|
||||||
public LeavesDrill(VeinMinerSession session) {
|
public LeavesDrill(VeinMinerSession session) {
|
||||||
super(session);
|
super(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final TagKey<Block> leavesTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "leaves"));
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(BlockState blockState) {
|
public boolean canHandle(BlockState blockState) {
|
||||||
return blockState.isIn(leavesTag);
|
return blockState.isIn(leavesTag);
|
||||||
|
@ -6,22 +6,21 @@ import net.minecraft.registry.RegistryKeys;
|
|||||||
import net.minecraft.registry.tag.TagKey;
|
import net.minecraft.registry.tag.TagKey;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
|
||||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||||
|
|
||||||
public class OreDrill extends DrillBase {
|
public class OreDrill extends DrillBase {
|
||||||
|
|
||||||
|
public static final TagKey<Block> oreTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "ore"));
|
||||||
|
|
||||||
public OreDrill(VeinMinerSession session) {
|
public OreDrill(VeinMinerSession session) {
|
||||||
super(session);
|
super(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final TagKey<Block> oreTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "ore"));
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(BlockState blockState) {
|
public boolean canHandle(BlockState blockState) {
|
||||||
return blockState.isIn(oreTag);
|
return blockState.isIn(oreTag);
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
package wtf.hak.survivalfabric.features.veinminer.drills;
|
package wtf.hak.survivalfabric.features.veinminer.drills;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
import net.minecraft.registry.tag.TagKey;
|
import net.minecraft.registry.tag.TagKey;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.registry.Registries;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
import wtf.hak.survivalfabric.features.veinminer.VeinMinerSession;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
|
||||||
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
||||||
|
|
||||||
public class WoodDrill extends DrillBase {
|
public class WoodDrill extends DrillBase {
|
||||||
|
|
||||||
|
public static final TagKey<Block> woodTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "wood"));
|
||||||
|
|
||||||
public WoodDrill(VeinMinerSession session) {
|
public WoodDrill(VeinMinerSession session) {
|
||||||
super(session);
|
super(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final TagKey<Block> woodTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "wood"));
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHandle(BlockState blockState) {
|
public boolean canHandle(BlockState blockState) {
|
||||||
return blockState.isIn(woodTag);
|
return blockState.isIn(woodTag);
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package wtf.hak.survivalfabric.mixin;
|
package wtf.hak.survivalfabric.mixin;
|
||||||
|
|
||||||
import com.mojang.authlib.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
import net.minecraft.network.message.MessageType;
|
import net.minecraft.network.message.MessageType;
|
||||||
import net.minecraft.network.message.SignedMessage;
|
import net.minecraft.network.message.SignedMessage;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.PlayerManager;
|
import net.minecraft.server.PlayerManager;
|
||||||
import net.minecraft.server.network.ConnectedClientData;
|
import net.minecraft.server.network.ConnectedClientData;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@ -18,9 +16,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
import wtf.hak.survivalfabric.commands.SpectatorCommand;
|
||||||
import wtf.hak.survivalfabric.config.ConfigManager;
|
import wtf.hak.survivalfabric.config.ConfigManager;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.beans.Expression;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Mixin(PlayerManager.class)
|
@Mixin(PlayerManager.class)
|
||||||
@ -62,7 +57,8 @@ public abstract class PlayerManagerMixin {
|
|||||||
String result = String.valueOf(evaluateExpression(expression));
|
String result = String.valueOf(evaluateExpression(expression));
|
||||||
if (rawMessage.contains(" ")) rawMessage += " ";
|
if (rawMessage.contains(" ")) rawMessage += " ";
|
||||||
rawMessage += (result.endsWith(".0")) ? result.substring(0, result.length() - 2) : result;
|
rawMessage += (result.endsWith(".0")) ? result.substring(0, result.length() - 2) : result;
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Text text = Text.literal(String.format(ConfigManager.getConfig().chatMessage, sender.getName().getString(), rawMessage));
|
Text text = Text.literal(String.format(ConfigManager.getConfig().chatMessage, sender.getName().getString(), rawMessage));
|
||||||
sender.getServer().getPlayerManager().broadcast(text, false);
|
sender.getServer().getPlayerManager().broadcast(text, false);
|
||||||
@ -78,7 +74,8 @@ public abstract class PlayerManagerMixin {
|
|||||||
Text formattedMessage = Text.literal("<" + sender.getName().getString() + "> " + rawMessage);
|
Text formattedMessage = Text.literal("<" + sender.getName().getString() + "> " + rawMessage);
|
||||||
sender.getServer().getPlayerManager().broadcast(formattedMessage, false);
|
sender.getServer().getPlayerManager().broadcast(formattedMessage, false);
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user