generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
3f74aa3
commit 3adfb1b
Showing
20 changed files
with
370 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/com/joacarpet/commands/BlockTicklingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
src/main/java/com/joacarpet/mixin/MinecraftServerMixin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.