Skip to content

Commit 5004975

Browse files
committed
Add salmon type to entity_spec
1 parent 983b153 commit 5004975

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.laytonsmith.abstraction.bukkit.entities;
2+
3+
import com.laytonsmith.abstraction.entities.MCSalmon;
4+
import org.bukkit.entity.Entity;
5+
import org.bukkit.entity.Salmon;
6+
7+
public class BukkitMCSalmon extends BukkitMCLivingEntity implements MCSalmon {
8+
9+
Salmon entity;
10+
11+
public BukkitMCSalmon(Entity be) {
12+
super(be);
13+
this.entity = (Salmon) be;
14+
}
15+
16+
@Override
17+
public Variant getVariant() {
18+
return Variant.valueOf(this.entity.getVariant().name());
19+
}
20+
21+
@Override
22+
public void setVariant(Variant size) {
23+
this.entity.setVariant(Salmon.Variant.valueOf(size.name()));
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.laytonsmith.abstraction.entities;
2+
3+
import com.laytonsmith.abstraction.MCLivingEntity;
4+
5+
public interface MCSalmon extends MCLivingEntity {
6+
7+
Variant getVariant();
8+
void setVariant(Variant size);
9+
10+
enum Variant {
11+
SMALL,
12+
MEDIUM,
13+
LARGE
14+
}
15+
16+
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.laytonsmith.abstraction.entities.MCProjectile;
8181
import com.laytonsmith.abstraction.entities.MCPufferfish;
8282
import com.laytonsmith.abstraction.entities.MCRabbit;
83+
import com.laytonsmith.abstraction.entities.MCSalmon;
8384
import com.laytonsmith.abstraction.entities.MCSheep;
8485
import com.laytonsmith.abstraction.entities.MCShulker;
8586
import com.laytonsmith.abstraction.entities.MCShulkerBullet;
@@ -2258,6 +2259,12 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
22582259
MCRabbit rabbit = (MCRabbit) entity;
22592260
specArray.set(entity_spec.KEY_RABBIT_TYPE, new CString(rabbit.getRabbitType().name(), t), t);
22602261
break;
2262+
case SALMON:
2263+
MCSalmon salmon = (MCSalmon) entity;
2264+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_3)) {
2265+
specArray.set(entity_spec.KEY_SALMON_TYPE, new CString(salmon.getVariant().name(), t), t);
2266+
}
2267+
break;
22612268
case SHEEP:
22622269
MCSheep sheep = (MCSheep) entity;
22632270
specArray.set(entity_spec.KEY_SHEEP_COLOR, new CString(sheep.getColor().name(), t), t);
@@ -2525,6 +2532,7 @@ public MSVersion since() {
25252532
private static final String KEY_RABBIT_TYPE = "type";
25262533
private static final String KEY_PRIMED_TNT_FUSETICKS = "fuseticks";
25272534
private static final String KEY_PRIMED_TNT_SOURCE = "source";
2535+
private static final String KEY_SALMON_TYPE = "type";
25282536
private static final String KEY_SHEEP_COLOR = "color";
25292537
private static final String KEY_SHEEP_SHEARED = "sheared";
25302538
private static final String KEY_SHULKER_COLOR = "color";
@@ -3695,6 +3703,24 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
36953703
}
36963704
}
36973705
break;
3706+
case SALMON:
3707+
MCSalmon salmon = (MCSalmon) entity;
3708+
for(String index : specArray.stringKeySet()) {
3709+
switch(index.toLowerCase()) {
3710+
case entity_spec.KEY_SALMON_TYPE:
3711+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_3)) {
3712+
try {
3713+
salmon.setVariant(MCSalmon.Variant.valueOf(specArray.get(index, t).val()));
3714+
} catch (IllegalArgumentException exception) {
3715+
throw new CREFormatException("Invalid salmon type: " + specArray.get(index, t).val(), t);
3716+
}
3717+
}
3718+
break;
3719+
default:
3720+
throwException(index, t);
3721+
}
3722+
}
3723+
break;
36983724
case SHEEP:
36993725
MCSheep sheep = (MCSheep) entity;
37003726
for(String index : specArray.stringKeySet()) {

src/main/resources/functionDocs/entity_spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ without knowing the rotations on the other axis or of other body parts beforehan
268268
|
269269
* %KEY_RABBIT_TYPE%: The type of the rabbit (can be %RABBIT_TYPE%).
270270
|-
271+
| SALMON
272+
|
273+
* %KEY_SALMON_TYPE%: The size type of salmon. Must be one of the sizes: SMALL, MEDIUM, or LARGE. (MC 1.21.3+)
274+
|-
271275
| SHEEP
272276
|
273277
* %KEY_SHEEP_COLOR%: The color of the sheep (can be %DYE_COLOR%).
@@ -290,7 +294,7 @@ without knowing the rotations on the other axis or of other body parts beforehan
290294
|-
291295
| SLIME
292296
|
293-
* %KEY_SLIME_SIZE%: The size of the slime.
297+
* %KEY_SLIME_SIZE%: The size of the slime. Must be an integer (0 - 126) where 0 is small, 1 is medium, and 3 is large.
294298
|-
295299
| SNOWMAN
296300
|

0 commit comments

Comments
 (0)