Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 17:10:13 +01:00
Improve 1.9->1.8 block place translation (and fix some bugs) (#2437)
Dieser Commit ist enthalten in:
Ursprung
d3a3e366b1
Commit
cfec0cc25f
@ -50,7 +50,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.CommandBlockStorag
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.PlaceBlockTracker;
|
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -169,8 +168,6 @@ public class Protocol1_9To1_8 extends Protocol<ClientboundPackets1_8, Clientboun
|
|||||||
userConnection.put(new MovementTracker(userConnection));
|
userConnection.put(new MovementTracker(userConnection));
|
||||||
// Inventory tracker
|
// Inventory tracker
|
||||||
userConnection.put(new InventoryTracker(userConnection));
|
userConnection.put(new InventoryTracker(userConnection));
|
||||||
// Place block tracker
|
|
||||||
userConnection.put(new PlaceBlockTracker(userConnection));
|
|
||||||
// CommandBlock storage
|
// CommandBlock storage
|
||||||
userConnection.put(new CommandBlockStorage(userConnection));
|
userConnection.put(new CommandBlockStorage(userConnection));
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.PlaceBlockTracker;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Chunk1_9to1_8Type;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Chunk1_9to1_8Type;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -351,7 +350,13 @@ public class WorldPackets {
|
|||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
map(Type.POSITION); // 0 - Position
|
map(Type.POSITION); // 0 - Position
|
||||||
map(Type.VAR_INT, Type.UNSIGNED_BYTE); // 1 - Block Face
|
map(Type.VAR_INT, Type.UNSIGNED_BYTE); // 1 - Block Face
|
||||||
map(Type.VAR_INT, Type.NOTHING); // 2 - Hand
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
final int hand = wrapper.read(Type.VAR_INT); // 2 - Hand
|
||||||
|
if (hand != 0) wrapper.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
create(new ValueCreator() {
|
create(new ValueCreator() {
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketWrapper wrapper) throws Exception {
|
public void write(PacketWrapper wrapper) throws Exception {
|
||||||
@ -363,19 +368,6 @@ public class WorldPackets {
|
|||||||
map(Type.UNSIGNED_BYTE); // 5 - Y
|
map(Type.UNSIGNED_BYTE); // 5 - Y
|
||||||
map(Type.UNSIGNED_BYTE); // 6 - Z
|
map(Type.UNSIGNED_BYTE); // 6 - Z
|
||||||
|
|
||||||
// Cancel if item as 1.9 uses Use_Item packet
|
|
||||||
handler(new PacketHandler() {
|
|
||||||
@Override
|
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
|
||||||
Position position = wrapper.get(Type.POSITION, 0);
|
|
||||||
PlaceBlockTracker tracker = wrapper.user().get(PlaceBlockTracker.class);
|
|
||||||
if (tracker.getLastPlacedPosition() != null && tracker.getLastPlacedPosition().equals(position) && !tracker.isExpired(50))
|
|
||||||
wrapper.cancel();
|
|
||||||
tracker.updateTime();
|
|
||||||
tracker.setLastPlacedPosition(position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Register block place to fix sounds
|
//Register block place to fix sounds
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,7 +56,7 @@ public class EntityTracker1_9 extends EntityTracker {
|
|||||||
private final Set<Integer> validBlocking = Sets.newConcurrentHashSet();
|
private final Set<Integer> validBlocking = Sets.newConcurrentHashSet();
|
||||||
private final Set<Integer> knownHolograms = Sets.newConcurrentHashSet();
|
private final Set<Integer> knownHolograms = Sets.newConcurrentHashSet();
|
||||||
private final Set<Position> blockInteractions = Collections.newSetFromMap(CacheBuilder.newBuilder()
|
private final Set<Position> blockInteractions = Collections.newSetFromMap(CacheBuilder.newBuilder()
|
||||||
.maximumSize(10)
|
.maximumSize(1000)
|
||||||
.expireAfterAccess(250, TimeUnit.MILLISECONDS)
|
.expireAfterAccess(250, TimeUnit.MILLISECONDS)
|
||||||
.<Position, Boolean>build()
|
.<Position, Boolean>build()
|
||||||
.asMap());
|
.asMap());
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
|
||||||
* Copyright (C) 2016-2021 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 us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
|
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.data.StoredObject;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.Position;
|
|
||||||
|
|
||||||
public class PlaceBlockTracker extends StoredObject {
|
|
||||||
private long lastPlaceTimestamp = 0;
|
|
||||||
private Position lastPlacedPosition = null;
|
|
||||||
|
|
||||||
public PlaceBlockTracker(UserConnection user) {
|
|
||||||
super(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a certain amount of time has passed
|
|
||||||
*
|
|
||||||
* @param ms The amount of time in MS
|
|
||||||
* @return True if it has passed
|
|
||||||
*/
|
|
||||||
public boolean isExpired(int ms) {
|
|
||||||
return System.currentTimeMillis() > (lastPlaceTimestamp + ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the last place time to the current time
|
|
||||||
*/
|
|
||||||
public void updateTime() {
|
|
||||||
lastPlaceTimestamp = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastPlaceTimestamp() {
|
|
||||||
return lastPlaceTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position getLastPlacedPosition() {
|
|
||||||
return lastPlacedPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastPlacedPosition(Position lastPlacedPosition) {
|
|
||||||
this.lastPlacedPosition = lastPlacedPosition;
|
|
||||||
}
|
|
||||||
}
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren