Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-17 13:30:14 +01:00
Fix notes color from note block being wrong in 1.13->1.12 (#680)
Closes https://github.com/ViaVersion/ViaBackwards/issues/679
Dieser Commit ist enthalten in:
Ursprung
170e5f224f
Commit
dca8ecf1db
@ -29,6 +29,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerP
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
@ -124,6 +125,8 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
||||
if (ViaBackwards.getConfig().isFix1_13FacePlayer() && !user.has(PlayerPositionStorage1_13.class)) {
|
||||
user.put(new PlayerPositionStorage1_13());
|
||||
}
|
||||
|
||||
user.put(new NoteBlockStorage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2T
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
@ -56,6 +57,8 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.BlockIdData
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -136,6 +139,17 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
else if (blockId >= 483 && blockId <= 498)
|
||||
blockId = blockId - 483 + 219;
|
||||
|
||||
if (blockId == 25) { // Note block
|
||||
final NoteBlockStorage noteBlockStorage = wrapper.user().get(NoteBlockStorage.class);
|
||||
|
||||
final Position position = wrapper.get(Type.POSITION1_8, 0);
|
||||
final Pair<Integer, Integer> update = noteBlockStorage.getNoteBlockUpdate(position);
|
||||
if (update != null) { // Use values from block state update
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, update.key().shortValue());
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 1, update.value().shortValue());
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.set(Type.VAR_INT, 0, blockId);
|
||||
});
|
||||
}
|
||||
@ -189,6 +203,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
|
||||
int blockState = wrapper.read(Type.VAR_INT);
|
||||
Position position = wrapper.get(Type.POSITION1_8, 0);
|
||||
|
||||
// Note block special treatment
|
||||
if (blockState >= 249 && blockState <= 748) { // Note block states id range
|
||||
wrapper.user().get(NoteBlockStorage.class).storeNoteBlockUpdate(position, blockState);
|
||||
}
|
||||
|
||||
// Store blocks
|
||||
BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class);
|
||||
storage.checkAndStore(position, blockState);
|
||||
|
@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityType
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
@ -197,7 +198,10 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
|
||||
map(Type.INT); // 0 - Dimension ID
|
||||
|
||||
handler(getDimensionHandler(0));
|
||||
handler(wrapper -> wrapper.user().get(BackwardsBlockStorage.class).clear());
|
||||
handler(wrapper -> {
|
||||
wrapper.user().get(BackwardsBlockStorage.class).clear();
|
||||
wrapper.user().get(NoteBlockStorage.class).clear();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.Position;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
public class NoteBlockStorage implements StorableObject {
|
||||
|
||||
private static final int MAX_NOTE_ID = 24;
|
||||
|
||||
private final Object2IntMap<Position> noteBlockUpdates = new Object2IntOpenHashMap<>();
|
||||
|
||||
public void storeNoteBlockUpdate(final Position position, final int blockStateId) {
|
||||
noteBlockUpdates.put(position, blockStateId);
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getNoteBlockUpdate(final Position position) {
|
||||
if (!noteBlockUpdates.containsKey(position)) {
|
||||
return null;
|
||||
}
|
||||
int relativeBlockState = noteBlockUpdates.removeInt(position) - 249;
|
||||
relativeBlockState = relativeBlockState / 2; // Get rid of powered state
|
||||
|
||||
return new Pair<>(relativeBlockState / MAX_NOTE_ID + 1, relativeBlockState % MAX_NOTE_ID + 1);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
noteBlockUpdates.clear();
|
||||
}
|
||||
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren