mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fish fixes (#374)
* Fixed tropical fish display. * Added base pufferfish class * Fixed pufferfish, fish flags and cleaned up tropical fish spawning * Fixed tropical fish model variant * Fix tropical fish colours
This commit is contained in:
parent
ba60f92722
commit
7417f57d47
4 changed files with 156 additions and 2 deletions
|
@ -25,12 +25,28 @@
|
||||||
|
|
||||||
package org.geysermc.connector.entity.living;
|
package org.geysermc.connector.entity.living;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
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.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
public class AbstractFishEntity extends WaterEntity {
|
public class AbstractFishEntity extends WaterEntity {
|
||||||
|
|
||||||
public AbstractFishEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public AbstractFishEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.CAN_SWIM, true);
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.BREATHING, true);
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.CAN_CLIMB, false);
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.HAS_GRAVITY, false);
|
||||||
|
|
||||||
|
metadata.put(EntityData.AIR, (short) 400);
|
||||||
|
|
||||||
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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.living.animal;
|
||||||
|
|
||||||
|
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 org.geysermc.connector.entity.living.AbstractFishEntity;
|
||||||
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
public class PufferFishEntity extends AbstractFishEntity {
|
||||||
|
|
||||||
|
public PufferFishEntity(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() == 16) {
|
||||||
|
// Transfers correctly but doesn't apply on the client
|
||||||
|
int puffsize = (int) entityMetadata.getValue();
|
||||||
|
metadata.put(EntityData.PUFFERFISH_SIZE, puffsize);
|
||||||
|
metadata.put(EntityData.VARIANT, puffsize);
|
||||||
|
}
|
||||||
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* 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.living.animal;
|
||||||
|
|
||||||
|
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.packet.AddEntityPacket;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.geysermc.connector.entity.living.AbstractFishEntity;
|
||||||
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
|
public class TropicalFishEntity extends AbstractFishEntity {
|
||||||
|
|
||||||
|
public TropicalFishEntity(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() == 16) {
|
||||||
|
// Still not always the right model and colour is broken
|
||||||
|
TropicalFishVariant variant = TropicalFishVariant.fromVariantNumber((int) entityMetadata.getValue());
|
||||||
|
metadata.put(EntityData.VARIANT, variant.getShape()); // Shape 0-1
|
||||||
|
metadata.put(EntityData.MARK_VARIANT, variant.getPattern()); // Pattern 0-5
|
||||||
|
metadata.put(EntityData.COLOR, variant.getBaseColor()); // Base color 0-15
|
||||||
|
metadata.put(EntityData.COLOR_2, variant.getPatternColor()); // Pattern color 0-15
|
||||||
|
}
|
||||||
|
super.updateBedrockMetadata(entityMetadata, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void spawnEntity(GeyserSession session) {
|
||||||
|
AddEntityPacket addEntityPacket = new AddEntityPacket();
|
||||||
|
addEntityPacket.setIdentifier("minecraft:tropicalfish");
|
||||||
|
addEntityPacket.setRuntimeEntityId(geyserId);
|
||||||
|
addEntityPacket.setUniqueEntityId(geyserId);
|
||||||
|
addEntityPacket.setPosition(position);
|
||||||
|
addEntityPacket.setMotion(motion);
|
||||||
|
addEntityPacket.setRotation(getBedrockRotation());
|
||||||
|
addEntityPacket.setEntityType(entityType.getType());
|
||||||
|
addEntityPacket.getMetadata().putAll(metadata);
|
||||||
|
|
||||||
|
valid = true;
|
||||||
|
session.getUpstream().sendPacket(addEntityPacket);
|
||||||
|
|
||||||
|
session.getConnector().getLogger().debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
private static class TropicalFishVariant {
|
||||||
|
private int shape;
|
||||||
|
private int pattern;
|
||||||
|
private byte baseColor;
|
||||||
|
private byte patternColor;
|
||||||
|
|
||||||
|
public static TropicalFishVariant fromVariantNumber(int varNumber) {
|
||||||
|
return new TropicalFishVariant((varNumber & 0xFF), ((varNumber >> 8) & 0xFF), (byte) ((varNumber >> 16) & 0xFF), (byte) ((varNumber >> 24) & 0xFF));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -140,10 +140,10 @@ public enum EntityType {
|
||||||
VEX(MonsterEntity.class, 105, 0f),
|
VEX(MonsterEntity.class, 105, 0f),
|
||||||
ICE_BOMB(Entity.class, 106, 0f),
|
ICE_BOMB(Entity.class, 106, 0f),
|
||||||
BALLOON(Entity.class, 107, 0f), //TODO
|
BALLOON(Entity.class, 107, 0f), //TODO
|
||||||
PUFFERFISH(AbstractFishEntity.class, 108, 0.7f, 0.7f),
|
PUFFERFISH(PufferFishEntity.class, 108, 0.7f, 0.7f),
|
||||||
SALMON(AbstractFishEntity.class, 109, 0.5f, 0.7f),
|
SALMON(AbstractFishEntity.class, 109, 0.5f, 0.7f),
|
||||||
DROWNED(ZombieEntity.class, 110, 1.95f, 0.6f),
|
DROWNED(ZombieEntity.class, 110, 1.95f, 0.6f),
|
||||||
TROPICAL_FISH(AbstractFishEntity.class, 111, 0.6f, 0.6f),
|
TROPICAL_FISH(TropicalFishEntity.class, 111, 0.6f, 0.6f),
|
||||||
COD(AbstractFishEntity.class, 112, 0.25f, 0.5f),
|
COD(AbstractFishEntity.class, 112, 0.25f, 0.5f),
|
||||||
PANDA(PandaEntity.class, 113, 1.25f, 1.125f, 1.825f),
|
PANDA(PandaEntity.class, 113, 1.25f, 1.125f, 1.825f),
|
||||||
FOX(FoxEntity.class, 121, 0.5f, 1.25f),
|
FOX(FoxEntity.class, 121, 0.5f, 1.25f),
|
||||||
|
|
Loading…
Reference in a new issue