Skip to content

Commit

Permalink
Frog, TropicalFish, Panda, Rabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 15, 2023
1 parent ca41a17 commit f9b6922
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import xiamomc.morph.MorphPlugin;
import xiamomc.morph.backends.DisguiseWrapper;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.AgeableMobWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.AgeableMobWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.ArmorStandWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.GhastWatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public class ValueIndex
public static final ParrotValues PARROT = new ParrotValues();
public static final CatValues CAT = new CatValues();
public static final GoatValues GOAT = new GoatValues();
public static final TropicalFishValues TROPICAL = new TropicalFishValues();
public static final RabbitValues RABBIT = new RabbitValues();
public static final FrogValues FROG = new FrogValues();
public static final PandaValues PANDA = new PandaValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.GoatWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.GoatWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.*;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses.AbstractHorseWatcher;
Expand Down Expand Up @@ -52,6 +52,11 @@ public WatcherIndex()
setTypeWatcher(EntityType.PARROT, ParrotWatcher::new);
setTypeWatcher(EntityType.CAT, CatWatcher::new);
setTypeWatcher(EntityType.GOAT, GoatWatcher::new);

setTypeWatcher(EntityType.RABBIT, RabbitWatcher::new);
setTypeWatcher(EntityType.TROPICAL_FISH, TropicalFishWatcher::new);
setTypeWatcher(EntityType.FROG, FrogWatcher::new);
setTypeWatcher(EntityType.PANDA, PandaWatcher::new);
}

private void setTypeWatcher(EntityType type, Function<Player, SingleWatcher> func)
Expand Down
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 AbstractFishValues extends WaterAnimalValues
{
public final SingleValue<Boolean> FROM_BUCKET = getSingle(false);

public AbstractFishValues()
{
super();

registerSingle(FROM_BUCKET);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.values;

import net.minecraft.world.entity.animal.FrogVariant;

public class FrogValues extends AnimalValues
{
public final SingleValue<FrogVariant> FROG_VARIANT = getSingle(FrogVariant.TEMPERATE).withRandom(FrogVariant.TEMPERATE, FrogVariant.COLD, FrogVariant.WARM);

public FrogValues()
{
super();

registerSingle(FROG_VARIANT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.values;

public class PandaValues extends AnimalValues
{
public final SingleValue<Integer> BREED_TIMER = getSingle(0);
public final SingleValue<Integer> SNEEZE_TIMER = getSingle(0);
public final SingleValue<Integer> EAT_TIMER = getSingle(0);
public final SingleValue<Byte> MAIN_GENE = getSingle((byte)0);
public final SingleValue<Byte> HIDDEN_GENE = getSingle((byte)0);
public final SingleValue<Byte> FLAGS = getSingle((byte)0);

public PandaValues()
{
super();

registerSingle(BREED_TIMER, SNEEZE_TIMER, EAT_TIMER, MAIN_GENE, HIDDEN_GENE, FLAGS);
}
}
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 RabbitValues extends AnimalValues
{
public final SingleValue<Integer> RABBIT_TYPE = getSingle(0);

public RabbitValues()
{
super();

registerSingle(RABBIT_TYPE);
}
}
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 TropicalFishValues extends AbstractFishValues
{
public final SingleValue<Integer> FISH_VARIANT = getSingle(0);

public TropicalFishValues()
{
super();

registerSingle(FISH_VARIANT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.values;

public class WaterAnimalValues extends MobValues
{
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers;
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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.AgeableMobWatcher;

public class FoxWatcher extends AgeableMobWatcher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import net.minecraft.core.registries.BuiltInRegistries;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Frog;
import org.bukkit.entity.Player;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;

import java.util.Arrays;

public class FrogWatcher extends LivingEntityWatcher
{
public FrogWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.FROG);
}

public Frog.Variant getFrogVariant()
{
var index = BuiltInRegistries.FROG_VARIANT.getId(get(ValueIndex.FROG.FROG_VARIANT));

return Arrays.stream(Frog.Variant.values()).toList().get(index);
}

@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.FROG);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers;
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import net.minecraft.nbt.CompoundTag;
import org.bukkit.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import org.bukkit.entity.EntityType;
import org.bukkit.entity.Panda;
import org.bukkit.entity.Player;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;
import xiamomc.morph.backends.server.renderer.network.datawatcher.values.PandaValues;

import java.util.Arrays;
import java.util.Random;

public class PandaWatcher extends LivingEntityWatcher
{
public PandaWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.PANDA);
}

@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.PANDA);
}

public Panda.Gene getMainGene()
{
return Arrays.stream(Panda.Gene.values()).toList().get(get(ValueIndex.PANDA.MAIN_GENE));
}

public Panda.Gene getHiddenGene()
{
return Arrays.stream(Panda.Gene.values()).toList().get(get(ValueIndex.PANDA.HIDDEN_GENE));
}

@Override
protected void initValues()
{
super.initValues();

var availableValues = Arrays.stream(Panda.Gene.values()).toList();
var random = new Random();
var mainGene = availableValues.get(random.nextInt(availableValues.size()));
var hiddenGene = availableValues.get(random.nextInt(availableValues.size()));

write(ValueIndex.PANDA.MAIN_GENE, (byte)mainGene.ordinal());
write(ValueIndex.PANDA.HIDDEN_GENE, (byte)hiddenGene.ordinal());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;

import java.util.Arrays;
import java.util.Random;

public class RabbitWatcher extends LivingEntityWatcher
{
public RabbitWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.RABBIT);
}

@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.RABBIT);
}

public Rabbit.Type getType()
{
return Arrays.stream(Rabbit.Type.values()).toList().get(get(ValueIndex.RABBIT.RABBIT_TYPE));
}

@Override
protected void initValues()
{
super.initValues();

var availableTypes = Arrays.stream(Rabbit.Type.values()).toList();
var random = new Random();

var targetValue = availableTypes.get(random.nextInt(availableTypes.size()));
write(ValueIndex.RABBIT.RABBIT_TYPE, targetValue.ordinal());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;

import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;

public class TropicalFishWatcher extends LivingEntityWatcher
{
public TropicalFishWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.TROPICAL_FISH);
}

@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.TROPICAL);
}

@Override
protected void initValues()
{
super.initValues();

//todo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
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.AgeableMobWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.LivingEntityWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.AgeableMobWatcher;

public class AbstractHorseWatcher extends AgeableMobWatcher
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.CatWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.FrogWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.PandaWatcher;

public class WatcherUtils
{
Expand Down Expand Up @@ -36,33 +38,30 @@ public static CompoundTag buildCompoundFromWatcher(SingleWatcher watcher)
tag.putString("variant", variant);
}

/*
case TROPICAL_FISH ->
{
var variant = ((TropicalFishWatcher) watcher).getVariant();
var variant = watcher.get(ValueIndex.TROPICAL.FISH_VARIANT);

compoundTag.putInt("Variant", variant);
tag.putInt("Variant", variant);
}

case RABBIT ->
{
var type = ((RabbitWatcher) watcher).getType().getTypeId();
compoundTag.putInt("RabbitType", type);
var type = watcher.get(ValueIndex.RABBIT.RABBIT_TYPE);
tag.putInt("RabbitType", type);
}
*/

case FOX ->
{
var foxType = watcher.get(ValueIndex.FOX.FOX_VARIANT) == 0 ? "red" : "snow";
tag.putString("Type", foxType);
}
/*

case FROG ->
{
var variant = ((FrogWatcher) watcher).getVariant().getKey().asString();
compoundTag.putString("variant", variant);
var variant = ((FrogWatcher)watcher).getFrogVariant().getKey().asString();
tag.putString("variant", variant);
}
*/

case GOAT ->
{
Expand All @@ -71,17 +70,17 @@ public static CompoundTag buildCompoundFromWatcher(SingleWatcher watcher)
tag.putBoolean("IsScreamingGoat", watcher.get(ValueIndex.GOAT.IS_SCREAMING));
}

/*
case PANDA ->
{
var pandaWatcher = ((PandaWatcher) watcher);
var pandaWatcher = (PandaWatcher)watcher;
var mainGene = pandaWatcher.getMainGene();
var hiddenGene = pandaWatcher.getHiddenGene();

compoundTag.putString("MainGene", mainGene.toString().toLowerCase());
compoundTag.putString("HiddenGene", hiddenGene.toString().toLowerCase());
tag.putString("MainGene", mainGene.toString().toLowerCase());
tag.putString("HiddenGene", hiddenGene.toString().toLowerCase());
}

/*
case VILLAGER ->
{
if (!compoundTag.contains("VillagerData"))
Expand Down

0 comments on commit f9b6922

Please sign in to comment.