Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private void keybindW(WTable table, KeybindSetting setting) {
private void blockW(WTable table, BlockSetting setting) {
WHorizontalList list = table.add(theme.horizontalList()).expandX().widget();

WItem item = list.add(theme.item(setting.get().asItem().getDefaultStack())).widget();
WItem item = list.add(theme.block(setting.get())).widget();

WButton select = list.add(theme.button("Select")).widget();
select.action = () -> {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/meteordevelopment/meteorclient/gui/GuiTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import meteordevelopment.meteorclient.utils.misc.Keybind;
import meteordevelopment.meteorclient.utils.misc.Names;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import net.minecraft.block.Block;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -176,6 +178,16 @@ public WItemWithLabel itemWithLabel(ItemStack stack) {
return itemWithLabel(stack, Names.get(stack.getItem()));
}

public WItem block(Block block) {
return w(new WItem(BlockUtils.getDisplayStack(block)));
}
public WItemWithLabel blockWithLabel(Block block, String name) {
return w(new WItemWithLabel(BlockUtils.getDisplayStack(block), name));
}
public WItemWithLabel blockWithLabel(Block block) {
return blockWithLabel(block, Names.get(block));
}

public WTexture texture(double width, double height, double rotation, Texture texture) {
return w(new WTexture(width, height, rotation, texture));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected boolean includeValue(Block value) {

@Override
protected WWidget getValueWidget(Block block) {
return theme.itemWithLabel(block.asItem().getDefaultStack(), Names.get(block));
return theme.blockWithLabel(block);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected boolean includeValue(Block value) {
}

@Override
protected WWidget getValueWidget(Block value) {
return theme.itemWithLabel(value.asItem().getDefaultStack(), Names.get(value));
protected WWidget getValueWidget(Block block) {
return theme.blockWithLabel(block);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void initTable() {
if (setting.filter != null && !setting.filter.test(block)) continue;
if (skipValue(block)) continue;

WItemWithLabel item = theme.itemWithLabel(block.asItem().getDefaultStack(), Names.get(block));
WItemWithLabel item = theme.blockWithLabel(block);
if (!filterText.isEmpty() && !Strings.CI.contains(item.getLabelText(), filterText)) continue;
table.add(item);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.game.ResourcePacksReloadedEvent;
import meteordevelopment.meteorclient.utils.PreInit;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.Block;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -76,7 +77,7 @@ public static String get(Item item) {
}

public static String get(Block block) {
return blockNames.computeIfAbsent(block, block1 -> StringHelper.stripTextFormat(I18n.translate(block1.getTranslationKey())));
return blockNames.computeIfAbsent(block, block1 -> BlockUtils.getDisplayName(block));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package meteordevelopment.meteorclient.utils.world;

import com.google.common.collect.ImmutableMap;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.systems.modules.Modules;
Expand All @@ -20,16 +21,23 @@
import net.minecraft.block.*;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.SlabType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.item.model.ItemModel;
import net.minecraft.client.render.item.model.MissingItemModel;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.effect.StatusEffectUtil;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.*;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -39,6 +47,9 @@
import net.minecraft.world.LightType;
import net.minecraft.world.World;

import java.util.Map;
import java.util.Set;

import static meteordevelopment.meteorclient.MeteorClient.mc;

@SuppressWarnings("ConstantConditions")
Expand Down Expand Up @@ -288,6 +299,99 @@ public static float calcBlockBreakingDelta2(BlockPos blockPos, float breakSpeed)
}
}

// GUI Display

// special blocks with no standard block models, manually map to item model
private static final Map<Block, Item> HARDCODED_MAPPINGS = Map.of(
Blocks.WATER, Items.WATER_BUCKET,
Blocks.LAVA, Items.LAVA_BUCKET,
Blocks.BUBBLE_COLUMN, Items.WATER_BUCKET,
Blocks.END_PORTAL, Items.ENDER_EYE,
Blocks.END_GATEWAY, Items.ENDER_EYE,
Blocks.PISTON_HEAD, Items.PISTON,
Blocks.MOVING_PISTON, Items.PISTON
);

// block whose block models look better than their item models
private static final Set<Block> FORCED_BLOCK_DISPLAY = Set.of(
Blocks.LAVA_CAULDRON, Blocks.POWDER_SNOW_CAULDRON
);

public static ItemStack getDisplayStack(Block block) {
ItemStack stack = block.asItem().getDefaultStack();
if (stack.isEmpty() == block.getDefaultState().isAir() && !FORCED_BLOCK_DISPLAY.contains(block)) {
return stack;
}

if (HARDCODED_MAPPINGS.containsKey(block)) {
return HARDCODED_MAPPINGS.get(block).getDefaultStack();
}

// replace with block model
Identifier blockId = Registries.BLOCK.getId(block);
Identifier displayModelId = MeteorClient.identifier(blockId.getPath() + "_display");

ItemModel model = MinecraftClient.getInstance().getBakedModelManager().getItemModel(displayModelId);

if (!(model instanceof MissingItemModel)) {
ItemStack replacement = Items.STICK.getDefaultStack(); // cant be air
replacement.set(DataComponentTypes.ITEM_MODEL, displayModelId);
return replacement;
}

// unknown missing block, render nothing
return stack;
}

private static final Map<Block, String> BLOCK_NAME_OVERRIDES = ImmutableMap.<Block, String>builder()
.put(Blocks.WALL_TORCH, "Wall Torch")
.put(Blocks.REDSTONE_WALL_TORCH, "Redstone Wall Torch")
.put(Blocks.SOUL_WALL_TORCH, "Soul Wall Torch")
.put(Blocks.COPPER_WALL_TORCH, "Copper Wall Torch")

.put(Blocks.SKELETON_WALL_SKULL, "Skeleton Wall Skull")
.put(Blocks.WITHER_SKELETON_WALL_SKULL, "Wither Skeleton Wall Skull")
.put(Blocks.ZOMBIE_WALL_HEAD, "Zombie Wall Head")
.put(Blocks.PLAYER_WALL_HEAD, "Player Wall Head")
.put(Blocks.DRAGON_WALL_HEAD, "Dragon Wall Head")
.put(Blocks.PIGLIN_WALL_HEAD, "Piglin Wall Head")
.put(Blocks.CREEPER_WALL_HEAD, "Creeper Wall Head")

.put(Blocks.OAK_WALL_SIGN, "Oak Wall Sign")
.put(Blocks.BIRCH_WALL_SIGN, "Birch Wall Sign")
.put(Blocks.SPRUCE_WALL_SIGN, "Spruce Wall Sign")
.put(Blocks.ACACIA_WALL_SIGN, "Acacia Wall Sign")
.put(Blocks.CHERRY_WALL_SIGN, "Cherry Wall Sign")
.put(Blocks.JUNGLE_WALL_SIGN, "Jungle Wall Sign")
.put(Blocks.BAMBOO_WALL_SIGN, "Bamboo Wall Sign")
.put(Blocks.WARPED_WALL_SIGN, "Warped Wall Sign")
.put(Blocks.CRIMSON_WALL_SIGN, "Crimson Wall Sign")
.put(Blocks.DARK_OAK_WALL_SIGN, "Dark Oak Wall Sign")
.put(Blocks.PALE_OAK_WALL_SIGN, "Pale Oak Wall Sign")
.put(Blocks.MANGROVE_WALL_SIGN, "Mangrove Wall Sign")

.put(Blocks.OAK_WALL_HANGING_SIGN, "Oak Wall Hanging Sign")
.put(Blocks.BIRCH_WALL_HANGING_SIGN, "Birch Wall Hanging Sign")
.put(Blocks.SPRUCE_WALL_HANGING_SIGN, "Spruce Wall Hanging Sign")
.put(Blocks.ACACIA_WALL_HANGING_SIGN, "Acacia Wall Hanging Sign")
.put(Blocks.CHERRY_WALL_HANGING_SIGN, "Cherry Wall Hanging Sign")
.put(Blocks.JUNGLE_WALL_HANGING_SIGN, "Jungle Wall Hanging Sign")
.put(Blocks.BAMBOO_WALL_HANGING_SIGN, "Bamboo Wall Hanging Sign")
.put(Blocks.WARPED_WALL_HANGING_SIGN, "Warped Wall Hanging Sign")
.put(Blocks.CRIMSON_WALL_HANGING_SIGN, "Crimson Wall Hanging Sign")
.put(Blocks.DARK_OAK_WALL_HANGING_SIGN, "Dark Oak Wall Hanging Sign")
.put(Blocks.PALE_OAK_WALL_HANGING_SIGN, "Pale Oak Wall Hanging Sign")
.put(Blocks.MANGROVE_WALL_HANGING_SIGN, "Mangrove Wall Hanging Sign")
.buildOrThrow();

public static String getDisplayName(Block block) {
if (BLOCK_NAME_OVERRIDES.containsKey(block) && mc.options.language.startsWith("en_")) {
return BLOCK_NAME_OVERRIDES.get(block);
} else {
return StringHelper.stripTextFormat(I18n.translate(block.getTranslationKey()));
}
}

// Other

public static boolean isClickable(Block block) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/attached_melon_stem_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/attached_pumpkin_stem_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/bamboo_sapling_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/black_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/blue_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/brown_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/cave_vines_plant_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/cyan_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/fire_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/frosted_ice_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/gray_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/green_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/kelp_plant_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/lava_cauldron_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/light_blue_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/light_gray_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/lime_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/magenta_candle_cake_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/nether_portal_display"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "meteor-client:block/orange_candle_cake_display"
}
}
Loading