Skip to content

Commit

Permalink
Merge pull request #520 from refinedmods/feat/GH-518/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
raoulvdberge authored Apr 5, 2024
2 parents 1a36d64 + a752533 commit 9d07262
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 31 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- The Detector, Network Receiver, Network Transmitter and Security Manager will now always connect regardless of color.

### Fixed

- Double slot highlighting in the Grid.
- Improved data corruption protection for storages.

## [2.0.0-milestone.3.5] - 2024-04-04

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,9 @@ public int getSignal(final BlockState state,
public BaseBlockItem createBlockItem() {
return new NetworkNodeBlockItem(this, HELP);
}

@Override
public boolean canAlwaysConnect() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import java.util.List;
import javax.annotation.Nullable;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Inventory;
Expand All @@ -46,12 +46,8 @@ public abstract class AbstractGridScreen<T extends AbstractGridContainerMenu> ex
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGridScreen.class);

private static final int MODIFIED_JUST_NOW_MAX_SECONDS = 10;

private static final int COLUMNS = 9;

private static final int DISABLED_SLOT_COLOR = 0xFF5B5B5B;
private static final int SELECTION_SLOT_COLOR = -2130706433;

private static final List<String> SEARCH_FIELD_HISTORY = new ArrayList<>();

protected final int bottomHeight;
Expand Down Expand Up @@ -235,7 +231,7 @@ private void renderSlot(final GuiGraphics graphics,
renderResourceWithAmount(graphics, slotX, slotY, resource);
}
if (inBounds && isOverStorageArea(mouseX, mouseY)) {
renderSelection(graphics, slotX, slotY);
renderSlotHighlight(graphics, slotX, slotY, 0);
if (resource != null) {
currentGridSlotIndex = idx;
}
Expand Down Expand Up @@ -269,22 +265,9 @@ private void renderAmount(final GuiGraphics graphics,
}

private void renderDisabledSlot(final GuiGraphics graphics, final int slotX, final int slotY) {
RenderSystem.disableDepthTest();
RenderSystem.colorMask(true, true, true, false);
graphics.fillGradient(slotX, slotY, slotX + 16, slotY + 16, DISABLED_SLOT_COLOR, DISABLED_SLOT_COLOR);
RenderSystem.colorMask(true, true, true, true);
RenderSystem.enableDepthTest();
}

private void renderSelection(final GuiGraphics graphics, final int slotX, final int slotY) {
graphics.pose().pushPose();
graphics.pose().translate(0, 0, 200);
RenderSystem.disableDepthTest();
RenderSystem.colorMask(true, true, true, false);
graphics.fillGradient(slotX, slotY, slotX + 16, slotY + 16, SELECTION_SLOT_COLOR, SELECTION_SLOT_COLOR);
RenderSystem.colorMask(true, true, true, true);
RenderSystem.enableDepthTest();
graphics.pose().popPose();
graphics.fillGradient(
RenderType.guiOverlay(), slotX, slotY, slotX + 16, slotY + 16, DISABLED_SLOT_COLOR, DISABLED_SLOT_COLOR, 0
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public <O extends BlockEntity> BlockEntityTicker<O> getTicker(final Level level,
public BaseBlockItem createBlockItem() {
return new NetworkNodeBlockItem(this);
}

@Override
public boolean canAlwaysConnect() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public <O extends BlockEntity> BlockEntityTicker<O> getTicker(final Level level,
public BaseBlockItem createBlockItem() {
return new NetworkNodeBlockItem(this);
}

@Override
public boolean canAlwaysConnect() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ public <O extends BlockEntity> BlockEntityTicker<O> getTicker(final Level level,
final BlockEntityType<O> type) {
return TICKER.get(level, type);
}

@Override
public boolean canAlwaysConnect() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,10 @@ public void appendToTooltip(final ItemStack stack,

@Override
public void transferToBlockEntity(final ItemStack stack, final ItemTransferableStorageBlockEntity blockEntity) {
getId(stack).ifPresentOrElse(
id -> {
blockEntity.modifyStorageIdAfterAlreadyInitialized(id);
LOGGER.debug("Transferred storage {} to block entity {}", id, blockEntity);
},
() -> LOGGER.warn("Could not transfer storage from stack to block entity {}, it has no id!", blockEntity)
);
getId(stack).ifPresent(id -> {
blockEntity.modifyStorageIdAfterAlreadyInitialized(id);
LOGGER.debug("Transferred storage {} to block entity {}", id, blockEntity);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository;
import com.refinedmods.refinedstorage2.platform.api.storage.StorageType;
import com.refinedmods.refinedstorage2.platform.api.support.registry.PlatformRegistry;
import com.refinedmods.refinedstorage2.platform.common.support.AbstractSafeSavedData;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -17,11 +18,10 @@
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.saveddata.SavedData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StorageRepositoryImpl extends SavedData implements StorageRepository {
public class StorageRepositoryImpl extends AbstractSafeSavedData implements StorageRepository {
public static final String NAME = "refinedstorage2_storages";

private static final Logger LOGGER = LoggerFactory.getLogger(StorageRepositoryImpl.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.refinedmods.refinedstorage2.platform.common.support;

import java.io.File;
import java.io.IOException;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

import com.mojang.logging.LogUtils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.saveddata.SavedData;
import org.slf4j.Logger;

public abstract class AbstractSafeSavedData extends SavedData {
private static final Logger LOGGER = LogUtils.getLogger();

@Override
public void save(final File file) {
if (!isDirty()) {
return;
}
final var targetPath = file.toPath().toAbsolutePath();
final var tempFile = targetPath.getParent().resolve(file.getName() + ".temp");
final CompoundTag compoundTag = new CompoundTag();
compoundTag.put("data", this.save(new CompoundTag()));
NbtUtils.addCurrentDataVersion(compoundTag);
try {
// Write to temp file first.
NbtIo.writeCompressed(compoundTag, tempFile);
// Try atomic move
try {
Files.move(tempFile, targetPath, StandardCopyOption.ATOMIC_MOVE);
} catch (final AtomicMoveNotSupportedException ignored) {
Files.move(tempFile, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
} catch (final IOException e) {
LOGGER.error("Could not save data {}", this, e);
}
setDirty(false);
}
}

0 comments on commit 9d07262

Please sign in to comment.