Skip to content

Commit

Permalink
Merge pull request #603 from refinedmods/fix/GH-597/upgrade-fixes
Browse files Browse the repository at this point in the history
Upgrade fixes
  • Loading branch information
raoulvdberge authored Jul 6, 2024
2 parents 250d2df + 592fd03 commit fa4162d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 71 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Fixed Relay model not being able to load correctly.
- Fixed not being able to ghost drag resources from recipe viewers into filter slots on NeoForge.
- Fixed extra dark backgrounds due to drawing background on GUIs twice.
- Fixed Configuration Card not being able to transfer upgrades for the Wireless Transmitter.
- Fixed upgrade inventories not maintaining order after reloading. Upgrade inventories from the milestone 4.2 are incompatible and will be empty.
- Fixed Wireless Transmitter not dropping upgrades when breaking block.

## [2.0.0-milestone.4.2] - 2024-07-06

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.refinedmods.refinedstorage.platform.common.support.BlockEntityWithDrops;
import com.refinedmods.refinedstorage.platform.common.support.containermenu.NetworkNodeExtendedMenuProvider;
import com.refinedmods.refinedstorage.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity;
import com.refinedmods.refinedstorage.platform.common.util.ContainerUtil;

import javax.annotation.Nullable;

Expand All @@ -19,7 +20,6 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -155,17 +155,14 @@ Container getNetworkCardInventory() {
@Override
public void saveAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
super.saveAdditional(tag, provider);
tag.put(TAG_NETWORK_CARD_INVENTORY, networkCardInventory.createTag(provider));
tag.put(TAG_NETWORK_CARD_INVENTORY, ContainerUtil.write(networkCardInventory, provider));
}

@Override
public void loadAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
super.loadAdditional(tag, provider);
if (tag.contains(TAG_NETWORK_CARD_INVENTORY)) {
networkCardInventory.fromTag(
tag.getList(TAG_NETWORK_CARD_INVENTORY, Tag.TAG_COMPOUND),
provider
);
ContainerUtil.read(tag.getCompound(TAG_NETWORK_CARD_INVENTORY), networkCardInventory, provider);
}
updateReceiverLocation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.refinedmods.refinedstorage.platform.common.support.FilterModeSettings;
import com.refinedmods.refinedstorage.platform.common.upgrade.UpgradeContainer;
import com.refinedmods.refinedstorage.platform.common.upgrade.UpgradeDestinations;
import com.refinedmods.refinedstorage.platform.common.util.ContainerUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
Expand All @@ -25,7 +25,6 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
Expand All @@ -34,13 +33,12 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;

// TODO: upgradeable + level interacting class hierarchy? Disk Interface is copying stuff now... :(
public abstract class AbstractDiskInterfaceBlockEntity
extends AbstractDiskContainerBlockEntity<StorageTransferNetworkNode>
implements StorageTransferListener {
public static final int AMOUNT_OF_DISKS = 6;

private static final String TAG_UPGRADES = "u";
private static final String TAG_UPGRADES = "upgr";
private static final String TAG_FILTER_MODE = "fim";
private static final String TAG_TRANSFER_MODE = "tm";

Expand Down Expand Up @@ -71,15 +69,11 @@ protected AbstractDiskInterfaceBlockEntity(final BlockPos pos, final BlockState
}

private void upgradeContainerChanged() {
configureAccordingToUpgrades();
setChanged();
}

private void configureAccordingToUpgrades() {
final int amountOfSpeedUpgrades = upgradeContainer.getAmount(Items.INSTANCE.getSpeedUpgrade());
this.workTickRate = 9 - (amountOfSpeedUpgrades * 2);
final long baseEnergyUsage = Platform.INSTANCE.getConfig().getDiskInterface().getEnergyUsage();
mainNode.setEnergyUsage(baseEnergyUsage + upgradeContainer.getEnergyUsage());
setChanged();
}

@Override
Expand All @@ -102,16 +96,15 @@ protected void setNormalizer(final UnaryOperator<ResourceKey> normalizer) {
@Override
public void loadAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
if (tag.contains(TAG_UPGRADES)) {
upgradeContainer.fromTag(tag.getList(TAG_UPGRADES, Tag.TAG_COMPOUND), provider);
ContainerUtil.read(tag.getCompound(TAG_UPGRADES), upgradeContainer, provider);
}
configureAccordingToUpgrades();
super.loadAdditional(tag, provider);
}

@Override
public void saveAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
super.saveAdditional(tag, provider);
tag.put(TAG_UPGRADES, upgradeContainer.createTag(provider));
tag.put(TAG_UPGRADES, ContainerUtil.write(upgradeContainer, provider));
tag.putInt(TAG_FILTER_MODE, FilterModeSettings.getFilterMode(mainNode.getFilterMode()));
}

Expand All @@ -134,20 +127,12 @@ public void writeConfiguration(final CompoundTag tag, final HolderLookup.Provide

@Override
public List<Item> getUpgradeItems() {
final List<Item> upgradeItems = new ArrayList<>();
for (int i = 0; i < upgradeContainer.getContainerSize(); ++i) {
final ItemStack itemStack = upgradeContainer.getItem(i);
if (itemStack.isEmpty()) {
continue;
}
upgradeItems.add(itemStack.getItem());
}
return upgradeItems;
return upgradeContainer.getUpgradeItems();
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addItem(new ItemStack(upgradeItem)).isEmpty();
return upgradeContainer.addUpgradeItem(upgradeItem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import com.refinedmods.refinedstorage.platform.common.support.BlockEntityWithDrops;
import com.refinedmods.refinedstorage.platform.common.upgrade.UpgradeContainer;
import com.refinedmods.refinedstorage.platform.common.upgrade.UpgradeDestinations;
import com.refinedmods.refinedstorage.platform.common.util.ContainerUtil;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -30,7 +29,7 @@ public abstract class AbstractUpgradeableNetworkNodeContainerBlockEntity<T exten
AbstractUpgradeableNetworkNodeContainerBlockEntity.class
);

private static final String TAG_UPGRADES = "u";
private static final String TAG_UPGRADES = "upgr";

protected final UpgradeContainer upgradeContainer;
private int workTickRate = 9;
Expand Down Expand Up @@ -63,7 +62,10 @@ protected void postDoWork() {
}

private void upgradeContainerChanged() {
configureAccordingToUpgrades();
LOGGER.debug("Reconfiguring {} for upgrades", getBlockPos());
final int amountOfSpeedUpgrades = upgradeContainer.getAmount(Items.INSTANCE.getSpeedUpgrade());
this.workTickRate = 9 - (amountOfSpeedUpgrades * 2);
this.setEnergyUsage(upgradeContainer.getEnergyUsage());
setChanged();
if (level instanceof ServerLevel serverLevel) {
initialize(serverLevel);
Expand All @@ -72,48 +74,32 @@ private void upgradeContainerChanged() {

@Override
public List<Item> getUpgradeItems() {
final List<Item> upgradeItems = new ArrayList<>();
for (int i = 0; i < upgradeContainer.getContainerSize(); ++i) {
final ItemStack itemStack = upgradeContainer.getItem(i);
if (itemStack.isEmpty()) {
continue;
}
upgradeItems.add(itemStack.getItem());
}
return upgradeItems;
return upgradeContainer.getUpgradeItems();
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addItem(new ItemStack(upgradeItem)).isEmpty();
return upgradeContainer.addUpgradeItem(upgradeItem);
}

@Override
public void saveAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
super.saveAdditional(tag, provider);
tag.put(TAG_UPGRADES, upgradeContainer.createTag(provider));
tag.put(TAG_UPGRADES, ContainerUtil.write(upgradeContainer, provider));
}

@Override
public void loadAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
if (tag.contains(TAG_UPGRADES)) {
upgradeContainer.fromTag(tag.getList(TAG_UPGRADES, Tag.TAG_COMPOUND), provider);
ContainerUtil.read(tag.getCompound(TAG_UPGRADES), upgradeContainer, provider);
}
configureAccordingToUpgrades();
super.loadAdditional(tag, provider);
}

private void configureAccordingToUpgrades() {
LOGGER.debug("Reconfiguring {} for upgrades", getBlockPos());
final int amountOfSpeedUpgrades = upgradeContainer.getAmount(Items.INSTANCE.getSpeedUpgrade());
this.workTickRate = 9 - (amountOfSpeedUpgrades * 2);
this.setEnergyUsage(upgradeContainer.getEnergyUsage());
}

protected abstract void setEnergyUsage(long upgradeEnergyUsage);

@Override
public NonNullList<ItemStack> getDrops() {
public final NonNullList<ItemStack> getDrops() {
final NonNullList<ItemStack> drops = NonNullList.create();
for (int i = 0; i < upgradeContainer.getContainerSize(); ++i) {
drops.add(upgradeContainer.getItem(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import com.refinedmods.refinedstorage.platform.api.upgrade.UpgradeRegistry;
import com.refinedmods.refinedstorage.platform.api.upgrade.UpgradeState;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalLong;
import java.util.Set;
import java.util.stream.IntStream;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -76,12 +76,6 @@ public OptionalLong getRegulatedAmount(final ResourceKey resource) {
.findFirst();
}

@Override
public void fromTag(final ListTag tag, final HolderLookup.Provider provider) {
super.fromTag(tag, provider);
updateIndex();
}

private void updateIndex() {
LOGGER.debug("Updating upgrade index for {}", destination);
index.clear();
Expand Down Expand Up @@ -123,4 +117,20 @@ public long getEnergyUsage() {
}
return usage;
}

public List<Item> getUpgradeItems() {
final List<Item> upgradeItems = new ArrayList<>();
for (int i = 0; i < getContainerSize(); ++i) {
final ItemStack itemStack = getItem(i);
if (itemStack.isEmpty()) {
continue;
}
upgradeItems.add(itemStack.getItem());
}
return upgradeItems;
}

public boolean addUpgradeItem(final Item upgradeItem) {
return addItem(new ItemStack(upgradeItem)).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,35 @@
import com.refinedmods.refinedstorage.platform.common.content.BlockEntities;
import com.refinedmods.refinedstorage.platform.common.content.ContentNames;
import com.refinedmods.refinedstorage.platform.common.support.AbstractDirectionalBlock;
import com.refinedmods.refinedstorage.platform.common.support.BlockEntityWithDrops;
import com.refinedmods.refinedstorage.platform.common.support.containermenu.NetworkNodeExtendedMenuProvider;
import com.refinedmods.refinedstorage.platform.common.support.network.AbstractRedstoneModeNetworkNodeContainerBlockEntity;
import com.refinedmods.refinedstorage.platform.common.upgrade.UpgradeContainer;
import com.refinedmods.refinedstorage.platform.common.upgrade.UpgradeDestinations;
import com.refinedmods.refinedstorage.platform.common.util.ContainerUtil;

import java.util.List;
import javax.annotation.Nullable;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.StreamEncoder;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;

public class WirelessTransmitterBlockEntity
extends AbstractRedstoneModeNetworkNodeContainerBlockEntity<SimpleNetworkNode>
implements NetworkNodeExtendedMenuProvider<WirelessTransmitterData> {
private static final String TAG_UPGRADES = "u";
implements NetworkNodeExtendedMenuProvider<WirelessTransmitterData>, BlockEntityWithDrops {
private static final String TAG_UPGRADES = "upgr";

private final UpgradeContainer upgradeContainer = new UpgradeContainer(
UpgradeDestinations.WIRELESS_TRANSMITTER,
Expand All @@ -53,18 +58,27 @@ protected InWorldNetworkNodeContainer createMainContainer(final SimpleNetworkNod
@Override
public void saveAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
super.saveAdditional(tag, provider);
tag.put(TAG_UPGRADES, upgradeContainer.createTag(provider));
tag.put(TAG_UPGRADES, ContainerUtil.write(upgradeContainer, provider));
}

@Override
public void loadAdditional(final CompoundTag tag, final HolderLookup.Provider provider) {
if (tag.contains(TAG_UPGRADES)) {
upgradeContainer.fromTag(tag.getList(TAG_UPGRADES, Tag.TAG_COMPOUND), provider);
ContainerUtil.read(tag.getCompound(TAG_UPGRADES), upgradeContainer, provider);
}
configureAccordingToUpgrades();
super.loadAdditional(tag, provider);
}

@Override
public List<Item> getUpgradeItems() {
return upgradeContainer.getUpgradeItems();
}

@Override
public boolean addUpgradeItem(final Item upgradeItem) {
return upgradeContainer.addUpgradeItem(upgradeItem);
}

@Override
public void addOutgoingConnections(final ConnectionSink sink) {
final Direction myDirection = getDirection();
Expand Down Expand Up @@ -109,13 +123,18 @@ int getRange() {
}

private void upgradeContainerChanged() {
final long baseUsage = Platform.INSTANCE.getConfig().getWirelessTransmitter().getEnergyUsage();
mainNode.setEnergyUsage(baseUsage + upgradeContainer.getEnergyUsage());
setChanged();
configureAccordingToUpgrades();
}

private void configureAccordingToUpgrades() {
final long baseUsage = Platform.INSTANCE.getConfig().getWirelessTransmitter().getEnergyUsage();
mainNode.setEnergyUsage(baseUsage + upgradeContainer.getEnergyUsage());
@Override
public NonNullList<ItemStack> getDrops() {
final NonNullList<ItemStack> drops = NonNullList.create();
for (int i = 0; i < upgradeContainer.getContainerSize(); ++i) {
drops.add(upgradeContainer.getItem(i));
}
return drops;
}

@Override
Expand Down

0 comments on commit fa4162d

Please sign in to comment.