Skip to content

Commit

Permalink
Made blocktickling per-player.
Browse files Browse the repository at this point in the history
Added the /blocktickling command, which lets you configure blockUpdates, shapeUpdates, and overrideRightclick toggles individually.
Added two miscellaneous enderman griefing and elytra rocketing toggles for survival.
Bump version to 2.1.0
  • Loading branch information
JoakimThorsen committed Jan 2, 2024
1 parent 3f74aa3 commit 3adfb1b
Show file tree
Hide file tree
Showing 20 changed files with 370 additions and 161 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Mod Properties
mod_id=joacarpet
mod_name=JoaCarpet
mod_version=2.0.0
mod_version=2.1.0
maven_group=me.fallenbreath
archives_base_name=joacarpet

Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/joacarpet/BlockTicklingSetting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* This file is part of the JoaCarpet project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Joa and contributors
*
* JoaCarpet is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JoaCarpet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JoaCarpet. If not, see <https://www.gnu.org/licenses/>.
*/

package com.joacarpet;

import net.minecraft.world.item.context.UseOnContext;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public enum BlockTicklingSetting {

BLOCKUPDATES ("blockUpdates", "Block Updates", false),
SHAPEUPDATES ("shapeUpdates", "Shape Updates", false),
OVERRIDERIGHTCLICK ("overrideRightclick", "Override Rightclick", false);

private static final Map<UUID, Map<BlockTicklingSetting, Boolean>> playerSettingMap = new HashMap<>();
private static final Map<String, BlockTicklingSetting> fromCommandKey = new HashMap<>();

private final String commandKey;
private final String name;
private final Boolean defaultSetting;
BlockTicklingSetting(String commandKey, String name, Boolean defaultSetting) {
this.commandKey = commandKey;
this.name = name;
this.defaultSetting = defaultSetting;
}

static
{
for(BlockTicklingSetting i : values())
{
fromCommandKey.put(i.commandKey, i);
}
}
public static BlockTicklingSetting fromCommandKey(String key) {
return fromCommandKey.get(key);
}

public static Iterable<String> commandKeys() {
return fromCommandKey.keySet();
}

public static Boolean get(BlockTicklingSetting setting, UUID uuid) {
return playerSettingMap
.getOrDefault(uuid, new HashMap<>())
.getOrDefault(setting, setting.defaultSetting);
}

public static Boolean get(BlockTicklingSetting setting, UseOnContext useOnContext) {
var player = useOnContext.getPlayer();
if (player == null)
return setting.defaultSetting;
return get(setting, player.getUUID());
}

public static void set(BlockTicklingSetting setting, UUID uuid, Boolean bool) {
playerSettingMap.computeIfAbsent(uuid, k -> new HashMap<>()).put(setting, bool);
}

public String getName()
{
return name;
}
}
55 changes: 0 additions & 55 deletions src/main/java/com/joacarpet/HelloWorldTemplate.java

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/java/com/joacarpet/JoaCarpetMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import carpet.CarpetServer;
import carpet.utils.Messenger;
import carpet.utils.Translations;
import com.joacarpet.commands.BlockTicklingCommand;
import com.joacarpet.commands.InsaneBehaviorsCommand;
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.api.ModInitializer;
Expand All @@ -49,7 +50,7 @@
public class JoaCarpetMod implements ModInitializer, CarpetExtension {
public static final Logger LOGGER =
//#if MC >= 11800
LoggerFactory.getLogger("joacarpet");
LoggerFactory.getLogger("joacarpet");
//#else
//$$ LogManager.getLogger("joacarpet");
//#endif
Expand All @@ -69,6 +70,7 @@ public void registerCommands(CommandDispatcher<CommandSourceStack> dispatcher
//#endif
) {
InsaneBehaviorsCommand.register(dispatcher);
BlockTicklingCommand.register(dispatcher);
}

@Override
Expand Down
43 changes: 29 additions & 14 deletions src/main/java/com/joacarpet/JoaCarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,12 @@

//#if MC >= 11900
import carpet.api.settings.Rule;
import static carpet.api.settings.RuleCategory.*;
//#else
//$$ import carpet.settings.Rule;
//$$ import static carpet.settings.RuleCategory.*;
//#endif

//#if MC >= 11900
import static carpet.api.settings.RuleCategory.COMMAND;
import static carpet.api.settings.RuleCategory.CREATIVE;
//#else
//$$ import static carpet.settings.RuleCategory.COMMAND;
//$$ import static carpet.settings.RuleCategory.CREATIVE;
//#endif


public class JoaCarpetSettings {
public static final String JOA = "JoaCarpet";

Expand Down Expand Up @@ -62,12 +55,34 @@ public class JoaCarpetSettings {

@Rule(
//#if MC >= 11900
categories = {CREATIVE, JOA},
categories = {COMMAND, CREATIVE, JOA},
//#else
//$$ category = {CREATIVE, JOA},
//$$ desc="Lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with update interations off or with budded blocks.",
//$$ category = {COMMAND, CREATIVE, JOA},
//$$ desc="Controls who can use the `/blocktickling` command, which lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with budded blocks, with /carpet interactionUpdates off, or with intricarpet's /interaction command.",
//#endif
options = {"true", "ops", "false", "0", "1", "2", "3", "4"}
)
public static String commandBlockTickling = "ops";

@Rule(
//#if MC >= 11900
categories = {SURVIVAL, JOA},
//#else
//$$ category = {SURVIVAL, JOA},
//$$ desc="Disables enderman griefing.",
//#endif
options = {"true", "false"}
)
public static String disableEndermanGriefing = "false";

@Rule(
//#if MC >= 11900
categories = {SURVIVAL, JOA},
//#else
//$$ category = {SURVIVAL, JOA},
//$$ desc="Disables using rockets with elytra.",
//#endif
options = {"off", "blockupdates", "shapeupdates", "both"}
options = {"true", "false"}
)
public static String blockTickling = "off";
public static String disableElytraRockets = "false";
}
100 changes: 100 additions & 0 deletions src/main/java/com/joacarpet/commands/BlockTicklingCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of the JoaCarpet project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Joa and contributors
*
* JoaCarpet is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JoaCarpet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JoaCarpet. If not, see <https://www.gnu.org/licenses/>.
*/

package com.joacarpet.commands;

import com.joacarpet.BlockTicklingSetting;
import com.joacarpet.JoaCarpetSettings;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import carpet.utils.Messenger;
import carpet.settings.SettingsManager;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer;

import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.BoolArgumentType.getBool;
import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.SharedSuggestionProvider.suggest;

public class BlockTicklingCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(literal("blocktickling")
.requires((player) -> SettingsManager.canUseCommand(player, JoaCarpetSettings.commandBlockTickling))
.then(argument("BlockTicklingSetting", StringArgumentType.word())
.suggests((c, b) -> suggest(BlockTicklingSetting.commandKeys(), b))
.then(argument("value", BoolArgumentType.bool())
.executes(BlockTicklingCommand::setBlockTicklingSetting)
)
.executes(BlockTicklingCommand::getBlockTicklingSetting)
)
);
}

private static String k(BlockTicklingSetting blockTicklingSetting)
{
return "c " + blockTicklingSetting.getName();
}

private static String v(boolean value)
{
return (value ? "l " : "r ") + value;
}

private static int setBlockTicklingSetting(CommandContext<CommandSourceStack> c)
{
try
{
ServerPlayer player = c.getSource().getPlayerOrException();
BlockTicklingSetting i = BlockTicklingSetting.fromCommandKey(getString(c, "BlockTicklingSetting"));
boolean value = getBool(c, "value");
BlockTicklingSetting.set(i, player.getUUID(), value);
Messenger.m(c.getSource(), "g BlockTickling setting ", k(i), "g set to ", v(value));
return 0;
}
catch(CommandSyntaxException e)
{
Messenger.m(c.getSource(), "r BlockTickling command must be executed by a player");
return 1;
}
}

private static int getBlockTicklingSetting(CommandContext<CommandSourceStack> c)
{
try
{
ServerPlayer player = c.getSource().getPlayerOrException();
BlockTicklingSetting i = BlockTicklingSetting.fromCommandKey(getString(c, "BlockTicklingSetting"));
Messenger.m(c.getSource(), "g BlockTickling setting ", k(i), "g is currently set to ", v(BlockTicklingSetting.get(i, player.getUUID())));
return 0;
}
catch(CommandSyntaxException e)
{
Messenger.m(c.getSource(), "r BlockTickling command must be executed by a player");
return 1;
}
}
}
53 changes: 0 additions & 53 deletions src/main/java/com/joacarpet/mixin/MinecraftServerMixin.java

This file was deleted.

Loading

0 comments on commit 3adfb1b

Please sign in to comment.