Skip to content

Commit

Permalink
Horses, SlimeMagma
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 14, 2023
1 parent 479faa0 commit b20f9c3
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/main/java/xiamomc/morph/backends/DisguiseWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ else if (getEntityType() == EntityType.ITEM_DISPLAY)

if (getEntityType() != EntityType.SLIME && getEntityType() != EntityType.MAGMA_CUBE) return;

var dimScale = getSlimeDimensionScale();
var dimScale = getSlimeSize();
this.dimensions = EntityDimensions.fixed(0.51F * dimScale, 0.51F * dimScale);
}

Expand All @@ -203,7 +203,7 @@ public EntityDimensions getDimensions()

public abstract boolean isBaby();

protected float getSlimeDimensionScale()
protected int getSlimeSize()
{
return Math.max(1, getCompound().getInt("Size"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public boolean isDisguised(@org.jetbrains.annotations.Nullable Entity target)
@Override
public boolean disguise(Player player, DisguiseWrapper<?> wrapper)
{
logger.info("Incoming wrapper is " + wrapper);
if (!(wrapper instanceof ServerDisguiseWrapper serverDisguiseWrapper)) return false;
if (disguiseWrapperMap.containsKey(player.getUniqueId()))
unDisguise(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
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.SlimeWatcher;
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.registries.EntryIndex;
import xiamomc.morph.misc.DisguiseEquipment;
import xiamomc.morph.misc.DisguiseState;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void mergeCompound(CompoundTag compoundTag)

if (bindingWatcher != null)
{
if (bindingWatcher instanceof SlimeWatcher slimeWatcher)
if (bindingWatcher instanceof AbstractSlimeWatcher slimeWatcher)
{
var size = Math.max(1, getCompound().getInt("Size"));
slimeWatcher.write(ValueIndex.SLIME_MAGMA.SIZE, size);
Expand Down Expand Up @@ -346,5 +347,8 @@ private void refreshRegistry()

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
@@ -1,5 +1,6 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher;

import org.checkerframework.checker.units.qual.A;
import xiamomc.morph.backends.server.renderer.network.datawatcher.values.*;

public class ValueIndex
Expand All @@ -12,4 +13,6 @@ public class ValueIndex
public static final PlayerValues PLAYER = new PlayerValues();
public static final SlimeValues SLIME_MAGMA = new SlimeValues();
public static final GhastValues GHAST = new GhastValues();
public static final AbstractHorseValues ABSTRACT_HORSE = new AbstractHorseValues();
public static final HorseValues HORSE = new HorseValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
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.values.ArmorStandValues;
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;
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.slimemagma.MagmaWatcher;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma.SlimeWatcher;

import java.util.Map;
import java.util.function.Function;
Expand All @@ -30,6 +35,12 @@ public WatcherIndex()
setTypeWatcher(EntityType.SLIME, SlimeWatcher::new);
setTypeWatcher(EntityType.MAGMA_CUBE, MagmaWatcher::new);
setTypeWatcher(EntityType.GHAST, GhastWatcher::new);

setTypeWatcher(EntityType.HORSE, HorseWatcher::new);
setTypeWatcher(EntityType.SKELETON_HORSE, SkeletonHorseWatcher::new);
setTypeWatcher(EntityType.ZOMBIE_HORSE, ZombieHorseWatcher::new);

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

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 AbstractHorseValues extends AgeableMobValues
{
public final SingleValue<Byte> FLAGS = getSingle((byte)0);

public AbstractHorseValues()
{
super();

registerSingle(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 AgeableMobValues extends MobValues
{
public final SingleValue<Boolean> IS_BABY = getSingle(false);

public AgeableMobValues()
{
super();

registerSingle(IS_BABY);
}
}
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 HorseValues extends AbstractHorseValues
{
public final SingleValue<Integer> VARIANT = getSingle(0);

public HorseValues()
{
super();

registerSingle(VARIANT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.comphenix.protocol.events.PacketContainer;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectLists;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.world.level.GameType;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -164,6 +165,15 @@ public void write(int index, Object value)
dirtySingles.put(single, value);

onTrackerWrite(index, prev, value);
sendPacketToAffectedPlayers(packetFactory.buildMetaPacket(getBindingPlayer(), this));
}

@Resolved(shouldSolveImmediately = true)
private PacketFactory packetFactory;

protected PacketFactory getPacketFactory()
{
return packetFactory;
}

protected void onTrackerWrite(int index, Object oldVal, Object newVal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public AllayWatcher(Player bindingPlayer)
@Override
protected void doSync()
{
write(ValueIndex.ALLAY.DANCING, true);
super.doSync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,4 @@ protected void doSync()
{
super.doSync();
}

@Resolved(shouldSolveImmediately = true)
private PacketFactory packetFactory;

@Override
protected void onTrackerWrite(int index, Object oldVal, Object newVal)
{
super.onTrackerWrite(index, oldVal, newVal);

if (ValueIndex.ARMOR_STAND.DATA_FLAGS.equals(getSingle(index)))
sendPacketToAffectedPlayers(packetFactory.buildMetaPacket(getBindingPlayer(), this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,4 @@ public GhastWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.GHAST);
}

@Resolved(shouldSolveImmediately = true)
private PacketFactory packetFactory;

@Override
protected void onTrackerWrite(int index, Object oldVal, Object newVal)
{
super.onTrackerWrite(index, oldVal, newVal);

if (ValueIndex.GHAST.CHARGING.equals(getSingle(index)))
sendPacketToAffectedPlayers(packetFactory.buildMetaPacket(getBindingPlayer(), this));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,4 @@ protected void doSync()

super.doSync();
}

@Resolved(shouldSolveImmediately = true)
private PacketFactory packetFactory;

@Override
protected void onCustomWrite(RegistryKey<?> key, Object oldVal, Object newVal)
{
super.onCustomWrite(key, oldVal, newVal);

if (key.equals(EntryIndex.DISPLAY_FAKE_EQUIPMENT) || key.equals(EntryIndex.EQUIPMENT))
sendPacketToAffectedPlayers(packetFactory.getEquipmentPacket(getBindingPlayer(), this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses;

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 AbstractHorseWatcher extends LivingEntityWatcher
{
@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.ABSTRACT_HORSE);
}

public AbstractHorseWatcher(Player bindingPlayer, EntityType entityType)
{
super(bindingPlayer, entityType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses;

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

public class HorseWatcher extends AbstractHorseWatcher
{
public HorseWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.HORSE);
}

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

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

import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

public class SkeletonHorseWatcher extends AbstractHorseWatcher
{
public SkeletonHorseWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.SKELETON_HORSE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.horses;

import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

public class ZombieHorseWatcher extends AbstractHorseWatcher
{
public ZombieHorseWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.ZOMBIE_HORSE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma;

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 AbstractSlimeWatcher extends LivingEntityWatcher
{
@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.SLIME_MAGMA);
}

public AbstractSlimeWatcher(Player bindingPlayer, EntityType entityType)
{
super(bindingPlayer, entityType);

}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma;

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 MagmaWatcher extends LivingEntityWatcher
public class MagmaWatcher extends AbstractSlimeWatcher
{
@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.SLIME_MAGMA);
}

public MagmaWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.MAGMA_CUBE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types;
package xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.types.slimemagma;

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 SlimeWatcher extends LivingEntityWatcher
public class SlimeWatcher extends AbstractSlimeWatcher
{
@Override
protected void initRegistry()
{
super.initRegistry();

register(ValueIndex.SLIME_MAGMA);
}

public SlimeWatcher(Player bindingPlayer)
{
super(bindingPlayer, EntityType.SLIME);
Expand Down

0 comments on commit b20f9c3

Please sign in to comment.