Skip to content

Commit

Permalink
Merge pull request #197 from RedstoneTools/dev
Browse files Browse the repository at this point in the history
Update to 1.1.2
  • Loading branch information
Matthias1590 authored Jun 2, 2023
2 parents 4d44458 + 3a08264 commit f66ff95
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 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 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.14.6

# Mod Properties
mod_version = 1.18.2-1.1.1
mod_version = 1.18.2-1.1.2
maven_group = tools.redstone
archives_base_name = redstonetools

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected Feedback execute(ServerCommandSource source) throws CommandSyntaxExcep

// prevent infinite loop
if (direction.lengthSq() == 0) {
direction = BlockVector3.at(1, 1, 1);
direction = BlockVector3.at(0, 0, 1);
}

var spacingVector = direction.multiply(offset.getValue());

if (direction.getX() + direction.getBlockY() + direction.getBlockZ() > 1) {
if (direction.getBlockX() + direction.getBlockY() + direction.getBlockZ() > 1) {
return Feedback.invalidUsage("The selection must have 2 axis the same");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package tools.redstone.redstonetools.features.commands;

import tools.redstone.redstonetools.features.Feature;
import tools.redstone.redstonetools.features.feedback.Feedback;
import tools.redstone.redstonetools.utils.BlockInfo;
import tools.redstone.redstonetools.utils.BlockStateNbtUtil;
import com.mojang.datafixers.util.Either;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.server.command.ServerCommandSource;

import java.lang.reflect.Method;
import tools.redstone.redstonetools.features.Feature;
import tools.redstone.redstonetools.features.feedback.Feedback;
import tools.redstone.redstonetools.mixin.MinecraftClientAccessor;
import tools.redstone.redstonetools.utils.BlockInfo;
import tools.redstone.redstonetools.utils.BlockStateNbtUtil;

@Feature(name = "Copy State", description = "Gives you a copy of the block you're looking at with its BlockState.", command = "copystate")
public class CopyStateFeature extends PickBlockFeature {
Expand All @@ -25,7 +23,7 @@ protected Either<ItemStack, Feedback> getItemStack(ServerCommandSource source, B
ItemStack itemStack = blockInfo.block.getPickStack(client.world, blockInfo.pos, blockInfo.state);

if (blockInfo.state.hasBlockEntity()) {
addBlockEntityNbt(itemStack, blockInfo.entity);
((MinecraftClientAccessor) client).addBlockEntityNbt(itemStack, blockInfo.entity);
}

int i = addBlockStateNbt(itemStack, blockInfo.state);
Expand Down Expand Up @@ -56,18 +54,4 @@ private void addBlockStateText(ItemStack itemStack) {
displayNbt.put("Lore", loreList);
itemStack.setSubNbt("display", displayNbt);
}

private void addBlockEntityNbt(ItemStack itemStack, BlockEntity blockEntity) {
try {
Class<? extends MinecraftClient> clientClass = MinecraftClient.class;
MinecraftClient clientClassInstance = MinecraftClient.getInstance();
Method m = clientClass.getDeclaredMethod("addBlockEntityNbt", ItemStack.class, BlockEntity.class);

m.setAccessible(true);
m.invoke(clientClassInstance, itemStack, blockEntity);
m.setAccessible(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tools.redstone.redstonetools.mixin;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(MinecraftClient.class)
public interface MinecraftClientAccessor {
@Invoker("addBlockEntityNbt")
ItemStack addBlockEntityNbt(ItemStack stack, BlockEntity blockEntity);
}
1 change: 1 addition & 0 deletions src/main/resources/redstonetools.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"CommandSuggestorMixin",
"CrashTelemetryMixin",
"KeyBindingMixinImpl",
"MinecraftClientAccessor",
"TelemetryInitializeMixin"
]
}

0 comments on commit f66ff95

Please sign in to comment.