-
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.
- Loading branch information
1 parent
fabdd50
commit ca41a17
Showing
16 changed files
with
327 additions
and
40 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
20 changes: 20 additions & 0 deletions
20
...ain/java/xiamomc/morph/backends/server/renderer/network/datawatcher/values/CatValues.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,20 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.values; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.entity.animal.CatVariant; | ||
import org.bukkit.entity.Cat; | ||
|
||
public class CatValues extends TameableAnimalValues | ||
{ | ||
public final SingleValue<CatVariant> CAT_VARIANT = getSingle(BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.TABBY)); | ||
public final SingleValue<Boolean> IS_LYING = getSingle(false); | ||
public final SingleValue<Boolean> RELAXED = getSingle(false); | ||
public final SingleValue<Integer> COLLAR_COLOR = getSingle(14); | ||
|
||
public CatValues() | ||
{ | ||
super(); | ||
|
||
registerSingle(CAT_VARIANT, IS_LYING, RELAXED, COLLAR_COLOR); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...in/java/xiamomc/morph/backends/server/renderer/network/datawatcher/values/GoatValues.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,15 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.values; | ||
|
||
public class GoatValues extends AnimalValues | ||
{ | ||
public final SingleValue<Boolean> IS_SCREAMING = getSingle(false); | ||
public final SingleValue<Boolean> HAS_LEFT_HORN = getSingle(true); | ||
public final SingleValue<Boolean> HAS_RIGHT_HORN = getSingle(true); | ||
|
||
public GoatValues() | ||
{ | ||
super(); | ||
|
||
registerSingle(IS_SCREAMING, HAS_LEFT_HORN, HAS_RIGHT_HORN); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
.../java/xiamomc/morph/backends/server/renderer/network/datawatcher/values/ParrotValues.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,13 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.values; | ||
|
||
public class ParrotValues extends TameableAnimalValues | ||
{ | ||
public final SingleValue<Integer> PARROT_VARIANT = getSingle(0).withRandom(0, 1, 2, 3, 4); | ||
|
||
public ParrotValues() | ||
{ | ||
super(); | ||
|
||
registerSingle(PARROT_VARIANT); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...amomc/morph/backends/server/renderer/network/datawatcher/values/TameableAnimalValues.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,16 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.values; | ||
|
||
import java.util.UUID; | ||
|
||
public class TameableAnimalValues extends AnimalValues | ||
{ | ||
public final SingleValue<Byte> TAMEABLE_FLAGS = getSingle((byte)0); | ||
public final SingleValue<UUID> OWNER = getSingle(UUID.randomUUID()); | ||
|
||
public TameableAnimalValues() | ||
{ | ||
super(); | ||
|
||
registerSingle(TAMEABLE_FLAGS, OWNER); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...java/xiamomc/morph/backends/server/renderer/network/datawatcher/watchers/GoatWatcher.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,54 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Player; | ||
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex; | ||
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.LivingEntityWatcher; | ||
|
||
import java.util.Random; | ||
|
||
public class GoatWatcher extends LivingEntityWatcher | ||
{ | ||
public GoatWatcher(Player bindingPlayer) | ||
{ | ||
super(bindingPlayer, EntityType.GOAT); | ||
} | ||
|
||
@Override | ||
protected void initRegistry() | ||
{ | ||
super.initRegistry(); | ||
|
||
register(ValueIndex.GOAT); | ||
} | ||
|
||
@Override | ||
protected void initValues() | ||
{ | ||
super.initValues(); | ||
|
||
var random = new Random(); | ||
|
||
if (random.nextInt(0, 100) <= 15) | ||
write(ValueIndex.GOAT.HAS_LEFT_HORN, false); | ||
|
||
if (random.nextInt(0, 100) <= 15) | ||
write(ValueIndex.GOAT.HAS_RIGHT_HORN, false); | ||
} | ||
|
||
@Override | ||
public void mergeFromCompound(CompoundTag nbt) | ||
{ | ||
super.mergeFromCompound(nbt); | ||
|
||
if (nbt.contains("HasLeftHorn")) | ||
write(ValueIndex.GOAT.HAS_LEFT_HORN, nbt.getBoolean("HasLeftHorn")); | ||
|
||
if (nbt.contains("HasRightHorn")) | ||
write(ValueIndex.GOAT.HAS_RIGHT_HORN, nbt.getBoolean("HasRightHorn")); | ||
|
||
if (nbt.contains("IsScreamingGoat")) | ||
write(ValueIndex.GOAT.IS_SCREAMING, nbt.getBoolean("IsScreamingGoat")); | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...xiamomc/morph/backends/server/renderer/network/datawatcher/watchers/types/CatWatcher.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,79 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.animal.CatVariant; | ||
import org.bukkit.entity.Cat; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Player; | ||
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex; | ||
|
||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
public class CatWatcher extends LivingEntityWatcher | ||
{ | ||
public CatWatcher(Player bindingPlayer) | ||
{ | ||
super(bindingPlayer, EntityType.CAT); | ||
} | ||
|
||
@Override | ||
protected void initRegistry() | ||
{ | ||
super.initRegistry(); | ||
|
||
register(ValueIndex.CAT); | ||
} | ||
|
||
public Cat.Type getCatType() | ||
{ | ||
var value = get(ValueIndex.CAT.CAT_VARIANT); | ||
var index = BuiltInRegistries.CAT_VARIANT.getId(value); | ||
|
||
return Cat.Type.values()[index]; | ||
} | ||
|
||
@Override | ||
protected void initValues() | ||
{ | ||
super.initValues(); | ||
|
||
var random = new Random(); | ||
var availableVariants = Arrays.stream(Cat.Type.values()).toList(); | ||
var targetIndex = random.nextInt(availableVariants.size()); | ||
var targetValue = bukkitTypeToNms(availableVariants.get(targetIndex)); | ||
|
||
logger.info("Write value " + targetValue); | ||
this.write(ValueIndex.CAT.CAT_VARIANT, targetValue); | ||
logger.info("Get value :" + getCatType()); | ||
} | ||
|
||
private CatVariant bukkitTypeToNms(Cat.Type bukkitType) | ||
{ | ||
var bukkitKey = bukkitType.getKey(); | ||
ResourceLocation key = new ResourceLocation(bukkitKey.namespace(), bukkitKey.getKey()); | ||
return BuiltInRegistries.CAT_VARIANT.get(key); | ||
} | ||
|
||
@Override | ||
public void mergeFromCompound(CompoundTag nbt) | ||
{ | ||
super.mergeFromCompound(nbt); | ||
|
||
if (nbt.contains("variant")) | ||
{ | ||
var name = nbt.getString("variant"); | ||
var match = Arrays.stream(Cat.Type.values()) | ||
.filter(t -> t.name().equalsIgnoreCase(name)) | ||
.findFirst(); | ||
|
||
match.ifPresent(type -> | ||
{ | ||
var finalValue = bukkitTypeToNms(type); | ||
this.write(ValueIndex.CAT.CAT_VARIANT, finalValue); | ||
}); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...momc/morph/backends/server/renderer/network/datawatcher/watchers/types/ParrotWatcher.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,34 @@ | ||
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Player; | ||
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex; | ||
|
||
public class ParrotWatcher extends LivingEntityWatcher | ||
{ | ||
public ParrotWatcher(Player bindingPlayer) | ||
{ | ||
super(bindingPlayer, EntityType.PARROT); | ||
} | ||
|
||
@Override | ||
protected void initRegistry() | ||
{ | ||
super.initRegistry(); | ||
|
||
register(ValueIndex.PARROT); | ||
} | ||
|
||
@Override | ||
public void mergeFromCompound(CompoundTag nbt) | ||
{ | ||
super.mergeFromCompound(nbt); | ||
|
||
if (nbt.contains("Variant")) | ||
{ | ||
var variant = nbt.getInt("Variant"); | ||
this.write(ValueIndex.PARROT.PARROT_VARIANT, variant); | ||
} | ||
} | ||
} |
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.