|
@@ -1,15 +1,13 @@
|
|
|
package me.shedaniel.rei;
|
|
|
|
|
|
import me.shedaniel.rei.gui.widget.ItemListOverlay;
|
|
|
-import net.fabricmc.api.EnvType;
|
|
|
import net.fabricmc.api.ModInitializer;
|
|
|
-import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
|
|
|
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
|
|
|
-import net.fabricmc.loader.api.FabricLoader;
|
|
|
import net.minecraft.client.resource.language.I18n;
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
|
import net.minecraft.text.StringTextComponent;
|
|
|
+import net.minecraft.text.TextFormat;
|
|
|
import net.minecraft.text.TranslatableTextComponent;
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
|
@@ -17,7 +15,6 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer {
|
|
|
|
|
|
public static final Identifier DELETE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "delete_item");
|
|
|
public static final Identifier CREATE_ITEMS_PACKET = new Identifier("roughlyenoughitems", "create_item");
|
|
|
- public static final Identifier REI_ON_SERVER_PACKET = new Identifier("roughlyenoughitems", "rei_on_server");
|
|
|
|
|
|
@Override
|
|
|
public void onInitialize() {
|
|
@@ -29,24 +26,15 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer {
|
|
|
ServerSidePacketRegistry.INSTANCE.register(CREATE_ITEMS_PACKET, (packetContext, packetByteBuf) -> {
|
|
|
ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer();
|
|
|
ItemStack stack = packetByteBuf.readItemStack();
|
|
|
+ if (!player.getServer().getCommandSource().hasPermissionLevel(1)) {
|
|
|
+ player.addChatMessage(new TranslatableTextComponent("text.rei.no_permission_cheat").applyFormat(TextFormat.RED), false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (player.inventory.insertStack(stack.copy()))
|
|
|
player.addChatMessage(new StringTextComponent(I18n.translate("text.rei.cheat_items").replaceAll("\\{item_name}", ItemListOverlay.tryGetItemStackName(stack.copy())).replaceAll("\\{item_count}", stack.copy().getAmount() + "").replaceAll("\\{player_name}", player.getEntityName())), false);
|
|
|
else
|
|
|
player.addChatMessage(new TranslatableTextComponent("text.rei.failed_cheat_items"), false);
|
|
|
});
|
|
|
- ClientSidePacketRegistry.INSTANCE.register(REI_ON_SERVER_PACKET, (packetContext, packetByteBuf) -> {
|
|
|
- if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
|
|
- try {
|
|
|
- Class.forName("me.shedaniel.rei.RoughlyEnoughItemsCore").getDeclaredField("reiIsOnServer").set(null, true);
|
|
|
- } catch (IllegalAccessException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (NoSuchFieldException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (ClassNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
}
|