3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Add tnt sounds/particles and support for level event sounds

Dieser Commit ist enthalten in:
RednedEpic 2020-05-03 01:48:38 -05:00
Ursprung 3370ad3db9
Commit 7f7d89e517
6 geänderte Dateien mit 103 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,65 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/
package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class TNTEntity extends Entity {
private int currentTick;
public TNTEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
}
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 7) {
currentTick = (int) entityMetadata.getValue();
metadata.getFlags().setFlag(EntityFlag.IGNITED, true);
metadata.put(EntityData.FUSE_LENGTH, currentTick);
ScheduledFuture<?> future = session.getConnector().getGeneralThreadPool().scheduleAtFixedRate(() -> {
if (currentTick % 5 == 0) {
metadata.put(EntityData.FUSE_LENGTH, currentTick);
}
currentTick--;
super.updateBedrockMetadata(entityMetadata, session);
}, 50, 50, TimeUnit.MILLISECONDS); // 5 ticks
session.getConnector().getGeneralThreadPool().schedule(() -> future.cancel(true), (int) entityMetadata.getValue() / 20, TimeUnit.SECONDS);
}
super.updateBedrockMetadata(entityMetadata, session);
}
}

Datei anzeigen

@ -98,7 +98,7 @@ public enum EntityType {
TRIPOD_CAMERA(Entity.class, 62, 0f),
PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f),
ITEM(ItemEntity.class, 64, 0.25f, 0.25f),
TNT(Entity.class, 65, 0.98f, 0.98f),
TNT(TNTEntity.class, 65, 0.98f, 0.98f),
FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f),
MOVING_BLOCK(Entity.class, 67, 0f),
EXPERIENCE_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f),

Datei anzeigen

@ -28,7 +28,12 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerExplosionPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@ -41,7 +46,22 @@ public class JavaExplosionTranslator extends PacketTranslator<ServerExplosionPac
@Override
public void translate(ServerExplosionPacket packet, GeyserSession session) {
for (ExplodedBlockRecord record : packet.getExploded()) {
ChunkUtils.updateBlock(session, BlockTranslator.AIR, Vector3i.from(record.getX(), record.getY(), record.getZ()));
Vector3f pos = Vector3f.from(packet.getX() + record.getX(), packet.getY() + record.getY(), packet.getZ() + record.getZ());
// Since bedrock does not play an explosion sound and particles sound, we have to manually do so
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setType(LevelEventType.PARTICLE_LARGE_EXPLOSION);
levelEventPacket.setData(0);
levelEventPacket.setPosition(pos.toFloat());
session.getUpstream().sendPacket(levelEventPacket);
ChunkUtils.updateBlock(session, BlockTranslator.AIR, pos.toInt());
}
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setRelativeVolumeDisabled(false);
levelSoundEventPacket.setBabySound(false);
levelSoundEventPacket.setExtraData(-1);
levelSoundEventPacket.setSound(SoundEvent.EXPLODE);
levelSoundEventPacket.setIdentifier(":");
levelSoundEventPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
session.getUpstream().sendPacket(levelSoundEventPacket);
}
}

Datei anzeigen

@ -27,7 +27,9 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayBuiltinSoundPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -49,6 +51,14 @@ public class JavaPlayBuiltinSoundTranslator extends PacketTranslator<ServerPlayB
return;
}
if (soundMapping.isLevelEvent()) {
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
levelEventPacket.setData(0);
levelEventPacket.setType(LevelEventType.valueOf(soundMapping.getBedrock()));
session.getUpstream().sendPacket(levelEventPacket);
return;
}
LevelSoundEventPacket soundPacket = new LevelSoundEventPacket();
SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.getBedrock());
if (sound == null) {

Datei anzeigen

@ -66,7 +66,8 @@ public class SoundUtils {
brMap.has("bedrock_mapping") && brMap.get("bedrock_mapping").isTextual() ? brMap.get("bedrock_mapping").asText() : null,
brMap.has("playsound_mapping") && brMap.get("playsound_mapping").isTextual() ? brMap.get("playsound_mapping").asText() : null,
brMap.has("extra_data") && brMap.get("extra_data").isInt() ? brMap.get("extra_data").asInt() : -1,
brMap.has("identifier") && brMap.get("identifier").isTextual() ? brMap.get("identifier").asText() : null
brMap.has("identifier") && brMap.get("identifier").isTextual() ? brMap.get("identifier").asText() : null,
brMap.has("level_event") && brMap.get("level_event").isBoolean() ? brMap.get("level_event").asBoolean() : false
)
);
}
@ -102,13 +103,15 @@ public class SoundUtils {
private final String playsound;
private final int extraData;
private String identifier;
private boolean levelEvent;
public SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier) {
public SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier, boolean levelEvent) {
this.java = java;
this.bedrock = bedrock == null || bedrock.equalsIgnoreCase("") ? null : bedrock;
this.playsound = playsound == null || playsound.equalsIgnoreCase("") ? null : playsound;
this.extraData = extraData;
this.identifier = identifier == null || identifier.equalsIgnoreCase("") ? ":" : identifier;
this.levelEvent = levelEvent;
}
}
}

@ -1 +1 @@
Subproject commit f3ddcd8b537f4064a5f858df866efec2e620f631
Subproject commit 848984295e2b2223cda81fd8514d2dc29b5f1a47