forked from retrooper/packetevents
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wolf_variant registry and start with biome registry
Biome registry is required for wolf variant registry to fully work
- Loading branch information
Showing
21 changed files
with
2,248 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...java/com/github/retrooper/packetevents/protocol/entity/wolfvariant/StaticWolfVariant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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.wolfvariant; | ||
|
||
import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity; | ||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet; | ||
import com.github.retrooper.packetevents.protocol.world.biome.Biome; | ||
import com.github.retrooper.packetevents.resources.ResourceLocation; | ||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class StaticWolfVariant extends AbstractMappedEntity implements WolfVariant { | ||
|
||
private final ResourceLocation wildTexture; | ||
private final ResourceLocation tameTexture; | ||
private final ResourceLocation angryTexture; | ||
private final MappedEntitySet<Biome> biomes; | ||
|
||
public StaticWolfVariant( | ||
ResourceLocation wildTexture, | ||
ResourceLocation tameTexture, | ||
ResourceLocation angryTexture, | ||
MappedEntitySet<Biome> biomes | ||
) { | ||
this(null, wildTexture, tameTexture, angryTexture, biomes); | ||
} | ||
|
||
public StaticWolfVariant( | ||
@Nullable TypesBuilderData data, | ||
ResourceLocation wildTexture, | ||
ResourceLocation tameTexture, | ||
ResourceLocation angryTexture, | ||
MappedEntitySet<Biome> biomes | ||
) { | ||
super(data); | ||
this.wildTexture = wildTexture; | ||
this.tameTexture = tameTexture; | ||
this.angryTexture = angryTexture; | ||
this.biomes = biomes; | ||
} | ||
|
||
@Override | ||
public WolfVariant copy(@Nullable TypesBuilderData newData) { | ||
return new StaticWolfVariant(newData, this.wildTexture, this.tameTexture, this.angryTexture, this.biomes); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getWildTexture() { | ||
return this.wildTexture; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTameTexture() { | ||
return this.tameTexture; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getAngryTexture() { | ||
return this.angryTexture; | ||
} | ||
|
||
@Override | ||
public MappedEntitySet<Biome> getBiomes() { | ||
return this.biomes; | ||
} | ||
} |
58 changes: 53 additions & 5 deletions
58
.../main/java/com/github/retrooper/packetevents/protocol/entity/wolfvariant/WolfVariant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,62 @@ | ||
/* | ||
* 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.wolfvariant; | ||
|
||
import com.github.retrooper.packetevents.protocol.mapper.CopyableEntity; | ||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity; | ||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet; | ||
import com.github.retrooper.packetevents.protocol.nbt.NBT; | ||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound; | ||
import com.github.retrooper.packetevents.protocol.nbt.NBTString; | ||
import com.github.retrooper.packetevents.protocol.player.ClientVersion; | ||
import com.github.retrooper.packetevents.protocol.world.biome.Biome; | ||
import com.github.retrooper.packetevents.protocol.world.biome.Biomes; | ||
import com.github.retrooper.packetevents.resources.ResourceLocation; | ||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface WolfVariant extends MappedEntity, CopyableEntity<WolfVariant> { | ||
|
||
ResourceLocation getWildTexture(); | ||
|
||
import java.util.Set; | ||
ResourceLocation getTameTexture(); | ||
|
||
//TODO Finish Wolf-Variant class | ||
public class WolfVariant { | ||
private ResourceLocation wildId, tameId, angryId; | ||
ResourceLocation getAngryTexture(); | ||
|
||
public WolfVariant(ResourceLocation wildId, ResourceLocation tameId, ResourceLocation angryId) { | ||
MappedEntitySet<Biome> getBiomes(); | ||
|
||
static WolfVariant decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) { | ||
NBTCompound compound = (NBTCompound) nbt; | ||
ResourceLocation wildTexture = new ResourceLocation(compound.getStringTagValueOrThrow("wild_texture")); | ||
ResourceLocation tameTexture = new ResourceLocation(compound.getStringTagValueOrThrow("tame_texture")); | ||
ResourceLocation angryTexture = new ResourceLocation(compound.getStringTagValueOrThrow("angry_texture")); | ||
MappedEntitySet<Biome> biomes = MappedEntitySet.decode( | ||
compound.getTagOrThrow("biomes"), version, Biomes.getRegistry()); | ||
return new StaticWolfVariant(data, wildTexture, tameTexture, angryTexture, biomes); | ||
} | ||
|
||
static NBT encode(WolfVariant variant, ClientVersion version) { | ||
NBTCompound compound = new NBTCompound(); | ||
compound.setTag("wild_texture", new NBTString(variant.getWildTexture().toString())); | ||
compound.setTag("tame_texture", new NBTString(variant.getTameTexture().toString())); | ||
compound.setTag("angry_texture", new NBTString(variant.getAngryTexture().toString())); | ||
compound.setTag("biomes", MappedEntitySet.encode(variant.getBiomes(), version)); | ||
return compound; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...main/java/com/github/retrooper/packetevents/protocol/entity/wolfvariant/WolfVariants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.wolfvariant; | ||
|
||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntitySet; | ||
import com.github.retrooper.packetevents.protocol.world.biome.Biome; | ||
import com.github.retrooper.packetevents.protocol.world.biome.Biomes; | ||
import com.github.retrooper.packetevents.resources.ResourceLocation; | ||
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.Arrays; | ||
|
||
public final class WolfVariants { | ||
|
||
private static final VersionedRegistry<WolfVariant> REGISTRY = new VersionedRegistry<>( | ||
"wolf_variant", "entity/wolf_variant_mappings"); | ||
|
||
private WolfVariants() { | ||
} | ||
|
||
@ApiStatus.Internal | ||
public static WolfVariant define(String key, MappedEntitySet<Biome> biomes) { | ||
return define(key, "wolf_" + key, biomes); | ||
} | ||
|
||
@ApiStatus.Internal | ||
public static WolfVariant define(String key, String assetId, MappedEntitySet<Biome> biomes) { | ||
return define(key, ResourceLocation.minecraft("entity/wolf/" + assetId), | ||
ResourceLocation.minecraft("entity/wolf/" + assetId + "_tame"), | ||
ResourceLocation.minecraft("entity/wolf/" + assetId + "_angry"), biomes); | ||
} | ||
|
||
@ApiStatus.Internal | ||
public static WolfVariant define( | ||
String key, | ||
ResourceLocation wildTexture, | ||
ResourceLocation tameTexture, | ||
ResourceLocation angryTexture, | ||
MappedEntitySet<Biome> biomes | ||
) { | ||
return REGISTRY.define(key, data -> new StaticWolfVariant( | ||
data, wildTexture, tameTexture, angryTexture, biomes)); | ||
} | ||
|
||
public static VersionedRegistry<WolfVariant> getRegistry() { | ||
return REGISTRY; | ||
} | ||
|
||
public static final WolfVariant PALE = define("pale", "wolf", | ||
new MappedEntitySet<>(Arrays.asList(Biomes.TAIGA))); | ||
public static final WolfVariant SPOTTED = define("spotted", | ||
new MappedEntitySet<>(ResourceLocation.minecraft("is_savanna"))); | ||
public static final WolfVariant SNOWY = define("snowy", | ||
new MappedEntitySet<>(Arrays.asList(Biomes.GROVE))); | ||
public static final WolfVariant BLACK = define("black", | ||
new MappedEntitySet<>(Arrays.asList(Biomes.OLD_GROWTH_PINE_TAIGA))); | ||
public static final WolfVariant ASHEN = define("ashen", | ||
new MappedEntitySet<>(Arrays.asList(Biomes.SNOWY_TAIGA))); | ||
public static final WolfVariant RUSTY = define("rusty", | ||
new MappedEntitySet<>(ResourceLocation.minecraft("is_jungle"))); | ||
public static final WolfVariant WOODS = define("woods", | ||
new MappedEntitySet<>(Arrays.asList(Biomes.FOREST))); | ||
public static final WolfVariant CHESTNUT = define("chestnut", | ||
new MappedEntitySet<>(Arrays.asList(Biomes.OLD_GROWTH_SPRUCE_TAIGA))); | ||
public static final WolfVariant STRIPED = define("striped", | ||
new MappedEntitySet<>(ResourceLocation.minecraft("is_badlands"))); | ||
|
||
static { | ||
REGISTRY.unloadMappings(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.