Skip to content

Commit

Permalink
Mooshroom, Sheep, Wolf, Phantom
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 16, 2023
1 parent d162243 commit 87af05b
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public class ValueIndex
public static final ZoglinValues ZOGLIN = new ZoglinValues();
public static final GuardianValues GUARDIAN = new GuardianValues();
public static final AxolotlValues AXOLOTL = new AxolotlValues();
public static final MooshroomValues MOOSHROOM = new MooshroomValues();
public static final SheepValues SHEEP = new SheepValues();
public static final WolfValues WOLF = new WolfValues();
public static final PhantomValues PHANTOM = new PhantomValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public WatcherIndex()
setTypeWatcher(EntityType.GUARDIAN, GuardianWatcher::new);

setTypeWatcher(EntityType.AXOLOTL, AxolotlWatcher::new);

setTypeWatcher(EntityType.MUSHROOM_COW, MooshroomWatcher::new);
setTypeWatcher(EntityType.SHEEP, SheepWatcher::new);

setTypeWatcher(EntityType.WOLF, WolfWatcher::new);
setTypeWatcher(EntityType.PHANTOM, PhantomWatcher::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,17 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.values;

import xiamomc.morph.backends.server.renderer.network.datawatcher.values.basetypes.AnimalValues;

public class MooshroomValues extends AnimalValues
{
public final SingleValue<String> VARIANT = getSingle(RED).withRandom(RED, RED, RED, BROWN);
public static final String RED = "red";
public static final String BROWN = "brown";

public MooshroomValues()
{
super();

registerSingle(VARIANT);
}
}
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 PhantomValues extends MobValues
{
public final SingleValue<Integer> SIZE = getSingle(0);

public PhantomValues()
{
super();

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

import net.minecraft.nbt.CompoundTag;
import xiamomc.morph.backends.server.renderer.network.datawatcher.values.basetypes.LivingEntityValues;

public class PlayerValues extends LivingEntityValues
Expand All @@ -8,13 +9,13 @@ public class PlayerValues extends LivingEntityValues
public final SingleValue<Integer> SCORE = getSingle(0);
public final SingleValue<Byte> SKIN_FLAGS = getSingle((byte)0); //127
public final SingleValue<Byte> MAINHAND = getSingle((byte)1);
public final SingleValue<Object> LEFT_SHOULDER_PARROT_COMPOUND = getSingle(new Object());
public final SingleValue<Object> RIGHT_SHOULDER_PARROT_COMPOUND = getSingle(new Object());
public final SingleValue<CompoundTag> LEFT_SHOULDER_PARROT_COMPOUND = getSingle(new CompoundTag());
public final SingleValue<CompoundTag> RIGHT_SHOULDER_PARROT_COMPOUND = getSingle(new CompoundTag());

public PlayerValues()
{
super();

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

import xiamomc.morph.backends.server.renderer.network.datawatcher.values.basetypes.AnimalValues;

public class SheepValues extends AnimalValues
{
public final SingleValue<Byte> WOOL_TYPE = getSingle((byte)0);

public SheepValues()
{
super();

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

import xiamomc.morph.backends.server.renderer.network.datawatcher.values.basetypes.TameableAnimalValues;

public class WolfValues extends TameableAnimalValues
{
public final SingleValue<Boolean> BEGGING = getSingle(false);
public final SingleValue<Integer> COLLAR_COLOR = getSingle(14);
public final SingleValue<Integer> ANGER_TIME = getSingle(0);

public WolfValues()
{
super();

registerSingle(BEGGING, COLLAR_COLOR, ANGER_TIME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Arrays;
import java.util.Random;

public class CatWatcher extends LivingEntityWatcher
public class CatWatcher extends TameableAnimalWatcher
{
public CatWatcher(Player bindingPlayer)
{
Expand Down Expand Up @@ -45,9 +45,7 @@ protected void initValues()
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 MooshroomWatcher extends LivingEntityWatcher
{
public MooshroomWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.MUSHROOM_COW);
}

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

register(ValueIndex.MOOSHROOM);
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("Type"))
write(ValueIndex.MOOSHROOM.VARIANT, nbt.getString("Type"));
}

@Override
public void writeToCompound(CompoundTag nbt)
{
super.writeToCompound(nbt);

nbt.putString("Type", get(ValueIndex.MOOSHROOM.VARIANT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.entity.Player;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;

public class ParrotWatcher extends LivingEntityWatcher
public class ParrotWatcher extends TameableAnimalWatcher
{
public ParrotWatcher(Player bindingPlayer)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 PhantomWatcher extends LivingEntityWatcher
{
public PhantomWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.PHANTOM);
}

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

register(ValueIndex.PHANTOM);
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("Size"))
write(ValueIndex.PHANTOM.SIZE, nbt.getInt("Size"));
}

@Override
public void writeToCompound(CompoundTag nbt)
{
super.writeToCompound(nbt);

nbt.putInt("Size", get(ValueIndex.PHANTOM.SIZE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 SheepWatcher extends LivingEntityWatcher
{
public SheepWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.SHEEP);
}

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

register(ValueIndex.SHEEP);
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("Color"))
write(ValueIndex.SHEEP.WOOL_TYPE, nbt.getByte("Color"));
}

@Override
public void writeToCompound(CompoundTag nbt)
{
super.writeToCompound(nbt);

nbt.putByte("Color", get(ValueIndex.SHEEP.WOOL_TYPE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 TameableAnimalWatcher extends LivingEntityWatcher
{
protected TameableAnimalWatcher(Player bindingPlayer, EntityType entityType)
{
super(bindingPlayer, entityType);
}

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

register(ValueIndex.TAMEABLE);
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("Owner"))
{
write(ValueIndex.TAMEABLE.OWNER, nbt.getUUID("Owner"));

byte val = get(ValueIndex.TAMEABLE.TAMEABLE_FLAGS);
write(ValueIndex.TAMEABLE.TAMEABLE_FLAGS, (byte)(val | 0x04));
}

if (nbt.contains("Sitting"))
{
byte val = get(ValueIndex.TAMEABLE.TAMEABLE_FLAGS);

write(ValueIndex.TAMEABLE.TAMEABLE_FLAGS, (byte)(val | 0x01));
}
}

@Override
public void writeToCompound(CompoundTag nbt)
{
super.writeToCompound(nbt);

var flag = get(ValueIndex.TAMEABLE.TAMEABLE_FLAGS);
nbt.putBoolean("Sitting", (flag & 0x01) == 0x01);
nbt.putUUID("Owner", get(ValueIndex.TAMEABLE.OWNER));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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 org.bukkit.entity.TropicalFish;
import xiamomc.morph.backends.server.renderer.network.datawatcher.ValueIndex;

import java.util.Arrays;

public class TropicalFishWatcher extends LivingEntityWatcher
{
public TropicalFishWatcher(Player bindingPlayer)
Expand All @@ -23,7 +27,28 @@ protected void initRegistry()
protected void initValues()
{
super.initValues();
/*
var patterns = TropicalFish.Pattern.values();
Arrays.stream(patterns).findAny().get();
*/

//todo
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("Variant"))
write(ValueIndex.TROPICAL.FISH_VARIANT, nbt.getInt("Variant"));
}

@Override
public void writeToCompound(CompoundTag nbt)
{
super.writeToCompound(nbt);

nbt.putInt("Variant", get(ValueIndex.TROPICAL.FISH_VARIANT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 WolfWatcher extends TameableAnimalWatcher
{
public WolfWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.WOLF);
}

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

register(ValueIndex.WOLF);
}

@Override
public void mergeFromCompound(CompoundTag nbt)
{
super.mergeFromCompound(nbt);

if (nbt.contains("CollarColor"))
write(ValueIndex.WOLF.COLLAR_COLOR, (int)nbt.getByte("CollarColor"));
}

@Override
public void writeToCompound(CompoundTag nbt)
{
super.writeToCompound(nbt);

nbt.putByte("CollarColor", get(ValueIndex.WOLF.COLLAR_COLOR).byteValue());
}
}

0 comments on commit 87af05b

Please sign in to comment.