-
Notifications
You must be signed in to change notification settings - Fork 1.2k
add SidedScrollOptionBehavior and made AllIcons usable with custom resource #8982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mc1.21.1/dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.simibubi.create.foundation.blockEntity.behaviour.scrollValue; | ||
|
|
||
| import net.minecraft.core.Direction; | ||
|
|
||
| public interface ISidedScrollValueBehavior<B extends ScrollValueBehaviour>{ | ||
|
|
||
| /** | ||
| * Returns the ValueSettingsBehaviour for the given side. | ||
| * | ||
| * @param side the side for which to get the ValueSettingsBehaviour | ||
| * @return the ValueSettingsBehaviour for the given side | ||
| */ | ||
| B get(Direction side); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.simibubi.create.foundation.blockEntity.behaviour.scrollValue; | ||
|
|
||
| import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
| import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform; | ||
|
|
||
| import net.createmod.catnip.data.Iterate; | ||
| import net.createmod.catnip.nbt.NBTHelper; | ||
| import net.minecraft.core.Direction; | ||
| import net.minecraft.core.HolderLookup; | ||
| import net.minecraft.nbt.CompoundTag; | ||
| import net.minecraft.nbt.Tag; | ||
| import net.minecraft.network.chat.Component; | ||
|
|
||
| import java.util.IdentityHashMap; | ||
| import java.util.Map; | ||
|
|
||
| // Example implementation of ISidedScrollValueBehavior | ||
| public class SidedScrollOptionBehavior<E extends Enum<E> & INamedIconOptions> extends ScrollValueBehaviour implements ISidedScrollValueBehavior<ScrollOptionBehaviour<E>> { | ||
| Map<Direction, ScrollOptionBehaviour<E>> sidedBehaviours; | ||
|
|
||
| /** | ||
| * Creates a new SidedScrollOptionBehavior with the given enum type, label, block entity, and slot transform. | ||
| * | ||
| * @param label The label for the behavior. | ||
| * @param be The SmartBlockEntity this behavior is associated with. | ||
| * @param slot The ValueBoxTransform for the slot. | ||
| */ | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weird extra line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, maybe a formatting issue or just accidentally left in there |
||
| public SidedScrollOptionBehavior(Class<E> enum_, Component label, SmartBlockEntity be, ValueBoxTransform slot) { | ||
| super(label, be, slot); | ||
| sidedBehaviours = new IdentityHashMap<>(); | ||
| for (Direction d : Iterate.directions) { | ||
| sidedBehaviours.put(d, new ScrollOptionBehaviour<>(enum_, label, be, slot)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public ScrollOptionBehaviour<E> get(Direction side) { | ||
| return sidedBehaviours.get(side); | ||
| } | ||
|
|
||
| @Override | ||
| public void read(CompoundTag nbt, HolderLookup.Provider registries, boolean clientPacket) { | ||
| NBTHelper.iterateCompoundList(nbt.getList("Behaviors", Tag.TAG_COMPOUND), compound -> { | ||
| Direction face = Direction.from3DDataValue(compound.getInt("Side")); | ||
| if (sidedBehaviours.containsKey(face)) | ||
| sidedBehaviours.get(face) | ||
| .read(compound, registries, clientPacket); | ||
| }); | ||
| super.read(nbt, registries, clientPacket); | ||
| } | ||
|
|
||
| @Override | ||
| public void write(CompoundTag nbt, HolderLookup.Provider registries, boolean clientPacket) { | ||
| nbt.put("Behaviors", NBTHelper.writeCompoundList(sidedBehaviours.entrySet(), entry -> { | ||
| CompoundTag compound = new CompoundTag(); | ||
| compound.putInt("Side", entry.getKey() | ||
| .get3DDataValue()); | ||
| entry.getValue() | ||
| .write(compound, registries, clientPacket); | ||
| return compound; | ||
| })); | ||
| super.write(nbt, registries, clientPacket); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ | |
|
|
||
| public class AllIcons implements ScreenElement { | ||
|
|
||
| public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/icons.png"); | ||
| public static final int ICON_ATLAS_SIZE = 256; | ||
| public final ResourceLocation ICON_ATLAS ; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these fields should stay static. Add new instance fields that get set to these in the constructor. |
||
| public final int ICON_ATLAS_SIZE; | ||
|
|
||
| private static int x = 0, y = -1; | ||
| private int iconX; | ||
|
|
@@ -170,9 +170,16 @@ public class AllIcons implements ScreenElement { | |
| I_MOVE_GAUGE = next(); | ||
| ; | ||
|
|
||
| public AllIcons(int x, int y) { | ||
| private AllIcons(int x, int y) { | ||
| this(x, y, Create.asResource("textures/gui/icons.png"), 256); | ||
| } | ||
|
|
||
| public AllIcons(int x, int y, ResourceLocation iconAtlas, int iconAtlasSize) { | ||
| iconX = x * 16; | ||
| iconY = y * 16; | ||
| ICON_ATLAS = iconAtlas; | ||
| ICON_ATLAS_SIZE = iconAtlasSize; | ||
|
|
||
| } | ||
|
|
||
| private static AllIcons next() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new interfaces should not be I-prefixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I thought I had a class named SidedScrollValueBehavior, will fix that