Skip to content

Commit 1080383

Browse files
fancynpcs: Add harness attribute for happy ghasts
1 parent e428d2c commit 1080383

5 files changed

Lines changed: 74 additions & 7 deletions

File tree

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ fancylibVersion=37
22
fancysitulaVersion=0.0.13
33
jdbVersion=1.0.0
44
plugintestsVersion=1.0.0
5-
6-
org.gradle.parallel=true
5+
org.gradle.parallel=false
76
org.gradle.caching=true

plugins/fancynpcs/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.0.283
1+
2.6.0.284

plugins/fancynpcs/implementation_1_21_6/src/main/java/de/oliver/fancynpcs/v1_21_6/Npc_1_21_6.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,25 @@ public void update(Player player) {
267267

268268
npc.setGlowingTag(data.isGlowing());
269269

270-
if (data.getEquipment() != null && data.getEquipment().size() > 0) {
271-
List<Pair<EquipmentSlot, ItemStack>> equipmentList = new ArrayList<>();
270+
data.applyAllAttributes(this);
272271

272+
// Set equipment
273+
List<Pair<EquipmentSlot, ItemStack>> equipmentList = new ArrayList<>();
274+
if (data.getEquipment() != null) {
273275
for (NpcEquipmentSlot slot : data.getEquipment().keySet()) {
274276
equipmentList.add(new Pair<>(EquipmentSlot.byName(slot.toNmsName()), CraftItemStack.asNMSCopy(data.getEquipment().get(slot))));
275277
}
278+
}
276279

280+
// Set body slot (from happy ghast harness attribute)
281+
if (npc instanceof LivingEntity livingEntity) {
282+
ItemStack bodySlot = livingEntity.getItemBySlot(EquipmentSlot.BODY);
283+
if (!bodySlot.isEmpty()) {
284+
equipmentList.add(new Pair<>(EquipmentSlot.BODY, bodySlot));
285+
}
286+
}
287+
288+
if (!equipmentList.isEmpty()) {
277289
ClientboundSetEquipmentPacket setEquipmentPacket = new ClientboundSetEquipmentPacket(npc.getId(), equipmentList);
278290
serverPlayer.connection.send(setEquipmentPacket);
279291
}
@@ -283,8 +295,6 @@ public void update(Player player) {
283295
npc.getEntityData().set(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION, (byte) (0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 | 0x40));
284296
}
285297

286-
data.applyAllAttributes(this);
287-
288298
refreshEntityData(player);
289299

290300
if (data.isSpawnEntity() && data.getLocation() != null) {

plugins/fancynpcs/implementation_1_21_6/src/main/java/de/oliver/fancynpcs/v1_21_6/attributes/Attributes_1_21_6.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static List<NpcAttribute> getAllAttributes() {
4242
attributes.addAll(BeeAttributes.getAllAttributes());
4343
attributes.addAll(VexAttributes.getAllAttributes());
4444
attributes.addAll(ArmadilloAttributes.getAllAttributes());
45+
attributes.addAll(HappyGhastAttributes.getAllAttributes());
4546

4647
attributes.addAll(DisplayAttributes.getAllAttributes());
4748
attributes.addAll(TextDisplayAttributes.getAllAttributes());
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package de.oliver.fancynpcs.v1_21_6.attributes;
2+
3+
import de.oliver.fancynpcs.api.Npc;
4+
import de.oliver.fancynpcs.api.NpcAttribute;
5+
import de.oliver.fancynpcs.v1_21_6.ReflectionHelper;
6+
import net.minecraft.world.entity.EquipmentSlot;
7+
import net.minecraft.world.entity.animal.HappyGhast;
8+
import net.minecraft.world.item.ItemStack;
9+
import net.minecraft.world.item.Items;
10+
import org.bukkit.entity.EntityType;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public class HappyGhastAttributes {
16+
17+
public static List<NpcAttribute> getAllAttributes() {
18+
List<NpcAttribute> attributes = new ArrayList<>();
19+
20+
attributes.add(new NpcAttribute(
21+
"harness",
22+
List.of("white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray", "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"),
23+
List.of(EntityType.HAPPY_GHAST),
24+
HappyGhastAttributes::setHarness
25+
));
26+
27+
return attributes;
28+
}
29+
30+
private static void setHarness(Npc npc, String value) {
31+
HappyGhast ghast = ReflectionHelper.getEntity(npc);
32+
33+
ItemStack harnessItem = switch (value.toLowerCase()) {
34+
case "white" -> Items.WHITE_HARNESS.getDefaultInstance();
35+
case "orange" -> Items.ORANGE_HARNESS.getDefaultInstance();
36+
case "magenta" -> Items.MAGENTA_HARNESS.getDefaultInstance();
37+
case "light_blue" -> Items.LIGHT_BLUE_HARNESS.getDefaultInstance();
38+
case "yellow" -> Items.YELLOW_HARNESS.getDefaultInstance();
39+
case "lime" -> Items.LIME_HARNESS.getDefaultInstance();
40+
case "pink" -> Items.PINK_HARNESS.getDefaultInstance();
41+
case "gray" -> Items.GRAY_HARNESS.getDefaultInstance();
42+
case "light_gray" -> Items.LIGHT_GRAY_HARNESS.getDefaultInstance();
43+
case "cyan" -> Items.CYAN_HARNESS.getDefaultInstance();
44+
case "purple" -> Items.PURPLE_HARNESS.getDefaultInstance();
45+
case "blue" -> Items.BLUE_HARNESS.getDefaultInstance();
46+
case "brown" -> Items.BROWN_HARNESS.getDefaultInstance();
47+
case "green" -> Items.GREEN_HARNESS.getDefaultInstance();
48+
case "red" -> Items.RED_HARNESS.getDefaultInstance();
49+
case "black" -> Items.BLACK_HARNESS.getDefaultInstance();
50+
default -> Items.AIR.getDefaultInstance();
51+
};
52+
53+
if (!harnessItem.isEmpty()) {
54+
ghast.setItemSlot(EquipmentSlot.BODY, harnessItem);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)