2021-06-04 12:15:14 +02:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2024-01-12 10:01:48 +01:00
|
|
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
2021-06-04 12:15:14 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
package com.viaversion.viaversion.api.rewriter;
|
|
|
|
|
2024-04-21 22:39:13 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
2021-06-04 12:15:14 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
|
|
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
2024-02-29 18:23:46 +01:00
|
|
|
import com.viaversion.viaversion.api.type.Type;
|
2021-06-04 12:15:14 +02:00
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
|
|
|
|
|
|
public interface ItemRewriter<T extends Protocol> extends Rewriter<T> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rewritten item, which may or may not be the same given Item instance.
|
|
|
|
*
|
2024-04-21 22:39:13 +02:00
|
|
|
* @param connection user connection
|
|
|
|
* @param item item
|
2021-06-04 12:15:14 +02:00
|
|
|
* @return rewritten item
|
|
|
|
*/
|
2024-04-21 22:39:13 +02:00
|
|
|
@Nullable
|
|
|
|
Item handleItemToClient(UserConnection connection, @Nullable Item item);
|
2021-06-04 12:15:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the rewritten item, which may or may not be the same given Item instance.
|
|
|
|
*
|
2024-04-21 22:39:13 +02:00
|
|
|
* @param connection user connection
|
|
|
|
* @param item item
|
2021-06-04 12:15:14 +02:00
|
|
|
* @return rewritten item
|
|
|
|
*/
|
2024-04-21 22:39:13 +02:00
|
|
|
@Nullable
|
|
|
|
Item handleItemToServer(UserConnection connection, @Nullable Item item);
|
2024-02-29 18:23:46 +01:00
|
|
|
|
2024-03-05 23:23:57 +01:00
|
|
|
/**
|
|
|
|
* Returns the item type of the current protocol.
|
2024-04-04 09:31:58 +02:00
|
|
|
*
|
2024-03-05 23:23:57 +01:00
|
|
|
* @return item type
|
|
|
|
*/
|
2024-04-04 09:31:58 +02:00
|
|
|
@Nullable
|
|
|
|
default Type<Item> itemType() {
|
2024-03-05 23:23:57 +01:00
|
|
|
return null;
|
|
|
|
}
|
2024-02-29 18:23:46 +01:00
|
|
|
|
2024-03-05 23:23:57 +01:00
|
|
|
/**
|
|
|
|
* Returns the item array type of the current protocol.
|
2024-04-04 09:31:58 +02:00
|
|
|
*
|
2024-03-05 23:23:57 +01:00
|
|
|
* @return item array type
|
|
|
|
*/
|
2024-04-04 09:31:58 +02:00
|
|
|
@Nullable
|
|
|
|
default Type<Item[]> itemArrayType() {
|
2024-03-05 23:23:57 +01:00
|
|
|
return null;
|
|
|
|
}
|
2024-02-29 18:23:46 +01:00
|
|
|
|
2024-03-05 23:23:57 +01:00
|
|
|
/**
|
|
|
|
* Returns the mapped item type of the target protocol.
|
2024-04-04 09:31:58 +02:00
|
|
|
*
|
2024-03-05 23:23:57 +01:00
|
|
|
* @return mapped item type
|
|
|
|
*/
|
2024-04-04 09:31:58 +02:00
|
|
|
@Nullable
|
|
|
|
default Type<Item> mappedItemType() {
|
2024-03-05 23:23:57 +01:00
|
|
|
return itemType();
|
|
|
|
}
|
2024-02-29 18:23:46 +01:00
|
|
|
|
2024-03-05 23:23:57 +01:00
|
|
|
/**
|
|
|
|
* Returns the mapped item array type of the target protocol.
|
2024-04-04 09:31:58 +02:00
|
|
|
*
|
2024-03-05 23:23:57 +01:00
|
|
|
* @return mapped item array type
|
|
|
|
*/
|
2024-04-04 09:31:58 +02:00
|
|
|
@Nullable
|
|
|
|
default Type<Item[]> mappedItemArrayType() {
|
2024-03-05 23:23:57 +01:00
|
|
|
return itemArrayType();
|
|
|
|
}
|
2024-04-04 09:31:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the NBT tag name used for storing original item data.
|
|
|
|
*
|
|
|
|
* @return NBT tag name
|
|
|
|
*/
|
|
|
|
default String nbtTagName() {
|
|
|
|
return "VV|" + protocol().getClass().getSimpleName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefixes the NBT tag name with the current protocol's {@link #nbtTagName()}.
|
|
|
|
*
|
|
|
|
* @param nbt NBT tag name
|
|
|
|
* @return prefixed NBT tag name
|
|
|
|
*/
|
|
|
|
default String nbtTagName(final String nbt) {
|
|
|
|
return nbtTagName() + "|" + nbt;
|
|
|
|
}
|
2021-06-04 12:15:14 +02:00
|
|
|
}
|