Skip to content

Commit fc5670d

Browse files
committed
1.18.2
1 parent 3c15cd5 commit fc5670d

File tree

24 files changed

+90
-291
lines changed

24 files changed

+90
-291
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ subprojects {
1616

1717
dependencies {
1818
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
19+
1920
mappings loom.officialMojangMappings()
2021
}
2122
}

common/src/main/java/dev/felnull/otyacraftengine/TestInit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class TestInit {
1111
public static void init() {
1212
TestServerHandler.init();
1313
TestCommonHandler.init();
14-
TestItem.init();
1514
TestBlock.init();
15+
TestItem.init();
1616
TestBlockEntity.init();
1717
TestMenu.init();
1818
}

common/src/main/java/dev/felnull/otyacraftengine/block/TestBlock.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.felnull.otyacraftengine.block;
22

33
import dev.architectury.registry.registries.DeferredRegister;
4+
import dev.architectury.registry.registries.RegistrySupplier;
45
import dev.felnull.otyacraftengine.OtyacraftEngine;
56
import dev.felnull.otyacraftengine.blockentity.TestBlockEntity;
67
import dev.felnull.otyacraftengine.util.OEVoxelShapeUtil;
@@ -37,16 +38,15 @@ public TestBlock(Properties properties) {
3738
super(properties);
3839
}
3940

40-
public static Block TEST_BLOCK;
41+
public static RegistrySupplier<Block> TEST_BLOCK;
4142

4243
public static void init() {
4344
DeferredRegister<Block> BLOCK_REG = DeferredRegister.create(OtyacraftEngine.MODID, Registry.BLOCK_REGISTRY);
4445
DeferredRegister<Item> ITEM_REG = DeferredRegister.create(OtyacraftEngine.MODID, Registry.ITEM_REGISTRY);
45-
TEST_BLOCK = new TestBlock(BlockBehaviour.Properties.of(Material.METAL).sound(SoundType.METAL));
46-
BLOCK_REG.register("test_block", () -> TEST_BLOCK);
47-
ITEM_REG.register("test_block", () -> new BlockItem(TEST_BLOCK, new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
48-
ITEM_REG.register();
46+
TEST_BLOCK = BLOCK_REG.register("test_block", () -> new TestBlock(BlockBehaviour.Properties.of(Material.METAL).sound(SoundType.METAL)));
4947
BLOCK_REG.register();
48+
ITEM_REG.register("test_block", () -> new BlockItem(TEST_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_MISC)));
49+
ITEM_REG.register();
5050
}
5151

5252
@Nullable
@@ -85,6 +85,6 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
8585
@Nullable
8686
@Override
8787
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
88-
return createTickerHelper(blockEntityType, TestBlockEntity.TEST_BLOCKENTITY, TestBlockEntity::tick);
88+
return createTickerHelper(blockEntityType, TestBlockEntity.TEST_BLOCKENTITY.get(), TestBlockEntity::tick);
8989
}
9090
}

common/src/main/java/dev/felnull/otyacraftengine/blockentity/TestBlockEntity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.felnull.otyacraftengine.blockentity;
22

33
import dev.architectury.registry.registries.DeferredRegister;
4+
import dev.architectury.registry.registries.RegistrySupplier;
45
import dev.felnull.otyacraftengine.OtyacraftEngine;
56
import dev.felnull.otyacraftengine.block.TestBlock;
67
import dev.felnull.otyacraftengine.inventory.TestMenu;
@@ -20,18 +21,17 @@
2021

2122
public class TestBlockEntity extends OEBaseContainerBlockEntity {
2223
private static final NonNullList<ItemStack> ITEMS = NonNullList.withSize(0, ItemStack.EMPTY);
23-
public static BlockEntityType<TestBlockEntity> TEST_BLOCKENTITY;
24+
public static RegistrySupplier<BlockEntityType<TestBlockEntity>> TEST_BLOCKENTITY;
2425
private float roted;
2526
private float oldRoted;
2627

2728
public TestBlockEntity(BlockPos blockPos, BlockState blockState) {
28-
super(TEST_BLOCKENTITY, blockPos, blockState);
29+
super(TEST_BLOCKENTITY.get(), blockPos, blockState);
2930
}
3031

3132
public static void init() {
3233
DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES_REGISTER = DeferredRegister.create(OtyacraftEngine.MODID, Registry.BLOCK_ENTITY_TYPE_REGISTRY);
33-
TEST_BLOCKENTITY = BlockEntityType.Builder.of(TestBlockEntity::new, TestBlock.TEST_BLOCK).build(null);
34-
BLOCK_ENTITY_TYPES_REGISTER.register("test_block_entity", () -> TEST_BLOCKENTITY);
34+
TEST_BLOCKENTITY = BLOCK_ENTITY_TYPES_REGISTER.register("test_block_entity", () -> BlockEntityType.Builder.of(TestBlockEntity::new, TestBlock.TEST_BLOCK.get()).build(null));
3535
BLOCK_ENTITY_TYPES_REGISTER.register();
3636
}
3737

@@ -76,7 +76,7 @@ public void onSync(CompoundTag tag) {
7676

7777
@Override
7878
protected Component getDefaultName() {
79-
return TestBlock.TEST_BLOCK.getName();
79+
return TestBlock.TEST_BLOCK.get().getName();
8080
}
8181

8282
@Override
Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,69 @@
11
package dev.felnull.otyacraftengine.client.gui.components;
22

33
import com.mojang.blaze3d.vertex.PoseStack;
4-
import dev.felnull.otyacraftengine.client.gui.components.base.IOEBaseComponent;
4+
import dev.felnull.otyacraftengine.client.gui.TextureSpecifyLocation;
5+
import dev.felnull.otyacraftengine.client.gui.components.base.OEBaseImageWidget;
56
import dev.felnull.otyacraftengine.client.util.OERenderUtil;
6-
import net.minecraft.client.gui.components.AbstractButton;
7-
import net.minecraft.client.gui.narration.NarratedElementType;
8-
import net.minecraft.client.gui.narration.NarrationElementOutput;
97
import net.minecraft.network.chat.Component;
10-
import net.minecraft.network.chat.TranslatableComponent;
11-
import net.minecraft.resources.ResourceLocation;
128
import net.minecraft.util.Mth;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
1311

12+
import java.util.Set;
1413
import java.util.function.Consumer;
1514
import java.util.function.Supplier;
1615

17-
@Deprecated
18-
public class RadioButton extends AbstractButton implements IOEBaseComponent {
19-
private final boolean showLabel;
20-
private final Supplier<RadioButton[]> group;
21-
private final ResourceLocation texture;
22-
private final int textureX;
23-
private final int textureY;
24-
private final int textureWidth;
25-
private final int textureHeight;
26-
private final int textureSizeWidth;
27-
private final int textureSizeHeight;
16+
public class RadioButton extends OEBaseImageWidget {
17+
@Nullable
2818
private final Consumer<RadioButton> onPress;
19+
@NotNull
20+
private final Supplier<Set<RadioButton>> group;
21+
private boolean showLabel;
2922
private boolean selected;
3023

31-
public RadioButton(int x, int y, int w, int h, Component title, boolean selected, boolean showLabel, Supplier<RadioButton[]> group, Consumer<RadioButton> onPress) {
32-
this(x, y, w, h, title, selected, showLabel, group, WIDGETS, 0, 0, 20, 20, 256, 256, onPress);
24+
public RadioButton(int x, int y, @NotNull Component message, @Nullable Consumer<RadioButton> onPress, @NotNull Supplier<Set<RadioButton>> group, boolean showLabel) {
25+
this(x, y, 20, 20, message, onPress, group, showLabel, new TextureSpecifyLocation(WIDGETS, 0, 0, 20, 20));
3326
}
3427

35-
public RadioButton(int x, int y, int w, int h, Component title, boolean selected, boolean showLabel, Supplier<RadioButton[]> group, ResourceLocation texture, int tx, int ty, int tw, int th, int tsX, int tsY, Consumer<RadioButton> onPress) {
36-
super(x, y, w, h, title);
37-
this.selected = selected;
38-
this.showLabel = showLabel;
39-
this.group = group;
40-
this.texture = texture;
41-
this.textureX = tx;
42-
this.textureY = ty;
43-
this.textureWidth = tw;
44-
this.textureHeight = th;
45-
this.textureSizeWidth = tsX;
46-
this.textureSizeHeight = tsY;
28+
public RadioButton(int x, int y, int width, int height, @NotNull Component message, @Nullable Consumer<RadioButton> onPress, @NotNull Supplier<Set<RadioButton>> group, boolean showLabel, @NotNull TextureSpecifyLocation texture) {
29+
super(x, y, width, height, "radioButton", message, texture);
4730
this.onPress = onPress;
31+
this.group = group;
32+
this.showLabel = showLabel;
33+
}
34+
35+
@Override
36+
public void renderButton(@NotNull PoseStack poseStack, int i, int j, float f) {
37+
OERenderUtil.drawTexture(texture.location(), poseStack, x, y, texture.x() + (this.isHoveredOrFocused() ? 20 : 0), texture.y() + (this.selected ? 20 : 0), texture.width(), texture.height(), texture.sizeWidth(), texture.sizeHeight());
38+
this.renderBg(poseStack, mc, i, j);
39+
if (this.showLabel)
40+
drawTextBase(poseStack, this.getMessage(), this.x + 24, this.y + (this.height - 8) / 2, 14737632 | Mth.ceil(this.alpha * 255.0F) << 24);
4841
}
4942

5043
@Override
5144
public void onPress() {
5245
this.selected = true;
53-
var rdos = this.group.get();
54-
for (RadioButton rdo : rdos) {
55-
if (this != rdo) {
46+
for (RadioButton rdo : group.get()) {
47+
if (this != rdo)
5648
rdo.selected = false;
57-
}
5849
}
59-
this.onPress.accept(this);
50+
if (onPress != null)
51+
this.onPress.accept(this);
6052
}
6153

62-
public void setSelected(boolean selected) {
63-
this.selected = selected;
54+
public boolean isShowLabel() {
55+
return showLabel;
6456
}
6557

66-
public boolean selected() {
67-
return this.selected;
68-
}
69-
70-
@Override
71-
public void updateNarration(NarrationElementOutput narrationElementOutput) {
72-
narrationElementOutput.add(NarratedElementType.TITLE, this.createNarrationMessage());
73-
if (this.active) {
74-
if (this.isFocused()) {
75-
narrationElementOutput.add(NarratedElementType.USAGE, new TranslatableComponent("narration.checkbox.usage.focused"));
76-
} else {
77-
narrationElementOutput.add(NarratedElementType.USAGE, new TranslatableComponent("narration.checkbox.usage.hovered"));
78-
}
79-
}
58+
public void setShowLabel(boolean showLabel) {
59+
this.showLabel = showLabel;
8060
}
8161

82-
@Override
83-
public void renderButton(PoseStack poseStack, int i, int j, float f) {
84-
OERenderUtil.drawTexture(texture, poseStack, x, y, textureX + (this.isHoveredOrFocused() ? 20 : 0), textureY + (this.selected ? 20 : 0), textureWidth, textureHeight, textureSizeWidth, textureSizeHeight);
85-
this.renderBg(poseStack, mc, i, j);
86-
if (this.showLabel) {
87-
drawRdoString(poseStack, this.getMessage(), this.x + 24, this.y + (this.height - 8) / 2, 14737632 | Mth.ceil(this.alpha * 255.0F) << 24);
88-
}
62+
public boolean isSelected() {
63+
return selected;
8964
}
9065

91-
public void drawRdoString(PoseStack poseStack, Component component, int i, int j, int k) {
92-
drawString(poseStack, mc.font, component, i, j, k);
66+
public void setSelected(boolean selected) {
67+
this.selected = selected;
9368
}
9469
}

common/src/main/java/dev/felnull/otyacraftengine/client/gui/components/RadioButtonV2.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

common/src/main/java/dev/felnull/otyacraftengine/client/gui/screen/TestBEScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.mojang.blaze3d.vertex.PoseStack;
55
import dev.architectury.registry.menu.MenuRegistry;
66
import dev.felnull.otyacraftengine.OtyacraftEngine;
7-
import dev.felnull.otyacraftengine.client.gui.components.RadioButtonV2;
7+
import dev.felnull.otyacraftengine.client.gui.components.RadioButton;
88
import dev.felnull.otyacraftengine.inventory.TestMenu;
99
import net.minecraft.network.chat.Component;
1010
import net.minecraft.network.chat.TextComponent;
@@ -16,7 +16,7 @@ public class TestBEScreen extends OEBEContainerBaseScreen<TestMenu> {
1616
// private ContainerTab testContainerTab;
1717

1818
public static void fInit() {
19-
MenuRegistry.registerScreenFactory(TestMenu.TEST_MENU, TestBEScreen::new);
19+
MenuRegistry.registerScreenFactory(TestMenu.TEST_MENU.get(), TestBEScreen::new);
2020
}
2121

2222
public TestBEScreen(TestMenu abstractContainerMenu, Inventory inventory, Component component) {
@@ -32,7 +32,7 @@ protected void init() {
3232
super.init();
3333
// this.addRenderableWidget(new ContainerTab(leftPos + imageWidth, topPos + 30, 30, 30, new TextComponent("TEST")));
3434

35-
this.addRenderableWidget(new RadioButtonV2(leftPos, topPos, new TextComponent("TEST V2"), null, ImmutableSet::of, true));
35+
this.addRenderableWidget(new RadioButton(leftPos, topPos, new TextComponent("TEST V2"), null, ImmutableSet::of, true));
3636
}
3737

3838
@Override

common/src/main/java/dev/felnull/otyacraftengine/client/gui/screen/TestScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ protected void init() {
3838
}
3939
}
4040
}));*/
41-
rdo1 = this.addRenderableWidget(new RadioButton(0, 0, 20, 20, new TextComponent("TEST1"), false, true, () -> new RadioButton[]{rdo1, rdo2}, n -> {
41+
/* rdo1 = this.addRenderableWidget(new RadioButton(0, 0, 20, 20, new TextComponent("TEST1"), false, true, () -> new RadioButton[]{rdo1, rdo2}, n -> {
4242
4343
}));
4444
rdo2 = this.addRenderableWidget(new RadioButton(0, 50, 20, 20, new TextComponent("TEST2"), false, true, () -> new RadioButton[]{rdo1, rdo2}, n -> {
4545
46-
}));
46+
}));*/
4747
}
4848

4949
@Override

common/src/main/java/dev/felnull/otyacraftengine/client/handler/ClientHandler.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import dev.felnull.otyacraftengine.client.renderer.GuiDebugRenderer;
1212
import dev.felnull.otyacraftengine.client.util.ClientUtilInit;
1313
import dev.felnull.otyacraftengine.util.OEItemUtil;
14-
import dev.felnull.otyacraftengine.util.OETagUtil;
1514
import net.minecraft.ChatFormatting;
1615
import net.minecraft.client.gui.screens.Screen;
1716
import net.minecraft.client.player.LocalPlayer;
1817
import net.minecraft.core.Registry;
1918
import net.minecraft.network.chat.Component;
2019
import net.minecraft.network.chat.TextComponent;
2120
import net.minecraft.resources.ResourceLocation;
21+
import net.minecraft.tags.TagKey;
2222
import net.minecraft.world.entity.EntityType;
2323
import net.minecraft.world.item.*;
2424

@@ -56,12 +56,11 @@ private static void onReset() {
5656

5757
private static void onTooltip(ItemStack itemStack, List<Component> list, TooltipFlag tooltipFlag) {
5858
if (itemStack.isEmpty()) return;
59-
var item = itemStack.getItem();
6059

6160
if (OtyacraftEngine.CONFIG.showTagTooltip) {
62-
var itemTags = OETagUtil.getTags(item);
63-
if (item instanceof BlockItem blockItem) {
64-
var blockTags = OETagUtil.getTags(blockItem.getBlock());
61+
var itemTags = itemStack.getTags().map(TagKey::location).toList();
62+
if (itemStack.getItem() instanceof BlockItem blockItem) {
63+
var blockTags = blockItem.getBlock().builtInRegistryHolder().tags().map(TagKey::location).toList();
6564
Set<ResourceLocation> bothTags = new HashSet<>();
6665
boolean firstItem = false;
6766
boolean firstBlock = false;
@@ -106,7 +105,7 @@ private static void onTooltip(ItemStack itemStack, List<Component> list, Tooltip
106105
}
107106
var entityTypes = getEntityTypesByItem(itemStack);
108107
Set<ResourceLocation> entityTypeTags = new HashSet<>();
109-
entityTypes.forEach(n -> entityTypeTags.addAll(OETagUtil.getTags(n)));
108+
entityTypes.forEach(n -> entityTypeTags.addAll(n.builtInRegistryHolder().tags().map(TagKey::location).toList()));
110109
if (!entityTypeTags.isEmpty()) {
111110
list.add(new TextComponent("Entity tags").withStyle(ChatFormatting.AQUA));
112111
for (ResourceLocation tag : entityTypeTags) {
@@ -116,7 +115,7 @@ private static void onTooltip(ItemStack itemStack, List<Component> list, Tooltip
116115
}
117116

118117
if (OtyacraftEngine.CONFIG.showModNameTooltip) {
119-
var modid = Registry.ITEM.getKey(item);
118+
var modid = Registry.ITEM.getKey(itemStack.getItem());
120119
list.add(new TextComponent(Platform.getMod(modid.getNamespace()).getName()).withStyle(ChatFormatting.DARK_GREEN));
121120
}
122121
}

common/src/main/java/dev/felnull/otyacraftengine/client/renderer/blockentity/TestRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public void render(TestBlockEntity blockEntity, float f, PoseStack poseStack, Mu
4747
}
4848

4949
public static void init() {
50-
BlockEntityRendererRegistry.register(TestBlockEntity.TEST_BLOCKENTITY, TestRenderer::new);
50+
BlockEntityRendererRegistry.register(TestBlockEntity.TEST_BLOCKENTITY.get(), TestRenderer::new);
5151
}
5252
}

0 commit comments

Comments
 (0)