mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +00:00
Minor fixes and cleanup
My working tree is a mess, so this is not a good commit. I'm making a bit of a habit of this. - Fix UserLevel.OWNER check failing on single player servers. - Correctly handle the "open folder" fake command. - Some reshuffling of Forge-specific methods to make Fabric slightly easier.
This commit is contained in:
parent
8360e8234d
commit
b2b58892e3
@ -52,14 +52,19 @@ public interface ComputerCraftAPIService {
|
||||
|
||||
@Nullable
|
||||
IMount createResourceMount(String domain, String subPath);
|
||||
// TODO(1.19.3): Make this take a MinecraftServer argument.
|
||||
|
||||
@Deprecated
|
||||
void registerPeripheralProvider(IPeripheralProvider provider);
|
||||
default void registerPeripheralProvider(IPeripheralProvider provider) {
|
||||
throw new UnsupportedOperationException("Can only register peripheral provider on Forge");
|
||||
}
|
||||
|
||||
void registerGenericSource(GenericSource source);
|
||||
|
||||
@Deprecated
|
||||
void registerGenericCapability(Capability<?> capability);
|
||||
default void registerGenericCapability(Capability<?> capability) {
|
||||
throw new UnsupportedOperationException("Can only register Capability on Forge");
|
||||
}
|
||||
|
||||
void registerBundledRedstoneProvider(IBundledRedstoneProvider provider);
|
||||
|
||||
@ -76,7 +81,9 @@ public interface ComputerCraftAPIService {
|
||||
|
||||
IWiredNode createWiredNodeForElement(IWiredElement element);
|
||||
|
||||
LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side);
|
||||
default LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
|
||||
throw new UnsupportedOperationException("Can only call getWiredElementAt on Forge");
|
||||
}
|
||||
|
||||
void registerRefuelHandler(TurtleRefuelHandler handler);
|
||||
|
||||
|
@ -16,25 +16,33 @@ import dan200.computercraft.client.render.monitor.MonitorHighlightRenderer;
|
||||
import dan200.computercraft.client.render.monitor.MonitorRenderState;
|
||||
import dan200.computercraft.client.sound.SpeakerManager;
|
||||
import dan200.computercraft.shared.CommonHooks;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.command.CommandComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ServerContext;
|
||||
import dan200.computercraft.shared.media.items.PrintoutItem;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableBlock;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorBlockEntity;
|
||||
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
|
||||
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
|
||||
import dan200.computercraft.shared.util.PauseAwareTimer;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.sounds.AudioStream;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -159,4 +167,24 @@ public final class ClientHooks {
|
||||
var upgrade = turtle.getUpgrade(side);
|
||||
if (upgrade != null) out.accept(String.format("Upgrade[%s]: %s", side, upgrade.getUpgradeID()));
|
||||
}
|
||||
|
||||
public static @Nullable BlockState getBlockBreakingState(BlockState state, BlockPos pos) {
|
||||
// Only apply to cables which have both a cable and modem
|
||||
if (state.getBlock() != ModRegistry.Blocks.CABLE.get()
|
||||
|| !state.getValue(CableBlock.CABLE)
|
||||
|| state.getValue(CableBlock.MODEM) == CableModemVariant.None
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var hit = Minecraft.getInstance().hitResult;
|
||||
if (hit == null || hit.getType() != HitResult.Type.BLOCK) return null;
|
||||
var hitPos = ((BlockHitResult) hit).getBlockPos();
|
||||
|
||||
if (!hitPos.equals(pos)) return null;
|
||||
|
||||
return WorldUtil.isVecInside(CableShapes.getModemShape(state), hit.getLocation().subtract(pos.getX(), pos.getY(), pos.getZ()))
|
||||
? state.getBlock().defaultBlockState().setValue(CableBlock.MODEM, state.getValue(CableBlock.MODEM))
|
||||
: state.setValue(CableBlock.MODEM, CableModemVariant.None);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu;
|
||||
import dan200.computercraft.shared.computer.inventory.ViewComputerMenu;
|
||||
import dan200.computercraft.shared.media.items.DiskItem;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.shared.media.items.TreasureDiskItem;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@ -137,7 +137,7 @@ public final class ClientRegistry {
|
||||
);
|
||||
|
||||
register.accept(
|
||||
(stack, layer) -> layer == 1 ? ItemTreasureDisk.getColour(stack) : 0xFFFFFF,
|
||||
(stack, layer) -> layer == 1 ? TreasureDiskItem.getColour(stack) : 0xFFFFFF,
|
||||
ModRegistry.Items.TREASURE_DISK.get()
|
||||
);
|
||||
|
||||
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.mixin.client;
|
||||
|
||||
import dan200.computercraft.client.ClientHooks;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
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;
|
||||
|
||||
@Mixin(LocalPlayer.class)
|
||||
class LocalPlayerMixin {
|
||||
@Inject(method = "commandUnsigned", at = @At("HEAD"), cancellable = true)
|
||||
void commandUnsigned(String message, CallbackInfoReturnable<Boolean> ci) {
|
||||
if (ClientHooks.onChatMessage(message)) ci.setReturnValue(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "dan200.computercraft.mixin.client",
|
||||
"minVersion": "0.8",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"client": [
|
||||
"LocalPlayerMixin"
|
||||
],
|
||||
"refmap": "client-computercraft.refmap.json"
|
||||
}
|
@ -34,9 +34,9 @@ import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
|
||||
import dan200.computercraft.shared.details.BlockDetails;
|
||||
import dan200.computercraft.shared.details.ItemDetails;
|
||||
import dan200.computercraft.shared.media.items.DiskItem;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
import dan200.computercraft.shared.media.items.PrintoutItem;
|
||||
import dan200.computercraft.shared.media.items.RecordMedia;
|
||||
import dan200.computercraft.shared.media.items.TreasureDiskItem;
|
||||
import dan200.computercraft.shared.media.recipes.DiskRecipe;
|
||||
import dan200.computercraft.shared.media.recipes.PrintoutRecipe;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
@ -227,8 +227,8 @@ public final class ModRegistry {
|
||||
|
||||
public static final RegistryEntry<DiskItem> DISK =
|
||||
REGISTRY.register("disk", () -> new DiskItem(properties().stacksTo(1)));
|
||||
public static final RegistryEntry<ItemTreasureDisk> TREASURE_DISK =
|
||||
REGISTRY.register("treasure_disk", () -> new ItemTreasureDisk(properties().stacksTo(1)));
|
||||
public static final RegistryEntry<TreasureDiskItem> TREASURE_DISK =
|
||||
REGISTRY.register("treasure_disk", () -> new TreasureDiskItem(properties().stacksTo(1)));
|
||||
|
||||
public static final RegistryEntry<PrintoutItem> PRINTED_PAGE = REGISTRY.register("printed_page",
|
||||
() -> new PrintoutItem(properties().stacksTo(1), PrintoutItem.Type.PAGE));
|
||||
|
@ -50,7 +50,7 @@ import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public final class CommandComputerCraft {
|
||||
public static final UUID SYSTEM_UUID = new UUID(0, 0);
|
||||
public static final String OPEN_COMPUTER = "/computercraft open-computer ";
|
||||
public static final String OPEN_COMPUTER = "computercraft open-computer ";
|
||||
|
||||
private CommandComputerCraft() {
|
||||
}
|
||||
@ -306,7 +306,7 @@ public final class CommandComputerCraft {
|
||||
|
||||
return link(
|
||||
text("\u270E"),
|
||||
OPEN_COMPUTER + id,
|
||||
"/" + OPEN_COMPUTER + id,
|
||||
translate("commands.computercraft.dump.open_path")
|
||||
);
|
||||
}
|
||||
|
@ -55,6 +55,6 @@ public enum UserLevel implements Predicate<CommandSourceStack> {
|
||||
var sender = source.getEntity();
|
||||
return server.isDedicatedServer()
|
||||
? source.getEntity() == null && source.hasPermission(4) && source.getTextName().equals("Server")
|
||||
: sender instanceof Player player && player.getGameProfile().getName().equalsIgnoreCase(server.getServerModName());
|
||||
: sender instanceof Player player && server.isSingleplayerOwner(player.getGameProfile());
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import dan200.computercraft.shared.computer.menu.ServerInputHandler;
|
||||
import dan200.computercraft.shared.computer.menu.ServerInputState;
|
||||
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
||||
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.container.SingleContainerData;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
|
@ -7,8 +7,8 @@ package dan200.computercraft.shared.computer.inventory;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.container.InvisibleSlot;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
@ -27,12 +27,12 @@ import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemTreasureDisk extends Item implements IMedia {
|
||||
public class TreasureDiskItem extends Item implements IMedia {
|
||||
private static final String NBT_TITLE = "Title";
|
||||
private static final String NBT_COLOUR = "Colour";
|
||||
private static final String NBT_SUB_PATH = "SubPath";
|
||||
|
||||
public ItemTreasureDisk(Properties settings) {
|
||||
public TreasureDiskItem(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
@ -247,7 +247,9 @@ public interface PlatformHelper extends dan200.computercraft.impl.PlatformHelper
|
||||
* @deprecated This is only needed for backwards compatibility, and will be removed in 1.19.3.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
IItemHandlerModifiable wrapContainerToItemHandler(Container container);
|
||||
default IItemHandlerModifiable wrapContainerToItemHandler(Container container) {
|
||||
throw new UnsupportedOperationException("Can only create IItemHandlerModifiable on Forge");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link RecipeIngredients} for this loader.
|
||||
|
@ -9,10 +9,10 @@ import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu;
|
||||
import dan200.computercraft.shared.container.SingleContainerData;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import dan200.computercraft.shared.turtle.blocks.TurtleBlockEntity;
|
||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||
import dan200.computercraft.shared.container.SingleContainerData;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
@ -11,7 +11,6 @@ import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import dan200.computercraft.impl.AbstractComputerCraftAPI;
|
||||
import dan200.computercraft.impl.ComputerCraftAPIService;
|
||||
import dan200.computercraft.shared.network.NetworkMessage;
|
||||
@ -41,7 +40,6 @@ import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@ -50,9 +48,6 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
@ -235,29 +230,9 @@ public class TestPlatformHelper extends AbstractComputerCraftAPI implements Plat
|
||||
throw new UnsupportedOperationException("Cannot create resource mount");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPeripheralProvider(IPeripheralProvider provider) {
|
||||
throw new UnsupportedOperationException("Cannot register peripheral provider");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGenericCapability(Capability<?> capability) {
|
||||
throw new UnsupportedOperationException("Cannot register generic capability");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyOptional<IWiredElement> getWiredElementAt(BlockGetter world, BlockPos pos, Direction side) {
|
||||
throw new UnsupportedOperationException("Cannot get wired element");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T tryGetRegistryObject(ResourceKey<Registry<T>> registry, ResourceLocation id) {
|
||||
throw new UnsupportedOperationException("Cannot query registries");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandlerModifiable wrapContainerToItemHandler(Container container) {
|
||||
throw new UnsupportedOperationException("Cannot wrap item handler ");
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,10 @@ minecraft {
|
||||
|
||||
mixin {
|
||||
add(sourceSets.main.get(), "computercraft.mixins.refmap.json")
|
||||
add(sourceSets.client.get(), "computercraft-client.mixins.refmap.json")
|
||||
|
||||
config("computercraft.mixins.json")
|
||||
config("computercraft-client.mixins.json")
|
||||
config("computercraft-client.forge.mixins.json")
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,10 @@ package dan200.computercraft.client;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.client.sound.SpeakerSound;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderHighlightEvent;
|
||||
import net.minecraftforge.client.event.RenderItemInFrameEvent;
|
||||
import net.minecraftforge.client.event.sound.PlayStreamingSourceEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
@ -46,11 +49,6 @@ public final class ForgeClientHooks {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onClientSendMessage(ClientChatEvent event) {
|
||||
if (ClientHooks.onChatMessage(event.getMessage())) event.setCanceled(true);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderText(CustomizeGuiOverlayEvent.DebugText event) {
|
||||
ClientHooks.addDebugInfo(event.getRight()::add);
|
||||
|
@ -7,12 +7,7 @@ package dan200.computercraft.mixin.client;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableBlock;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import dan200.computercraft.client.ClientHooks;
|
||||
import net.minecraft.client.renderer.block.BlockModelShaper;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.block.ModelBlockRenderer;
|
||||
@ -21,8 +16,6 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@ -60,27 +53,15 @@ public class BlockRenderDispatcherMixin {
|
||||
BlockState state, BlockPos pos, BlockAndTintGetter world, PoseStack pose, VertexConsumer buffers, ModelData modelData,
|
||||
CallbackInfo info
|
||||
) {
|
||||
// Only apply to cables which have both a cable and modem
|
||||
if (state.getBlock() != ModRegistry.Blocks.CABLE.get()
|
||||
|| !state.getValue(CableBlock.CABLE)
|
||||
|| state.getValue(CableBlock.MODEM) == CableModemVariant.None
|
||||
) {
|
||||
return;
|
||||
var newState = ClientHooks.getBlockBreakingState(state, pos);
|
||||
if (newState != null) {
|
||||
info.cancel();
|
||||
|
||||
var model = blockModelShaper.getBlockModel(newState);
|
||||
modelRenderer.tesselateBlock(
|
||||
world, model, newState, pos, pose, buffers, true, random, newState.getSeed(pos),
|
||||
OverlayTexture.NO_OVERLAY, modelData, null
|
||||
);
|
||||
}
|
||||
|
||||
var hit = Minecraft.getInstance().hitResult;
|
||||
if (hit == null || hit.getType() != HitResult.Type.BLOCK) return;
|
||||
var hitPos = ((BlockHitResult) hit).getBlockPos();
|
||||
|
||||
if (!hitPos.equals(pos)) return;
|
||||
|
||||
info.cancel();
|
||||
var newState = WorldUtil.isVecInside(CableShapes.getModemShape(state), hit.getLocation().subtract(pos.getX(), pos.getY(), pos.getZ()))
|
||||
? state.getBlock().defaultBlockState().setValue(CableBlock.MODEM, state.getValue(CableBlock.MODEM))
|
||||
: state.setValue(CableBlock.MODEM, CableModemVariant.None);
|
||||
|
||||
var model = blockModelShaper.getBlockModel(newState);
|
||||
var seed = newState.getSeed(pos);
|
||||
modelRenderer.tesselateBlock(world, model, newState, pos, pose, buffers, true, random, seed, OverlayTexture.NO_OVERLAY, modelData, null);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user