89 lines
3.7 KiB
Java
89 lines
3.7 KiB
Java
/*
|
|
* 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 com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata;
|
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
|
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
|
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
|
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13;
|
|
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
|
|
import com.viaversion.viaversion.api.type.types.Particle;
|
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
|
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
|
|
|
import java.util.List;
|
|
|
|
public class MetadataRewriter1_15To1_14_4 extends EntityRewriter<Protocol1_15To1_14_4> {
|
|
|
|
public MetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) {
|
|
super(protocol);
|
|
}
|
|
|
|
@Override
|
|
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
|
if (metadata.metaType() == MetaType1_14.Slot) {
|
|
protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue());
|
|
} else if (metadata.metaType() == MetaType1_14.BlockID) {
|
|
// Convert to new block id
|
|
int data = (int) metadata.getValue();
|
|
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
|
} else if (metadata.metaType() == MetaType1_13.PARTICLE) {
|
|
rewriteParticle((Particle) metadata.getValue());
|
|
}
|
|
|
|
if (type == null) return;
|
|
|
|
if (type.isOrHasParent(Entity1_15Types.MINECART_ABSTRACT)
|
|
&& metadata.id() == 10) {
|
|
// Convert to new block id
|
|
int data = (int) metadata.getValue();
|
|
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
|
|
}
|
|
|
|
// Metadata 12 added to abstract_living
|
|
if (metadata.id() > 11 && type.isOrHasParent(Entity1_15Types.LIVINGENTITY)) {
|
|
metadata.setId(metadata.id() + 1); //TODO is it 11 or 12? what is it for?
|
|
}
|
|
|
|
//NOTES:
|
|
//new boolean with id 11 for trident, default = false, added in 19w45a
|
|
//new boolean with id 17 for enderman
|
|
|
|
if (type.isOrHasParent(Entity1_15Types.WOLF)) {
|
|
if (metadata.id() == 18) {
|
|
metadatas.remove(metadata);
|
|
} else if (metadata.id() > 18) {
|
|
metadata.setId(metadata.id() - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int newEntityId(final int id) {
|
|
return EntityPackets.getNewEntityId(id);
|
|
}
|
|
|
|
@Override
|
|
public EntityType typeFromId(int type) {
|
|
return Entity1_15Types.getTypeFromId(type);
|
|
}
|
|
}
|