Skip to content

Commit

Permalink
feat: HeightEye for livingentity
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyaPeyaPeyang committed Aug 26, 2024
1 parent 2a27872 commit c57858d
Show file tree
Hide file tree
Showing 36 changed files with 54 additions and 42 deletions.
5 changes: 4 additions & 1 deletion Scenamatica/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Scenamatica/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Scenamatica/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface NMSEntityLiving extends NMSEntity
/**
* エンティティが寝ているかどうかを取得します。
*
* @return
* @return 寝ているかどうか
*/
boolean isSleeping();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
mappingOf = LivingEntity.class,

properties = {
@TypeProperty(
name = LivingEntityStructure.KEY_EYE_HEIGHT,
description = "目の高さです。",
type = double.class
),
@TypeProperty(
name = LivingEntityStructure.KEY_REMAINING_AIR,
description = "残りの空気です。",
Expand Down Expand Up @@ -124,6 +129,7 @@
)
public interface LivingEntityStructure extends EntityStructure
{
String KEY_EYE_HEIGHT = "eyeHeight";
String KEY_REMAINING_AIR = "remainAir";
String KEY_MAX_AIR = "maxAir";
String KEY_ARROW_COOLDOWN = "arrowCooldown";
Expand Down Expand Up @@ -161,6 +167,12 @@ public interface LivingEntityStructure extends EntityStructure
String KEY_JUMPING = "jumping";
String KEY_HURT_DIRECTION = "hurtDirection";

/**
* このエンティティの目の高さを取得します。
*
* @return 目の高さ
*/
Double getEyeHeight();
/**
* このエンティティの残りの空気を取得します。
*
Expand Down
5 changes: 2 additions & 3 deletions Scenamatica/ScenamaticaScenarioFile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
<scope>provided</scope>
</dependency>

<!-- ストラクチャを追加していく -->
<dependency>
<groupId>org.kunlab.scenamatica.structure</groupId>
<artifactId>StructureBase</artifactId>
<groupId>org.kunlab.scenamatica</groupId>
<artifactId>ScenamaticaStructures</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
Expand Down
20 changes: 0 additions & 20 deletions Scenamatica/ScenamaticaStructures/StructureBase/pom.xml

This file was deleted.

11 changes: 7 additions & 4 deletions Scenamatica/ScenamaticaStructures/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
<relativePath>../pom.xml</relativePath>
</parent>

<packaging>pom</packaging>
<modules>
<module>StructureBase</module>
</modules>
<artifactId>ScenamaticaStructures</artifactId>

<properties>
Expand All @@ -23,6 +19,13 @@
</properties>

<dependencies>
<!--suppress MavenDuplicateDependenciesInspection due to dependency order injection, VulnerableLibrariesLocal -->
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kunlab.scenamatica</groupId>
<artifactId>ScenamaticaModels</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@AllArgsConstructor
public class LivingEntityStructureImpl extends EntityStructureImpl implements LivingEntityStructure
{

protected final Double eyeHeight;
protected final Integer remainAir;
protected final Integer maxAir;
protected final Integer arrowCooldown;
Expand Down Expand Up @@ -72,6 +72,7 @@ public class LivingEntityStructureImpl extends EntityStructureImpl implements Li

protected LivingEntityStructureImpl(
EntityStructure original,
Double eyeHeight,
Integer remainAir,
Integer maxAir,
Integer arrowCooldown,
Expand Down Expand Up @@ -100,6 +101,7 @@ protected LivingEntityStructureImpl(
Boolean isHandRaised)
{
super(original);
this.eyeHeight = eyeHeight;
this.remainAir = remainAir;
this.maxAir = maxAir;
this.arrowCooldown = arrowCooldown;
Expand Down Expand Up @@ -138,6 +140,7 @@ protected LivingEntityStructureImpl()
null,
null,
null,
null,
PlayerSpecifierImpl.EMPTY,
Collections.emptyList(),
null,
Expand Down Expand Up @@ -169,6 +172,7 @@ protected LivingEntityStructureImpl(@NotNull EntityType type, @NotNull LivingEnt
{
super(type, original);

this.eyeHeight = original.getEyeHeight();
this.remainAir = original.getRemainAir();
this.maxAir = original.getMaxAir();
this.arrowCooldown = original.getArrowCooldown();
Expand Down Expand Up @@ -210,6 +214,7 @@ protected LivingEntityStructureImpl(@NotNull EntityType type, @NotNull LivingEnt
public static Map<String, Object> serializeLivingEntity(LivingEntityStructure entity, @NotNull StructureSerializer serializer)
{
Map<String, Object> map = EntityStructureImpl.serialize(entity, serializer);
MapUtils.putIfNotNull(map, KEY_EYE_HEIGHT, entity.getEyeHeight());
MapUtils.putIfNotNull(map, KEY_REMAINING_AIR, entity.getRemainAir());
MapUtils.putIfNotNull(map, KEY_MAX_AIR, entity.getMaxAir());
MapUtils.putIfNotNull(map, KEY_ARROW_COOLDOWN, entity.getArrowCooldown());
Expand Down Expand Up @@ -311,6 +316,7 @@ public static LivingEntityStructure deserializeLivingEntity(@NotNull Map<String,

EntityStructure base = EntityStructureImpl.deserialize(map, serializer);

Double eyeHeight = MapUtils.getOrNull(map, KEY_EYE_HEIGHT);
Integer remainAir = MapUtils.getOrNull(map, KEY_REMAINING_AIR);
Integer maxAir = MapUtils.getOrNull(map, KEY_MAX_AIR);
Integer arrowCooldown = MapUtils.getOrNull(map, KEY_ARROW_COOLDOWN);
Expand Down Expand Up @@ -349,6 +355,7 @@ public static LivingEntityStructure deserializeLivingEntity(@NotNull Map<String,

return new LivingEntityStructureImpl(
base,
eyeHeight,
remainAir,
maxAir,
arrowCooldown,
Expand Down Expand Up @@ -384,6 +391,7 @@ public static LivingEntityStructure ofLivingEntity(@NotNull LivingEntity entity)

return new LivingEntityStructureImpl(
EntityStructureImpl.of(entity),
entity.getEyeHeight(),
entity.getRemainingAir(),
entity.getMaximumAir(),
NMSProvider.doNMSSafe(nmsEntity::getArrowCooldown),
Expand Down Expand Up @@ -491,7 +499,8 @@ public boolean equals(Object o)
if (!super.equals(o)) return false;
LivingEntityStructureImpl that = (LivingEntityStructureImpl) o;

return Objects.equals(this.remainAir, that.remainAir)
return Objects.equals(this.eyeHeight, that.eyeHeight)
&& Objects.equals(this.remainAir, that.remainAir)
&& Objects.equals(this.maxAir, that.maxAir)
&& Objects.equals(this.arrowCooldown, that.arrowCooldown)
&& Objects.equals(this.arrowsInBody, that.arrowsInBody)
Expand Down Expand Up @@ -523,10 +532,10 @@ public boolean equals(Object o)
public int hashCode()
{
return Objects.hash(
super.hashCode(), this.remainAir, this.maxAir, this.arrowCooldown, this.arrowsInBody,
this.maxNoDamageTicks, this.lastDamage, this.noDamageTicks, this.killer, this.potionEffects,
this.removeWhenFarAway, this.canPickupItems, this.leashed, this.leashHolder, this.gliding,
this.swimming, this.riptiding, this.sleeping, this.ai, this.collidable, this.invisible,
super.hashCode(), this.eyeHeight, this.remainAir, this.maxAir, this.arrowCooldown,
this.arrowsInBody, this.maxNoDamageTicks, this.lastDamage, this.noDamageTicks, this.killer,
this.potionEffects, this.removeWhenFarAway, this.canPickupItems, this.leashed, this.leashHolder,
this.gliding, this.swimming, this.riptiding, this.sleeping, this.ai, this.collidable, this.invisible,
this.arrowsStuck, this.shieldBlockingDelay, this.activeItem, this.itemUseRemainTime,
this.handRaisedTime, this.isHandRaised
);
Expand Down Expand Up @@ -628,7 +637,8 @@ public boolean isAdequate(@Nullable Entity entity, boolean strict)
if (nmsArrowCooldown != null)
arrowCooldownMatches = Objects.equals(this.arrowCooldown, nmsArrowCooldown);
}
return (this.remainAir == null || this.remainAir == livingEntity.getRemainingAir())
return (this.eyeHeight == null || this.eyeHeight.equals(livingEntity.getEyeHeight()))
&& (this.remainAir == null || this.remainAir == livingEntity.getRemainingAir())
&& (this.maxAir == null || this.maxAir == livingEntity.getMaximumAir())
&& arrowCooldownMatches
&& (this.arrowsInBody == null || this.arrowsInBody == nmsEntity.getArrowCount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public <V, T extends Mapped & Structure> T toStructure(@NotNull V value, @Nullab
{
// エンティティの場合は, さらに EntityType で分岐する
if (isEntityRelatedValue(value, clazz))
return (T) SelectiveEntityStructureSerializerMock.toStructure((Entity) value, this);
return SelectiveEntityStructureSerializerMock.toStructure((Entity) value, this);

return this.selectMappedEntry(value, clazz).getConstructor().apply(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class EntityStructureSerializeTest
@Test
void 正常にシリアライズできるか()
{
Map<String, Object> map = EntityStructureImpl.serialize((EntityStructure) FULFILLED, StructureSerializerMock.getInstance());
Map<String, Object> map = EntityStructureImpl.serialize(FULFILLED, StructureSerializerMock.getInstance());

MapTestUtil.assertEqual(FULFILLED_MAP, map);
}
Expand All @@ -123,7 +123,7 @@ public class EntityStructureSerializeTest
@Test
void 必須項目のみでシリアライズできるか()
{
Map<String, Object> map = EntityStructureImpl.serialize((EntityStructure) EMPTY, StructureSerializerMock.getInstance());
Map<String, Object> map = EntityStructureImpl.serialize(EMPTY, StructureSerializerMock.getInstance());

MapTestUtil.assertEqual(EMPTY_MAP, map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class LivingEntitySerializeTest
{
public static final LivingEntityStructure FULFILLED = new LivingEntityStructureImpl(
EntityStructureSerializeTest.FULFILLED,
0.5,
114,
514,
1919,
Expand Down Expand Up @@ -47,6 +48,7 @@ public class LivingEntitySerializeTest

public static final Map<String, Object> FULFILLED_MAP = new HashMap<String, Object>(EntityStructureSerializeTest.FULFILLED_MAP)
{{
this.put("eyeHeight", 0.5d);
this.put("remainAir", 114);
this.put("maxAir", 514);
this.put("arrowCooldown", 1919);
Expand Down
2 changes: 1 addition & 1 deletion Scenamatica/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</repositories>

<dependencies>
<!--suppress MavenDuplicateDependenciesInspection due to dependency order injection -->
<!--suppress MavenDuplicateDependenciesInspection due to dependency order injection, VulnerableLibrariesLocal -->
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
Expand Down

0 comments on commit c57858d

Please sign in to comment.