mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-24 12:35:43 +01:00
Change darkness->blindness in 1.19->1.18.2 (#908)
This commit is contained in:
parent
04a692022a
commit
8cb285db69
@ -36,6 +36,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
||||
private boolean handlePingsAsInvAcknowledgements;
|
||||
private boolean bedrockAtY0;
|
||||
private boolean sculkShriekersToCryingObsidian;
|
||||
private boolean mapDarknessEffect;
|
||||
private boolean suppressEmulationWarnings;
|
||||
|
||||
public ViaBackwardsConfig(File configFile, Logger logger) {
|
||||
@ -57,6 +58,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
||||
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
|
||||
bedrockAtY0 = getBoolean("bedrock-at-y-0", false);
|
||||
sculkShriekersToCryingObsidian = getBoolean("sculk-shriekers-to-crying-obsidian", false);
|
||||
mapDarknessEffect = getBoolean("map-darkness-effect", true);
|
||||
suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false);
|
||||
}
|
||||
|
||||
@ -100,6 +102,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
|
||||
return sculkShriekersToCryingObsidian;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mapDarknessEffect() {
|
||||
return mapDarknessEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean suppressEmulationWarnings() {
|
||||
return suppressEmulationWarnings;
|
||||
|
@ -78,6 +78,13 @@ public interface ViaBackwardsConfig extends Config {
|
||||
*/
|
||||
boolean sculkShriekerToCryingObsidian();
|
||||
|
||||
/**
|
||||
* Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean mapDarknessEffect();
|
||||
|
||||
/**
|
||||
* Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
|
||||
*
|
||||
|
@ -28,11 +28,11 @@ import com.viaversion.viabackwards.protocol.v1_19to1_18_2.rewriter.BlockItemPack
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.rewriter.CommandRewriter1_19;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.rewriter.EntityPacketRewriter1_19;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.DimensionRegistryStorage;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.EntityTracker1_19;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.NonceStorage;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||
@ -40,7 +40,6 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
||||
@ -364,7 +363,7 @@ public final class Protocol1_19To1_18_2 extends BackwardsProtocol<ClientboundPac
|
||||
@Override
|
||||
public void init(final UserConnection user) {
|
||||
user.put(new DimensionRegistryStorage());
|
||||
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_19.PLAYER));
|
||||
addEntityTracker(user, new EntityTracker1_19(user));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,9 +20,11 @@ package com.viaversion.viabackwards.protocol.v1_19to1_18_2.rewriter;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.DimensionRegistryStorage;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.EntityTracker1_19;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.LastDeathPosition;
|
||||
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.StoredPainting;
|
||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
@ -111,6 +113,50 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
|
||||
handler(wrapper -> {
|
||||
// Remove factor data
|
||||
wrapper.read(Types.OPTIONAL_NAMED_COMPOUND_TAG);
|
||||
|
||||
if (!ViaBackwards.getConfig().mapDarknessEffect()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityTracker1_19 tracker = tracker(wrapper.user());
|
||||
|
||||
final int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||
final int effectId = wrapper.get(Types.VAR_INT, 1);
|
||||
if (effectId == 33) { // Newly added darkness, rewrite to blindness
|
||||
tracker.getAffectedByDarkness().add(entityId);
|
||||
wrapper.set(Types.VAR_INT, 1, 15);
|
||||
} else if (effectId == 15) { // Track actual blindness effect for removal later
|
||||
tracker.getAffectedByBlindness().add(entityId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_19.REMOVE_MOB_EFFECT, new PacketHandlers() {
|
||||
@Override
|
||||
protected void register() {
|
||||
map(Types.VAR_INT); // Entity id
|
||||
map(Types.VAR_INT); // Effect id
|
||||
handler(wrapper -> {
|
||||
if (!ViaBackwards.getConfig().mapDarknessEffect()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int entityId = wrapper.get(Types.VAR_INT, 0);
|
||||
final int effectId = wrapper.get(Types.VAR_INT, 1);
|
||||
|
||||
final EntityTracker1_19 tracker = tracker(wrapper.user());
|
||||
if (effectId == 33) { // Remove darkness and the fake blindness effect if the client doesn't have actual blindness
|
||||
tracker.getAffectedByDarkness().rem(entityId);
|
||||
if (!tracker.getAffectedByBlindness().contains(entityId)) {
|
||||
wrapper.set(Types.VAR_INT, 1, 15);
|
||||
}
|
||||
} else if (effectId == 15) { // Remove blindness and cancel if the client has darkness (will be removed by darkness removal)
|
||||
tracker.getAffectedByBlindness().rem(entityId);
|
||||
if (tracker.getAffectedByDarkness().contains(entityId)) {
|
||||
wrapper.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.v1_19to1_18_2.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntArrayList;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntList;
|
||||
|
||||
public final class EntityTracker1_19 extends EntityTrackerBase {
|
||||
|
||||
private final IntList affectedByBlindness = new IntArrayList();
|
||||
private final IntList affectedByDarkness = new IntArrayList();
|
||||
|
||||
public EntityTracker1_19(final UserConnection connection) {
|
||||
super(connection, EntityTypes1_19.PLAYER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEntity(final int id) {
|
||||
super.removeEntity(id);
|
||||
this.affectedByBlindness.rem(id);
|
||||
this.affectedByDarkness.rem(id);
|
||||
}
|
||||
|
||||
public IntList getAffectedByBlindness() {
|
||||
return affectedByBlindness;
|
||||
}
|
||||
|
||||
public IntList getAffectedByDarkness() {
|
||||
return affectedByDarkness;
|
||||
}
|
||||
}
|
@ -28,5 +28,8 @@ bedrock-at-y-0: false
|
||||
# If disabled, the client will see them as end portal frames.
|
||||
sculk-shriekers-to-crying-obsidian: true
|
||||
#
|
||||
# Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers.
|
||||
map-darkness-effect: true
|
||||
#
|
||||
# Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
|
||||
suppress-emulation-warnings: false
|
Loading…
Reference in New Issue
Block a user