Skip to content

Commit

Permalink
Merge pull request #666 from refinedmods/fix/GH-665/mouse-keybinds
Browse files Browse the repository at this point in the history
Mouse keybinds
  • Loading branch information
raoulvdberge authored Aug 11, 2024
2 parents 380b85f + 13811fa commit d7cd115
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed mouse keybindings not working on NeoForge.

## [2.0.0-milestone.4.7] - 2024-08-11

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SmithingRecipe;
import net.minecraft.world.item.crafting.StonecutterRecipe;
import org.apache.commons.lang3.tuple.Pair;
import org.apiguardian.api.API;

public class PatternGridContainerMenu extends AbstractGridContainerMenu {
Expand Down Expand Up @@ -277,15 +278,15 @@ private void addProcessingMatrixSlots(final int x,
int slotX = x;
int slotY = y;
for (int i = 0; i < resourceContainer.size(); ++i) {
//noinspection SuspiciousNameCombination
addSlot(new ProcessingMatrixResourceSlot(
resourceContainer,
i,
slotX,
slotY,
input,
this::getPatternType,
startY,
endY
Pair.of(startY, endY)
));
if ((i + 1) % 3 == 0) {
slotX = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -43,17 +44,16 @@ class ProcessingMatrixResourceSlot extends ResourceSlot {
final int y,
final boolean input,
final Supplier<PatternType> patternTypeSupplier,
final int startY,
final int endY) {
final Pair<Integer, Integer> startEndY) {
super(resourceContainer, index, input ? INPUT_HELP : OUTPUT_HELP, x, y, ResourceSlotType.FILTER_WITH_AMOUNT);
this.patternTypeSupplier = patternTypeSupplier;
this.cachedAllowedAlternatives =
resourceContainer instanceof ProcessingMatrixInputResourceContainer inputResourceContainer
? inputResourceContainer.getAllowedTagIds(index)
: Collections.emptySet();
this.input = input;
this.startY = startY;
this.endY = endY;
this.startY = startEndY.getLeft();
this.endY = startEndY.getRight();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class ContentNames {
public static final MutableComponent CONTROLLER = name("controller");
public static final MutableComponent CREATIVE_CONTROLLER = name("creative_controller");
public static final MutableComponent WIRELESS_GRID = createTranslation("item", "wireless_grid");
public static final MutableComponent CREATIVE_WIRELESS_GRID = createTranslation("item", "creative_wireless_grid");
public static final MutableComponent WIRELESS_TRANSMITTER = name("wireless_transmitter");
public static final MutableComponent REGULATOR_UPGRADE = createTranslation("item", "regulator_upgrade");
public static final MutableComponent STORAGE_MONITOR = name("storage_monitor");
Expand All @@ -32,6 +33,7 @@ public final class ContentNames {
public static final MutableComponent NETWORK_RECEIVER = name("network_receiver");
public static final MutableComponent NETWORK_TRANSMITTER = name("network_transmitter");
public static final MutableComponent PORTABLE_GRID = name("portable_grid");
public static final MutableComponent CREATIVE_PORTABLE_GRID = name("creative_portable_grid");
public static final MutableComponent SECURITY_CARD = createTranslation("item", "security_card");
public static final MutableComponent FALLBACK_SECURITY_CARD = createTranslation("item", "fallback_security_card");
public static final MutableComponent SECURITY_MANAGER = name("security_manager");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.refinedmods.refinedstorage.common.api.grid.Grid;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference;
import com.refinedmods.refinedstorage.common.content.ContentNames;
import com.refinedmods.refinedstorage.common.support.containermenu.ExtendedMenuProvider;

import javax.annotation.Nullable;
Expand All @@ -15,16 +14,11 @@
import net.minecraft.world.inventory.AbstractContainerMenu;

class WirelessGridExtendedMenuProvider implements ExtendedMenuProvider<WirelessGridData> {
@Nullable
private final Component name;
private final Grid grid;
private final SlotReference slotReference;

WirelessGridExtendedMenuProvider(
@Nullable final Component name,
final Grid grid,
final SlotReference slotReference
) {
WirelessGridExtendedMenuProvider(final Component name, final Grid grid, final SlotReference slotReference) {
this.name = name;
this.grid = grid;
this.slotReference = slotReference;
Expand All @@ -45,7 +39,7 @@ public StreamEncoder<RegistryFriendlyByteBuf, WirelessGridData> getMenuCodec() {

@Override
public Component getDisplayName() {
return name == null ? ContentNames.WIRELESS_GRID : name;
return name;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

import static java.util.Objects.requireNonNullElse;

public class WirelessGridItem extends AbstractNetworkEnergyItem {
public WirelessGridItem() {
private final boolean creative;

public WirelessGridItem(final boolean creative) {
super(
new Item.Properties().stacksTo(1),
RefinedStorageApi.INSTANCE.getEnergyItemHelper(),
RefinedStorageApi.INSTANCE.getNetworkItemHelper()
);
this.creative = creative;
}

public EnergyStorage createEnergyStorage(final ItemStack stack) {
Expand All @@ -48,7 +53,9 @@ protected void use(@Nullable final Component name,
return;
}
final Grid grid = new WirelessGrid(context);
final var provider = new WirelessGridExtendedMenuProvider(name, grid, slotReference);
final Component correctedName = requireNonNullElse(name,
creative ? ContentNames.CREATIVE_WIRELESS_GRID : ContentNames.WIRELESS_GRID);
final var provider = new WirelessGridExtendedMenuProvider(correctedName, grid, slotReference);
Platform.INSTANCE.getMenuOpener().openMenu(player, provider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ void render(final GuiGraphics graphics, final int x3, final int y3) {
}
final int frame = cycle % 3;
switch (frame) {
case 0:
graphics.blitSprite(TRANSMITTING_1, x3, y3 + 3, 14, 6);
break;
case 1:
graphics.blitSprite(TRANSMITTING_2, x3, y3 + 1, 17, 10);
break;
case 2:
graphics.blitSprite(TRANSMITTING_3, x3, y3, WIDTH_3, 12);
break;
case 0:
default:
graphics.blitSprite(TRANSMITTING_1, x3, y3 + 3, 14, 6);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.nbt.Tag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.codec.StreamEncoder;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
Expand Down Expand Up @@ -69,6 +70,7 @@ public abstract class AbstractPortableGridBlockEntity extends BlockEntity
private final EnergyStorage energyStorage;
private final RateLimiter activenessChangeRateLimiter = RateLimiter.create(1);
private final PortableGrid grid;
private final PortableGridType type;

private RedstoneMode redstoneMode = RedstoneMode.IGNORE;

Expand All @@ -77,6 +79,7 @@ protected AbstractPortableGridBlockEntity(final PortableGridType type, final Blo
this.diskInventory = new DiskInventory((inventory, slot) -> onDiskChanged(), 1);
this.energyStorage = createEnergyStorage(type, this);
this.grid = new InWorldPortableGrid(energyStorage, diskInventory, diskStateListener, this);
this.type = type;
}

static void readDiskInventory(final CompoundTag tag,
Expand Down Expand Up @@ -242,7 +245,10 @@ public void setRedstoneMode(final RedstoneMode redstoneMode) {

@Override
public Component getDisplayName() {
return name == null ? ContentNames.PORTABLE_GRID : name;
final MutableComponent defaultName = type == PortableGridType.CREATIVE
? ContentNames.CREATIVE_PORTABLE_GRID
: ContentNames.PORTABLE_GRID;
return name == null ? defaultName : name;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceHandlerItem;
import com.refinedmods.refinedstorage.common.content.BlockEntities;
import com.refinedmods.refinedstorage.common.content.ContentNames;
import com.refinedmods.refinedstorage.common.storage.Disk;
import com.refinedmods.refinedstorage.common.storage.DiskInventory;
import com.refinedmods.refinedstorage.common.support.energy.CreativeEnergyStorage;
Expand All @@ -38,6 +39,7 @@
import net.minecraft.world.level.block.Block;

import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation;
import static java.util.Objects.requireNonNullElse;

public class PortableGridBlockItem extends AbstractEnergyBlockItem implements SlotReferenceHandlerItem {
private static final Component HELP = createTranslation("item", "portable_grid.help");
Expand Down Expand Up @@ -139,7 +141,8 @@ public void use(final ServerPlayer player, final ItemStack stack, final SlotRefe
energyStorage.portableGrid = portableGrid;
portableGrid.updateStorage();
Platform.INSTANCE.getMenuOpener().openMenu(player, new PortableGridItemExtendedMenuProvider(
stack.get(DataComponents.CUSTOM_NAME),
requireNonNullElse(stack.get(DataComponents.CUSTOM_NAME),
type == PortableGridType.CREATIVE ? ContentNames.CREATIVE_PORTABLE_GRID : ContentNames.PORTABLE_GRID),
portableGrid,
energyStorage,
diskInventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.common.api.grid.Grid;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference;
import com.refinedmods.refinedstorage.common.content.ContentNames;
import com.refinedmods.refinedstorage.common.grid.GridData;
import com.refinedmods.refinedstorage.common.grid.PortableGridData;
import com.refinedmods.refinedstorage.common.storage.DiskInventory;
Expand All @@ -20,15 +19,14 @@
import net.minecraft.world.inventory.AbstractContainerMenu;

class PortableGridItemExtendedMenuProvider implements ExtendedMenuProvider<PortableGridData> {
@Nullable
private final Component name;
private final Grid grid;
private final EnergyStorage energyStorage;
private final DiskInventory diskInventory;
private final SlotReference slotReference;

PortableGridItemExtendedMenuProvider(
@Nullable final Component name,
final Component name,
final Grid grid,
final EnergyStorage energyStorage,
final DiskInventory diskInventory,
Expand Down Expand Up @@ -58,7 +56,7 @@ public StreamEncoder<RegistryFriendlyByteBuf, PortableGridData> getMenuCodec() {

@Override
public Component getDisplayName() {
return name == null ? ContentNames.PORTABLE_GRID : name;
return name;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public boolean allowComponentsUpdateAnimation(final Player player,
return AbstractModInitializer.allowComponentsUpdateAnimation(oldStack, newStack);
}
}));
Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, () -> new WirelessGridItem() {
Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, () -> new WirelessGridItem(false) {
@Override
public boolean allowComponentsUpdateAnimation(final Player player,
final InteractionHand hand,
Expand All @@ -324,7 +324,7 @@ public boolean allowComponentsUpdateAnimation(final Player player,
}));
Items.INSTANCE.setCreativeWirelessGrid(callback.register(
CREATIVE_WIRELESS_GRID,
() -> new WirelessGridItem() {
() -> new WirelessGridItem(true) {
@Override
public boolean allowComponentsUpdateAnimation(final Player player,
final InteractionHand hand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,6 @@ public Optional<FluidOperationResult> fillContainer(final ItemStack container,
}
}

private Optional<ItemStack> getFilledItemStack(final FluidResource fluidResource,
final SimpleSingleStackStorage interceptingStorage) {
final Storage<FluidVariant> destination = FluidStorage.ITEM.find(
interceptingStorage.getStack(),
ContainerItemContext.ofSingleSlot(interceptingStorage)
);
if (destination == null) {
return Optional.empty();
}
try (Transaction tx = Transaction.openOuter()) {
destination.insert(toFluidVariant(fluidResource), FluidConstants.BUCKET, tx);
return Optional.of(interceptingStorage.getStack());
}
}

@Override
public TransferManager createTransferManager(final AbstractContainerMenu containerMenu) {
return new TransferManager(containerMenu, ContainerTransferDestination::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private ClientModInitializer() {
@SubscribeEvent
public static void onClientSetup(final FMLClientSetupEvent e) {
NeoForge.EVENT_BUS.addListener(ClientModInitializer::onKeyInput);
NeoForge.EVENT_BUS.addListener(ClientModInitializer::onMouseInput);
e.enqueueWork(ClientModInitializer::registerModelPredicates);
e.enqueueWork(ClientModInitializer::registerItemProperties);
registerBlockEntityRenderer();
Expand All @@ -84,6 +85,11 @@ public static void onKeyInput(final InputEvent.Key e) {
handleInputEvents();
}

@SubscribeEvent
public static void onMouseInput(final InputEvent.MouseButton.Pre e) {
handleInputEvents();
}

private static void registerModelPredicates() {
Items.INSTANCE.getControllers().forEach(controllerBlockItem -> ItemProperties.register(
controllerBlockItem.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public boolean isAutoSelected() {

@Override
public void setAutoSelected(final boolean autoSelected) {
if (autoSelected != this.autoSelected.get()) {
if (autoSelected != Boolean.TRUE.equals(this.autoSelected.get())) {
this.autoSelected.set(autoSelected);
ConfigImpl.this.spec.save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack,
return AbstractModInitializer.allowComponentsUpdateAnimation(oldStack, newStack);
}
}));
Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, () -> new WirelessGridItem() {
Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, () -> new WirelessGridItem(false) {
@Override
public boolean shouldCauseReequipAnimation(final ItemStack oldStack,
final ItemStack newStack,
Expand All @@ -289,7 +289,7 @@ public boolean shouldCauseReequipAnimation(final ItemStack oldStack,
}));
Items.INSTANCE.setCreativeWirelessGrid(callback.register(
CREATIVE_WIRELESS_GRID,
() -> new WirelessGridItem() {
() -> new WirelessGridItem(true) {
@Override
public boolean shouldCauseReequipAnimation(final ItemStack oldStack,
final ItemStack newStack,
Expand Down

0 comments on commit d7cd115

Please sign in to comment.