Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper 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.github.retrooper.packetevents.protocol.entity.cat;

import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

public interface CatVariant extends MappedEntity {

ResourceLocation getTexture();

static CatVariant read(PacketWrapper<?> wrapper) {
return wrapper.readMappedEntity(CatVariants.getRegistry());
}

static void write(PacketWrapper<?> wrapper, CatVariant variant) {
wrapper.writeMappedEntity(variant);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper 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.github.retrooper.packetevents.protocol.entity.cat;

import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;

public class CatVariantImpl extends AbstractMappedEntity implements CatVariant {

private final ResourceLocation texture;

public CatVariantImpl(TypesBuilderData data, ResourceLocation texture) {
super(data);
this.texture = texture;
}

@Override
public ResourceLocation getTexture() {
return this.texture;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper 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.github.retrooper.packetevents.protocol.entity.cat;

import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry;

public final class CatVariants {

private static final VersionedRegistry<CatVariant> REGISTRY = new VersionedRegistry<>(
"cat_variant", "entity/cat_variant_mappings");

public static final CatVariant TABBY = define("tabby");
public static final CatVariant BLACK = define("black");
public static final CatVariant RED = define("red");
public static final CatVariant SIAMESE = define("siamese");
public static final CatVariant BRITISH_SHORTHAIR = define("british_shorthair");
public static final CatVariant CALICO = define("calico");
public static final CatVariant PERSIAN = define("persian");
public static final CatVariant RAGDOLL = define("ragdoll");
public static final CatVariant WHITE = define("white");
public static final CatVariant JELLIE = define("jellie");
public static final CatVariant ALL_BLACK = define("all_black");

private CatVariants() {
}

private static CatVariant define(String name) {
return define(name, ResourceLocation.minecraft("textures/entity/cat/" + name + ".png"));
}

private static CatVariant define(String name, ResourceLocation texture) {
return REGISTRY.define(name, data -> new CatVariantImpl(data, texture));
}

public static VersionedRegistry<CatVariant> getRegistry() {
return REGISTRY;
}

static {
REGISTRY.unloadMappings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.github.retrooper.packetevents.protocol.entity.data;

@Deprecated
public class EntityData {
private int index;
private EntityDataType<?> type;
Expand Down Expand Up @@ -52,4 +53,4 @@ public Object getValue() {
public void setValue(Object value) {
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,29 @@
import java.util.function.BiConsumer;
import java.util.function.Function;

public class EntityDataType<T> {
private final String name;
private final int[] ids;
private final Function<PacketWrapper<?>, T> dataDeserializer;
private final BiConsumer<PacketWrapper<?>, Object> dataSerializer;

public EntityDataType(String name, int[] ids, Function<PacketWrapper<?>, T> dataDeserializer, BiConsumer<PacketWrapper<?>, Object> dataSerializer) {
this.name = name;
this.ids = ids;
this.dataDeserializer = dataDeserializer;
this.dataSerializer = dataSerializer;
@Deprecated
public final class EntityDataType<T> {

private final IEntityDataType<T> delegate;

EntityDataType(IEntityDataType<T> delegate) {
this.delegate = delegate;
}

public String getName() {
return name;
return this.delegate.getName().toString();
}

public int getId(ClientVersion version) {
int index = EntityDataTypes.TYPES_BUILDER.getDataIndex(version);
return ids[index];
return this.delegate.getId(version);
}

public Function<PacketWrapper<?>, T> getDataDeserializer() {
return dataDeserializer;
return this.delegate::deserialize;
}

@SuppressWarnings("unchecked")
public BiConsumer<PacketWrapper<?>, Object> getDataSerializer() {
return dataSerializer;
return (wrapper, value) -> this.delegate.serialize(wrapper, (T) value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of packetevents - https://github.com/retrooper/packetevents
* Copyright (C) 2024 retrooper 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.github.retrooper.packetevents.protocol.entity.data;

import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity;
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

import java.util.function.Function;

public class EntityDataTypeImpl<T> extends AbstractMappedEntity implements IEntityDataType<T> {

@Deprecated
private final EntityDataType<T> legacy;

private final PacketWrapper.Reader<T> reader;
private final PacketWrapper.Writer<T> writer;

@SuppressWarnings("deprecation")
public EntityDataTypeImpl(
TypesBuilderData data,
PacketWrapper.Reader<T> reader,
PacketWrapper.Writer<T> writer
) {
super(data);
this.legacy = new EntityDataType<>(this);
this.reader = reader;
this.writer = writer;
}

@Override
public T deserialize(PacketWrapper<?> wrapper) {
return this.reader.apply(wrapper);
}

@Override
public void serialize(PacketWrapper<?> wrapper, T value) {
this.writer.accept(wrapper, value);
}

@Override
public <Z> IEntityDataType<Z> map(Function<T, Z> processor, Function<Z, T> unprocessor) {
return new EntityDataTypeImpl<>(this.data,
wrapper -> processor.apply(this.reader.apply(wrapper)),
(wrapper, value) -> this.writer.accept(wrapper, unprocessor.apply(value)));
}

@Deprecated
@Override
public EntityDataType<T> asLegacy() {
return this.legacy;
}
}
Loading