use of com.viaversion.viaversion.api.minecraft.item.Item in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_15 method registerPackets.
@Override
protected void registerPackets() {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Chunk chunk = wrapper.read(new Chunk1_15Type());
wrapper.write(new Chunk1_14Type(), chunk);
if (chunk.isFullChunk()) {
int[] biomeData = chunk.getBiomeData();
int[] newBiomeData = new int[256];
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
int x = j << 2;
int z = i << 2;
int newIndex = z << 4 | x;
int oldIndex = i << 2 | j;
int biome = biomeData[oldIndex];
for (int k = 0; k < 4; k++) {
int offX = newIndex + (k << 4);
for (int l = 0; l < 4; l++) {
newBiomeData[offX + l] = biome;
}
}
}
}
chunk.setBiomeData(newBiomeData);
}
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(j, newId);
}
}
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Particle ID
map(Type.INT);
// 1 - Long Distance
map(Type.BOOLEAN);
// 2 - X
map(Type.DOUBLE, Type.FLOAT);
// 3 - Y
map(Type.DOUBLE, Type.FLOAT);
// 4 - Z
map(Type.DOUBLE, Type.FLOAT);
// 5 - Offset X
map(Type.FLOAT);
// 6 - Offset Y
map(Type.FLOAT);
// 7 - Offset Z
map(Type.FLOAT);
// 8 - Particle Data
map(Type.FLOAT);
// 9 - Particle Count
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 3 || id == 23) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) {
Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
}
int mappedId = protocol.getMappingData().getNewParticleId(id);
if (id != mappedId) {
wrapper.set(Type.INT, 0, mappedId);
}
}
});
}
});
}
use of com.viaversion.viaversion.api.minecraft.item.Item in project ViaBackwards by ViaVersion.
the class EntityPackets1_16 method registerRewrites.
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
meta.setMetaType(Types1_14.META_TYPES.byId(meta.metaType().typeId()));
MetaType type = meta.metaType();
if (type == Types1_14.META_TYPES.itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient((Item) meta.getValue()));
} else if (type == Types1_14.META_TYPES.blockStateType) {
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
} else if (type == Types1_14.META_TYPES.particleType) {
rewriteParticle((Particle) meta.getValue());
} else if (type == Types1_14.META_TYPES.optionalComponentType) {
JsonElement text = meta.value();
if (text != null) {
protocol.getTranslatableRewriter().processText(text);
}
}
});
mapEntityType(Entity1_16Types.ZOMBIFIED_PIGLIN, Entity1_15Types.ZOMBIE_PIGMAN);
mapTypes(Entity1_16Types.values(), Entity1_15Types.class);
mapEntityTypeWithData(Entity1_16Types.HOGLIN, Entity1_16Types.COW).jsonName();
mapEntityTypeWithData(Entity1_16Types.ZOGLIN, Entity1_16Types.COW).jsonName();
mapEntityTypeWithData(Entity1_16Types.PIGLIN, Entity1_16Types.ZOMBIFIED_PIGLIN).jsonName();
mapEntityTypeWithData(Entity1_16Types.STRIDER, Entity1_16Types.MAGMA_CUBE).jsonName();
filter().type(Entity1_16Types.ZOGLIN).cancel(16);
filter().type(Entity1_16Types.HOGLIN).cancel(15);
filter().type(Entity1_16Types.PIGLIN).cancel(16);
filter().type(Entity1_16Types.PIGLIN).cancel(17);
filter().type(Entity1_16Types.PIGLIN).cancel(18);
filter().type(Entity1_16Types.STRIDER).index(15).handler((event, meta) -> {
boolean baby = meta.value();
meta.setTypeAndValue(Types1_14.META_TYPES.varIntType, baby ? 1 : 3);
});
filter().type(Entity1_16Types.STRIDER).cancel(16);
filter().type(Entity1_16Types.STRIDER).cancel(17);
filter().type(Entity1_16Types.STRIDER).cancel(18);
filter().type(Entity1_16Types.FISHING_BOBBER).cancel(8);
filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).cancel(8);
filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).handler((event, meta) -> {
if (event.index() >= 8) {
event.setIndex(event.index() + 1);
}
});
filter().type(Entity1_16Types.WOLF).index(16).handler((event, meta) -> {
byte mask = meta.value();
StoredEntityData data = tracker(event.user()).entityData(event.entityId());
data.put(new WolfDataMaskStorage(mask));
});
filter().type(Entity1_16Types.WOLF).index(20).handler((event, meta) -> {
StoredEntityData data = tracker(event.user()).entityDataIfPresent(event.entityId());
byte previousMask = 0;
if (data != null) {
WolfDataMaskStorage wolfData = data.get(WolfDataMaskStorage.class);
if (wolfData != null) {
previousMask = wolfData.tameableMask();
}
}
int angerTime = meta.value();
byte tameableMask = (byte) (angerTime > 0 ? previousMask | 2 : previousMask & -3);
event.createExtraMeta(new Metadata(16, Types1_14.META_TYPES.byteType, tameableMask));
event.cancel();
});
}
use of com.viaversion.viaversion.api.minecraft.item.Item in project ViaVersion by ViaVersion.
the class RecipeRewriter1_16 method handleSmithing.
public void handleSmithing(PacketWrapper wrapper) throws Exception {
Item[] baseIngredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : baseIngredients) {
rewrite(item);
}
Item[] ingredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : ingredients) {
rewrite(item);
}
// Result
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
use of com.viaversion.viaversion.api.minecraft.item.Item in project ViaVersion by ViaVersion.
the class ComponentRewriter1_13 method handleHoverEvent.
@Override
protected void handleHoverEvent(JsonObject hoverEvent) {
super.handleHoverEvent(hoverEvent);
String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
if (!action.equals("show_item"))
return;
JsonElement value = hoverEvent.get("value");
if (value == null)
return;
String text = findItemNBT(value);
if (text == null)
return;
CompoundTag tag;
try {
tag = BinaryTagIO.readString(text);
} catch (Exception e) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Error reading NBT in show_item:" + text);
e.printStackTrace();
}
return;
}
CompoundTag itemTag = tag.get("tag");
ShortTag damageTag = tag.get("Damage");
// Call item converter
short damage = damageTag != null ? damageTag.asShort() : 0;
Item item = new DataItem();
item.setData(damage);
item.setTag(itemTag);
protocol.getItemRewriter().handleItemToClient(item);
// Serialize again
if (damage != item.data()) {
tag.put("Damage", new ShortTag(item.data()));
}
if (itemTag != null) {
tag.put("tag", itemTag);
}
JsonArray array = new JsonArray();
JsonObject object = new JsonObject();
array.add(object);
String serializedNBT;
try {
serializedNBT = BinaryTagIO.writeString(tag);
object.addProperty("text", serializedNBT);
hoverEvent.add("value", array);
} catch (IOException e) {
Via.getPlatform().getLogger().warning("Error writing NBT in show_item:" + text);
e.printStackTrace();
}
}
use of com.viaversion.viaversion.api.minecraft.item.Item in project ViaVersion by ViaVersion.
the class RecipeRewriter1_14 method handleStonecutting.
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.STRING);
// Ingredients
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : items) {
rewrite(item);
}
// Result
rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
Aggregations