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. // 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); crafted.onCraftedBy(player.level, player, amountCrafted);
ForgeEventFactory.firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, amountCrafted), grid.getCraftingMatrix()); ForgeEventFactory.firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, amountCrafted), grid.getCraftingMatrix());
ForgeHooks.setCraftingPlayer(null); ForgeHooks.setCraftingPlayer(null);

View File

@@ -20,30 +20,28 @@ public abstract class RSWorldSavedData extends SavedData {
public abstract CompoundTag save(CompoundTag compound); public abstract CompoundTag save(CompoundTag compound);
@Override @Override
public void save(File fileIn) { public void save(File file) {
//@Volatile Mostly Copied from WorldSavedData // @Volatile Mostly Copied from SavedData
if (this.isDirty()) { 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(); CompoundTag tag = new CompoundTag();
compoundnbt.put("data", this.save(new CompoundTag())); tag.put("data", this.save(new CompoundTag()));
compoundnbt.putInt("DataVersion", SharedConstants.getCurrentVersion().getWorldVersion()); tag.putInt("DataVersion", SharedConstants.getCurrentVersion().getWorldVersion());
try { try {
NbtIo.writeCompressed(compoundnbt, tempFile); NbtIo.writeCompressed(tag, tempFile);
if (fileIn.exists()) { if (file.exists()) {
if (!fileIn.delete()) { if (!file.delete()) {
LOGGER.error("Failed To delete " + fileIn.getName()); LOGGER.error("Failed to delete " + file.getName());
} }
} }
if (!tempFile.renameTo(fileIn)) { if (!tempFile.renameTo(file)) {
LOGGER.error("Failed to rename " + tempFile.getName()); LOGGER.error("Failed to rename " + tempFile.getName());
} }
} catch (IOException e) {
} catch (IOException ioexception) { LOGGER.error("Could not save data {}", this, e);
LOGGER.error("Could not save data {}", this, ioexception);
} }
this.setDirty(false); 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.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 { } else {
ItemEntity itemEntity = player.drop(stack, false); ItemEntity itemEntity = player.drop(stack, false);
if (itemEntity != null) { if (itemEntity != null) {

View File

@@ -79,7 +79,7 @@ public class ListNetworkCommand implements Command<CommandSourceStack> {
public NetworkInList(INetwork network) { public NetworkInList(INetwork network) {
this.network = network; this.network = network;
// @Volatile: From CommandTps // @Volatile: From TPSCommand
this.tickTime = mean(network.getTickTimes()) * 1.0E-6D; this.tickTime = mean(network.getTickTimes()) * 1.0E-6D;
this.tps = Math.min(1000.0 / tickTime, 20); 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) { if (slot instanceof CraftingGridSlot || slot == craftingResultSlot || slot == patternResultSlot) {
for (ContainerListener listener : containerListeners) { 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) { if (listener instanceof ServerPlayer) {
((ServerPlayer) listener).connection.send(new ClientboundContainerSetSlotPacket(containerId, incrementStateId(), i, slot.getItem())); ((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 com.refinedmods.refinedstorage.util.PacketBufferUtils;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
@@ -38,9 +39,7 @@ public class PlayerSlot {
if (hand == InteractionHand.MAIN_HAND) { if (hand == InteractionHand.MAIN_HAND) {
return new PlayerSlot(player.getInventory().selected); return new PlayerSlot(player.getInventory().selected);
} }
return new PlayerSlot(Inventory.SLOT_OFFHAND);
//@Volatile Offhand Slot, could use -1 as we aren't using this anywhere.
return new PlayerSlot(40);
} }
public ItemStack getStackFromSlot(Player player) { public ItemStack getStackFromSlot(Player player) {

View File

@@ -6,7 +6,7 @@ public final class PacketBufferUtils {
private 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) { public static String readString(FriendlyByteBuf buffer) {
return buffer.readUtf(32767); return buffer.readUtf(32767);
} }