Skip to content

Commit

Permalink
Fox, Llama
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 14, 2023
1 parent 19499d8 commit 1668229
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 59 deletions.
12 changes: 12 additions & 0 deletions src/main/java/xiamomc/morph/backends/server/ServerDisguise.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public ServerDisguise(EntityType type)

public boolean isBaby;

public boolean armorStandShowArms;
public boolean armorStandSmall;
public boolean armorStandNoBasePlate;

public boolean horseChested;

@Override
protected ServerDisguise clone()
{
Expand All @@ -49,6 +55,12 @@ protected ServerDisguise clone()
obj = new ServerDisguise(this.type);
}

obj.horseChested = this.horseChested;

obj.armorStandNoBasePlate = this.armorStandNoBasePlate;
obj.armorStandSmall = this.armorStandSmall;
obj.armorStandShowArms = this.armorStandShowArms;

obj.type = this.type;
obj.name = this.name;
obj.glowingColor = this.glowingColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
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.SingleWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.ArmorStandWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.GhastWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma.AbstractSlimeWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma.SlimeWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.InventoryLivingWatcher;
import xiamomc.morph.backends.server.renderer.network.registries.EntryIndex;
import xiamomc.morph.misc.DisguiseEquipment;
import xiamomc.morph.misc.DisguiseState;
Expand Down Expand Up @@ -48,21 +48,14 @@ public void mergeCompound(CompoundTag compoundTag)

if (bindingWatcher != null)
{
if (bindingWatcher instanceof AbstractSlimeWatcher slimeWatcher)
{
var size = Math.max(1, getCompound().getInt("Size"));
slimeWatcher.write(ValueIndex.SLIME_MAGMA.SIZE, size);
}

if (bindingWatcher instanceof ArmorStandWatcher armorStandWatcher)
{
this.armorStandNoBasePlate = getCompound().getBoolean("NoBasePlate");
this.armorStandSmall = getCompound().getBoolean("Small");
this.armorStandShowArms = getCompound().getBoolean("ShowArms");

var values = ValueIndex.ARMOR_STAND;
armorStandWatcher.write(values.DATA_FLAGS, getArmorStandFlags());
}
bindingWatcher.mergeFromCompound(compoundTag);

if (bindingWatcher instanceof AgeableMobWatcher)
bindingWatcher.write(ValueIndex.AGEABLE_MOB.IS_BABY, instance.isBaby);

instance.armorStandSmall = compoundTag.getBoolean("Small");
instance.armorStandNoBasePlate = compoundTag.getBoolean("NoBasePlate");
instance.armorStandShowArms = compoundTag.getBoolean("ShowArms");
}
}

Expand All @@ -72,8 +65,6 @@ public CompoundTag getCompound()
return instance.compoundTag.copy();
}

private static final UUID nilUUID = UUID.fromString("0-0-0-0-0");

/**
* Gets network id of this disguise displayed to other players
*
Expand All @@ -82,7 +73,7 @@ public CompoundTag getCompound()
@Override
public int getNetworkEntityId()
{
return -1;
return bindingPlayer.getEntityId();
}

@Nullable
Expand Down Expand Up @@ -163,10 +154,6 @@ public DisguiseWrapper<ServerDisguise> clone()
newInstance.shouldDisplayCustomEquipment = this.shouldDisplayCustomEquipment;
newInstance.setFakeEquipments(this.equipment);

newInstance.armorStandShowArms = this.armorStandShowArms;
newInstance.armorStandSmall = this.armorStandSmall;
newInstance.armorStandNoBasePlate = this.armorStandNoBasePlate;

return newInstance;
}

Expand Down Expand Up @@ -276,36 +263,20 @@ public void setAggressive(boolean aggressive)
ghastWatcher.write(ValueIndex.GHAST.CHARGING, aggressive);
}

private boolean armorStandShowArms;
private boolean armorStandSmall;
private boolean armorStandNoBasePlate;

@Override
public void setShowArms(boolean showArms)
{
super.setShowArms(showArms);

this.armorStandShowArms = showArms;
instance.armorStandShowArms = showArms;
if (bindingWatcher instanceof ArmorStandWatcher armorStandWatcher)
armorStandWatcher.write(ValueIndex.ARMOR_STAND.DATA_FLAGS, getArmorStandFlags());
}

private byte getArmorStandFlags()
{
var value = (byte)0x00;

if (armorStandSmall)
value |= (byte)0x01;

if (armorStandShowArms)
value |= (byte)0x04;

if (armorStandNoBasePlate)
value |= (byte)0x08;

return value;
{
armorStandWatcher.write(
ValueIndex.ARMOR_STAND.DATA_FLAGS,
armorStandWatcher.getArmorStandFlags(instance.armorStandSmall,
instance.armorStandShowArms, instance.armorStandNoBasePlate));
}
}

private Player bindingPlayer;

public Player getBindingPlayer()
Expand Down Expand Up @@ -337,18 +308,17 @@ private void refreshRegistry()
return;
}

bindingWatcher.mergeFromCompound(getCompound());

//todo: 激活刷新时也刷新到玩家
bindingWatcher.write(EntryIndex.PROFILE, this.instance.profile);
bindingWatcher.write(EntryIndex.DISPLAY_FAKE_EQUIPMENT, shouldDisplayCustomEquipment);
bindingWatcher.write(EntryIndex.EQUIPMENT, this.equipment);
if (bindingWatcher instanceof InventoryLivingWatcher)
{
bindingWatcher.write(EntryIndex.PROFILE, this.instance.profile);
bindingWatcher.write(EntryIndex.DISPLAY_FAKE_EQUIPMENT, shouldDisplayCustomEquipment);
bindingWatcher.write(EntryIndex.EQUIPMENT, this.equipment);
}

if (bindingWatcher instanceof GhastWatcher ghastWatcher)
ghastWatcher.write(ValueIndex.GHAST.CHARGING, aggressive);

if (bindingWatcher instanceof ArmorStandWatcher armorStandWatcher)
armorStandWatcher.write(ValueIndex.ARMOR_STAND.DATA_FLAGS, getArmorStandFlags());

if (bindingWatcher instanceof AbstractSlimeWatcher slimeWatcher)
slimeWatcher.write(ValueIndex.SLIME_MAGMA.SIZE, getSlimeSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ValueIndex
{
public static final EntityValues BASE_ENTITY = new EntityValues();
public static final LivingEntityValues BASE_LIVING = new LivingEntityValues();
public static final AgeableMobValues AGEABLE_MOB = new AgeableMobValues();

public static final ArmorStandValues ARMOR_STAND = new ArmorStandValues();
public static final AllayValues ALLAY = new AllayValues();
Expand All @@ -15,4 +16,7 @@ public class ValueIndex
public static final GhastValues GHAST = new GhastValues();
public static final AbstractHorseValues ABSTRACT_HORSE = new AbstractHorseValues();
public static final HorseValues HORSE = new HorseValues();
public static final ChestedHorseValues CHESTED_HORSE = new ChestedHorseValues();
public static final LlamaValues LLAMA = new LlamaValues();
public static final FoxValues FOX = new FoxValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses.HorseWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses.SkeletonHorseWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses.ZombieHorseWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.llama.LlamaWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.llama.TraderLlamaWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma.MagmaWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma.SlimeWatcher;

Expand Down Expand Up @@ -41,6 +43,11 @@ public WatcherIndex()
setTypeWatcher(EntityType.ZOMBIE_HORSE, ZombieHorseWatcher::new);

setTypeWatcher(EntityType.CAMEL, p -> new AbstractHorseWatcher(p, EntityType.CAMEL));

setTypeWatcher(EntityType.LLAMA, LlamaWatcher::new);
setTypeWatcher(EntityType.TRADER_LLAMA, TraderLlamaWatcher::new);

setTypeWatcher(EntityType.FOX, FoxWatcher::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,5 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.values;

public class AnimalValues extends AgeableMobValues
{
}
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 ChestedHorseValues extends AbstractHorseValues
{
public final SingleValue<Boolean> HAS_CHEST = getSingle(false);

public ChestedHorseValues()
{
super();

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

import java.util.UUID;

public class FoxValues extends AnimalValues
{
public final SingleValue<Integer> VARIANT = getSingle(0);
public final SingleValue<Byte> FLAGS = getSingle((byte)0);
public final SingleValue<UUID> TRUSTED_ID_0 = getSingle(UUID.randomUUID());
public final SingleValue<UUID> TRUSTED_ID_1 = getSingle(UUID.randomUUID());

public FoxValues()
{
super();

registerSingle(VARIANT, FLAGS);
}
}
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 LlamaValues extends ChestedHorseValues
{
public final SingleValue<Integer> SLOTS = getSingle(0);
public final SingleValue<Integer> CARPET_COLOR = getSingle(-1);
public final SingleValue<Integer> VARIANT = getSingle(0);

public LlamaValues()
{
super();

registerSingle(SLOTS, CARPET_COLOR, VARIANT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers;

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;

public class AgeableMobWatcher extends LivingEntityWatcher
{
public AgeableMobWatcher(Player bindingPlayer, EntityType entityType)
{
super(bindingPlayer, entityType);
}

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

register(ValueIndex.AGEABLE_MOB);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.GameType;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -231,6 +232,10 @@ protected void doSync()
{
}

public void mergeFromCompound(CompoundTag nbt)
{
}

//region Networking

//endregion Networking
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.PacketFactory;
Expand All @@ -23,9 +24,31 @@ public ArmorStandWatcher(Player bindingPlayer)
super(bindingPlayer, EntityType.ARMOR_STAND);
}


public byte getArmorStandFlags(boolean small, boolean showArms, boolean noBasePlate)
{
var value = (byte)0x00;

if (small)
value |= (byte)0x01;

if (showArms)
value |= (byte)0x04;

if (noBasePlate)
value |= (byte)0x08;

return value;
}

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

var small = nbt.getBoolean("Small");
var noBasePlate = nbt.getBoolean("NoBasePlate");
var showArms = nbt.getBoolean("ShowArms");
write(ValueIndex.ARMOR_STAND.DATA_FLAGS, getArmorStandFlags(small, showArms, noBasePlate));
}
}
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.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.AgeableMobWatcher;

public class FoxWatcher extends AgeableMobWatcher
{
@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.FOX);
}

public FoxWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.FOX);
}

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

var isSnow = nbt.getString("Type").equalsIgnoreCase("SNOW");
write(ValueIndex.FOX.VARIANT, isSnow ? 1 : 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
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;

public class AbstractHorseWatcher extends LivingEntityWatcher
public class AbstractHorseWatcher extends AgeableMobWatcher
{
@Override
protected void initRegistry()
Expand Down
Loading

0 comments on commit 1668229

Please sign in to comment.