Skip to content
Open
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 @@ -4,6 +4,8 @@

import com.simibubi.create.AllBlocks;

import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ISidedScrollValueBehavior;

import net.createmod.catnip.gui.ScreenOpener;
import net.createmod.catnip.platform.CatnipServices;
import net.createmod.catnip.theme.Color;
Expand Down Expand Up @@ -85,6 +87,9 @@ public void tick() {
cancelInteraction();
return;
}

if (valueSettingBehaviour instanceof ISidedScrollValueBehavior<?> sided) valueSettingBehaviour = sided.get(interactHeldFace);

if (!mc.options.keyUse.isDown()) {
CatnipServices.NETWORK.sendToServer(new ValueSettingsPacket(interactHeldPos, 0, 0, interactHeldHand, blockHitResult,
interactHeldFace, false, valueSettingBehaviour.netId()));
Expand All @@ -99,7 +104,7 @@ public void tick() {
return;
ScreenOpener.open(new ValueSettingsScreen(interactHeldPos,
valueSettingBehaviour.createBoard(player, blockHitResult), valueSettingBehaviour.getValueSettings(),
valueSettingBehaviour::newSettingHovered, valueSettingBehaviour.netId()));
valueSettingBehaviour::newSettingHovered, valueSettingBehaviour.netId(), interactHeldFace));
interactHeldTicks = -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.simibubi.create.CreateClient;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.SidedFilteringBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ISidedScrollValueBehavior;
import com.simibubi.create.foundation.utility.AdventureUtil;

import net.createmod.catnip.platform.CatnipServices;
Expand Down Expand Up @@ -54,6 +55,11 @@ public static void onBlockActivated(PlayerInteractEvent.RightClickBlock event) {
BlockHitResult ray = event.getHitVec();
if (ray == null)
return;
if (behaviour instanceof ISidedScrollValueBehavior<?> sidedBehavior) {
behaviour = sidedBehavior.get(ray.getDirection());
if (behaviour == null)
continue;
}
if (behaviour instanceof SidedFilteringBehaviour) {
behaviour = ((SidedFilteringBehaviour) behaviour).get(ray.getDirection());
if (behaviour == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.simibubi.create.AllPackets;
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsBehaviour.ValueSettings;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ISidedScrollValueBehavior;
import com.simibubi.create.foundation.networking.BlockEntityConfigurationPacket;

import net.createmod.catnip.codecs.stream.CatnipLargerStreamCodecs;
Expand Down Expand Up @@ -65,6 +66,8 @@ protected void applySettings(ServerPlayer player, SmartBlockEntity be) {
valueSettingsBehaviour.onShortInteract(player, interactHand, side, hitResult);
return;
}
if (valueSettingsBehaviour instanceof ISidedScrollValueBehavior<?>) valueSettingsBehaviour = ((ISidedScrollValueBehavior<?>) valueSettingsBehaviour).get(side);
valueSettingsBehaviour.newSettingHovered(new ValueSettings(row, value));
valueSettingsBehaviour.setValueSettings(player, new ValueSettings(row, value), ctrlDown);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ public class ValueSettingsScreen extends AbstractSimiScreen {
private int milestoneSize;
private int soundCoolDown;
private int netId;
private Direction face;

public ValueSettingsScreen(BlockPos pos, ValueSettingsBoard board, ValueSettings valueSettings,
Consumer<ValueSettings> onHover, int netId) {
Consumer<ValueSettings> onHover, int netId, Direction face) {
this.pos = pos;
this.board = board;
this.initialSettings = valueSettings;
this.onHover = onHover;
this.netId = netId;
this.iconMode = board.formatter() instanceof ScrollOptionSettingsFormatter;
this.milestoneSize = iconMode ? 8 : 4;
this.face = face;
}

@Override
Expand Down Expand Up @@ -321,8 +323,7 @@ public boolean mouseReleased(double pMouseX, double pMouseY, int pButton) {

protected void saveAndClose(double pMouseX, double pMouseY) {
ValueSettings closest = getClosestCoordinate((int) pMouseX, (int) pMouseY);
// FIXME: value settings may be face-sensitive on future components
CatnipServices.NETWORK.sendToServer(new ValueSettingsPacket(pos, closest.row(), closest.value(), null, null, Direction.UP,
CatnipServices.NETWORK.sendToServer(new ValueSettingsPacket(pos, closest.row(), closest.value(), null, null, face,
AllKeys.ctrlDown(), netId));
onClose();
}
Expand Down
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
Expand Up @@ -11,6 +11,7 @@
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBox;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBox.IconValueBox;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBox.TextValueBox;
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.SidedFilteringBehaviour;
import com.simibubi.create.foundation.utility.CreateLang;

import net.createmod.catnip.outliner.Outliner;
Expand Down Expand Up @@ -47,6 +48,11 @@ public static void tick() {
if (!(blockEntityBehaviour instanceof ScrollValueBehaviour behaviour))
continue;

if (behaviour instanceof ISidedScrollValueBehavior<?> sidedScrollValueBehavior) {
behaviour = sidedScrollValueBehavior.get(face);
if (behaviour == null)
continue;
}
if (!behaviour.isActive()) {
Outliner.getInstance().remove(behaviour);
continue;
Expand Down
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.
*/

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);
}
}
13 changes: 10 additions & 3 deletions src/main/java/com/simibubi/create/foundation/gui/AllIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
public final int ICON_ATLAS_SIZE;

private static int x = 0, y = -1;
private int iconX;
Expand Down Expand Up @@ -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() {
Expand Down