1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-31 05:33:00 +00:00

Merge branch 'mc-1.19.x' into mc-1.20.x

This commit is contained in:
Jonathan Coates
2023-06-10 09:07:41 +01:00
18 changed files with 93 additions and 131 deletions

View File

@@ -23,7 +23,7 @@ import java.util.Objects;
* A {@link TableFormatter} subclass which writes directly to {@linkplain ChatComponent the chat GUI}.
* <p>
* Each message written gets a special {@link GuiMessageTag}, so we can remove the previous table of the same
* {@link TableBuilder#getId() id}.
* {@linkplain TableBuilder#getId() id}.
*/
public class ClientTableFormatter implements TableFormatter {
public static final ClientTableFormatter INSTANCE = new ClientTableFormatter();

View File

@@ -15,6 +15,7 @@ import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.narration.NarratedElementType;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
import org.lwjgl.glfw.GLFW;
@@ -81,6 +82,11 @@ public class TerminalWidget extends AbstractWidget {
@Override
public boolean keyPressed(int key, int scancode, int modifiers) {
if (key == GLFW.GLFW_KEY_ESCAPE) return false;
if (Screen.isPaste(key)) {
paste();
return true;
}
if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0) {
switch (key) {
case GLFW.GLFW_KEY_T -> {
@@ -92,32 +98,6 @@ public class TerminalWidget extends AbstractWidget {
case GLFW.GLFW_KEY_R -> {
if (rebootTimer < 0) rebootTimer = 0;
}
case GLFW.GLFW_KEY_V -> {
// Ctrl+V for paste
var clipboard = Minecraft.getInstance().keyboardHandler.getClipboard();
if (clipboard != null) {
// Clip to the first occurrence of \r or \n
var newLineIndex1 = clipboard.indexOf("\r");
var newLineIndex2 = clipboard.indexOf("\n");
if (newLineIndex1 >= 0 && newLineIndex2 >= 0) {
clipboard = clipboard.substring(0, Math.min(newLineIndex1, newLineIndex2));
} else if (newLineIndex1 >= 0) {
clipboard = clipboard.substring(0, newLineIndex1);
} else if (newLineIndex2 >= 0) {
clipboard = clipboard.substring(0, newLineIndex2);
}
// Filter the string
clipboard = SharedConstants.filterText(clipboard);
if (!clipboard.isEmpty()) {
// Clip to 512 characters and queue the event
if (clipboard.length() > 512) clipboard = clipboard.substring(0, 512);
computer.queueEvent("paste", new Object[]{ clipboard });
}
return true;
}
}
}
}
@@ -131,6 +111,29 @@ public class TerminalWidget extends AbstractWidget {
return true;
}
private void paste() {
var clipboard = Minecraft.getInstance().keyboardHandler.getClipboard();
// Clip to the first occurrence of \r or \n
var newLineIndex1 = clipboard.indexOf('\r');
var newLineIndex2 = clipboard.indexOf('\n');
if (newLineIndex1 >= 0 && newLineIndex2 >= 0) {
clipboard = clipboard.substring(0, Math.min(newLineIndex1, newLineIndex2));
} else if (newLineIndex1 >= 0) {
clipboard = clipboard.substring(0, newLineIndex1);
} else if (newLineIndex2 >= 0) {
clipboard = clipboard.substring(0, newLineIndex2);
}
// Filter the string
clipboard = SharedConstants.filterText(clipboard);
if (!clipboard.isEmpty()) {
// Clip to 512 characters and queue the event
if (clipboard.length() > 512) clipboard = clipboard.substring(0, 512);
computer.queueEvent("paste", new Object[]{ clipboard });
}
}
@Override
public boolean keyReleased(int key, int scancode, int modifiers) {
// Queue the "key_up" event and remove from the down set

View File

@@ -5,15 +5,11 @@
package dan200.computercraft.shared.details;
import com.google.gson.JsonParseException;
import dan200.computercraft.shared.platform.PlatformHelper;
import dan200.computercraft.shared.platform.RegistryWrappers;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.EnchantedBookItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@@ -46,7 +42,9 @@ public class ItemDetails {
}
data.put("tags", DetailHelpers.getTags(stack.getTags()));
data.put("itemGroups", getItemGroups(stack));
// Include deprecated itemGroups field
data.put("itemGroups", List.of());
var tag = stack.getTag();
if (tag != null && tag.contains("display", Tag.TAG_COMPOUND)) {
@@ -85,25 +83,6 @@ public class ItemDetails {
}
}
/**
* Retrieve all item groups an item stack pertains to.
*
* @param stack Stack to analyse
* @return A filled list that contains pairs of item group IDs and their display names.
*/
private static List<Map<String, Object>> getItemGroups(ItemStack stack) {
return CreativeModeTabs.allTabs().stream()
.filter(x -> x.shouldDisplay() && x.getType() == CreativeModeTab.Type.CATEGORY && x.contains(stack))
.map(group -> {
Map<String, Object> groupData = new HashMap<>(2);
groupData.put("id", PlatformHelper.get().getRegistryKey(Registries.CREATIVE_MODE_TAB, group).toString());
groupData.put("displayName", group.getDisplayName().getString());
return groupData;
})
.toList();
}
/**
* Retrieve all visible enchantments from given stack. Try to follow all tooltip rules : order and visibility.
*

View File

@@ -319,7 +319,6 @@ public class TurtleBrain implements TurtleAccessInternal {
return false;
}
@Override
public Vec3 getVisualPosition(float f) {
var offset = getRenderOffset(f);
var pos = owner.getBlockPos();
@@ -330,7 +329,6 @@ public class TurtleBrain implements TurtleAccessInternal {
);
}
@Override
public float getVisualYaw(float f) {
var yaw = getDirection().toYRot();
switch (animation) {

View File

@@ -169,7 +169,7 @@ public class TurtlePlaceCommand implements TurtleCommand {
if (Math.abs(hitY - 0.5f) < 0.01f) hitY = 0.45f;
// Check if there's something suitable to place onto
var hit = new BlockHitResult(new Vec3(hitX, hitY, hitZ), side, position, false);
var hit = new BlockHitResult(new Vec3(position.getX() + hitX, position.getY() + hitY, position.getZ() + hitZ), side, position, false);
var context = new UseOnContext(turtlePlayer.player(), InteractionHand.MAIN_HAND, hit);
if (!canDeployOnBlock(new BlockPlaceContext(context), turtle, turtlePlayer, position, side, adjacent, outErrorMessage)) {
return false;