Handle volatiles

This commit is contained in:
raoulvdberge
2021-12-13 11:28:28 +01:00
parent 5c1aa6ae1f
commit 24e82e64dc
7 changed files with 21 additions and 23 deletions

View File

@@ -136,9 +136,9 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
}
}
// @Volatile: This is some logic copied from CraftingResultSlot#onCrafting. We call this manually for shift clicking because
// @Volatile: This is some logic copied from ResultSlot#checkTakeAchievements. We call this manually for shift clicking because
// otherwise it's not being called.
// For regular crafting, this is already called in ResultCraftingGridSlot#onTake -> onCrafting(stack)
// For regular crafting, this is already called in ResultCraftingGridSlot#onTake -> checkTakeAchievements(stack)
crafted.onCraftedBy(player.level, player, amountCrafted);
ForgeEventFactory.firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, amountCrafted), grid.getCraftingMatrix());
ForgeHooks.setCraftingPlayer(null);

View File

@@ -20,30 +20,28 @@ public abstract class RSWorldSavedData extends SavedData {
public abstract CompoundTag save(CompoundTag compound);
@Override
public void save(File fileIn) {
//@Volatile Mostly Copied from WorldSavedData
public void save(File file) {
// @Volatile Mostly Copied from SavedData
if (this.isDirty()) {
File tempFile = fileIn.toPath().getParent().resolve(fileIn.getName() + ".temp").toFile();
File tempFile = file.toPath().getParent().resolve(file.getName() + ".temp").toFile();
CompoundTag compoundnbt = new CompoundTag();
compoundnbt.put("data", this.save(new CompoundTag()));
compoundnbt.putInt("DataVersion", SharedConstants.getCurrentVersion().getWorldVersion());
CompoundTag tag = new CompoundTag();
tag.put("data", this.save(new CompoundTag()));
tag.putInt("DataVersion", SharedConstants.getCurrentVersion().getWorldVersion());
try {
NbtIo.writeCompressed(compoundnbt, tempFile);
if (fileIn.exists()) {
if (!fileIn.delete()) {
LOGGER.error("Failed To delete " + fileIn.getName());
NbtIo.writeCompressed(tag, tempFile);
if (file.exists()) {
if (!file.delete()) {
LOGGER.error("Failed to delete " + file.getName());
}
}
if (!tempFile.renameTo(fileIn)) {
if (!tempFile.renameTo(file)) {
LOGGER.error("Failed to rename " + tempFile.getName());
}
} catch (IOException ioexception) {
LOGGER.error("Could not save data {}", this, ioexception);
} catch (IOException e) {
LOGGER.error("Could not save data {}", this, e);
}
this.setDirty(false);
}
}

View File

@@ -58,6 +58,7 @@ public class CreateDiskCommand implements Command<CommandSourceStack> {
}
player.level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2F, ((player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.containerMenu.broadcastChanges();
} else {
ItemEntity itemEntity = player.drop(stack, false);
if (itemEntity != null) {

View File

@@ -79,7 +79,7 @@ public class ListNetworkCommand implements Command<CommandSourceStack> {
public NetworkInList(INetwork network) {
this.network = network;
// @Volatile: From CommandTps
// @Volatile: From TPSCommand
this.tickTime = mean(network.getTickTimes()) * 1.0E-6D;
this.tps = Math.min(1000.0 / tickTime, 20);
}

View File

@@ -278,7 +278,7 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
if (slot instanceof CraftingGridSlot || slot == craftingResultSlot || slot == patternResultSlot) {
for (ContainerListener listener : containerListeners) {
// @Volatile: We can't use ContainerSynchronizer#sendInitialData since ServerPlayerEntity blocks CraftingResultSlot changes...
// @Volatile: We can't use ContainerListener#slotChanged since ServerPlayer blocks ResultSlot changes...
if (listener instanceof ServerPlayer) {
((ServerPlayer) listener).connection.send(new ClientboundContainerSetSlotPacket(containerId, incrementStateId(), i, slot.getItem()));
}

View File

@@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage.integration.curios.CuriosIntegration;
import com.refinedmods.refinedstorage.util.PacketBufferUtils;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
@@ -38,9 +39,7 @@ public class PlayerSlot {
if (hand == InteractionHand.MAIN_HAND) {
return new PlayerSlot(player.getInventory().selected);
}
//@Volatile Offhand Slot, could use -1 as we aren't using this anywhere.
return new PlayerSlot(40);
return new PlayerSlot(Inventory.SLOT_OFFHAND);
}
public ItemStack getStackFromSlot(Player player) {

View File

@@ -6,7 +6,7 @@ public final class PacketBufferUtils {
private PacketBufferUtils() {
}
// @Volatile: From PacketBuffer#readString, this exists because SideOnly
// @Volatile: From PacketBuffer#readUtf, this exists because SideOnly
public static String readString(FriendlyByteBuf buffer) {
return buffer.readUtf(32767);
}