use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.
the class PlatformHelper method playParticleEffect.
/**
* @param location the {@link Location} around which players must be to see the effect
* @param effectName list of effects: https://gist.github.com/riking/5759002
* @param offsetX the amount to be randomly offset by in the X axis
* @param offsetY the amount to be randomly offset by in the Y axis
* @param offsetZ the amount to be randomly offset by in the Z axis
* @param speed the speed of the particles
* @param count the number of particles
* @param radius the radius around the location
*/
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
Validate.notNull(location, "Location cannot be null");
Validate.notNull(effect, "Effect cannot be null");
Validate.notNull(location.getWorld(), "World cannot be null");
ParticleOptions particle = null;
if (effect.getDeserializer() != null && data != null) {
try {
particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
} else if (effect instanceof SimpleParticleType) {
particle = (SimpleParticleType) effect;
}
if (particle == null) {
return;
}
ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
radius = radius * radius;
for (Player player : location.getWorld().getPlayers()) {
if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
((CraftPlayer) player).getHandle().connection.send(packet);
}
}
}
use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.
the class ConfigItem method load.
@Override
public void load(MaterialHolder material, String data) {
ResourceLocation key = new ResourceLocation(material.getId());
Item item = Registry.ITEM.get(key);
// TODO AIR now?
if (item == null) {
Block block = Registry.BLOCK.get(key);
item = block.asItem();
}
if (item == null) {
return;
}
net.minecraft.world.item.ItemStack is = new net.minecraft.world.item.ItemStack(item, 1);
if (data != null) {
CompoundTag tag = null;
String nbtString = data.trim();
if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
try {
tag = TagParser.parseTag(nbtString);
} catch (Exception e) {
MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
MyPetApi.getLogger().warning(item.getDescriptionId() + " " + nbtString);
}
if (tag != null) {
is.setTag(tag);
}
}
}
this.item = CraftItemStack.asCraftMirror(is);
}
use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.
the class EntityConverterService method convertEntity.
@Override
public void convertEntity(MyPet myPet, LivingEntity normalEntity) {
if (myPet instanceof MyCreeper) {
if (((MyCreeper) myPet).isPowered()) {
((Creeper) normalEntity).setPowered(true);
}
} else if (myPet instanceof MyGoat) {
if (((MyGoat) myPet).isScreaming()) {
((Goat) normalEntity).setScreaming(true);
}
} else if (myPet instanceof MyEnderman) {
if (((MyEnderman) myPet).hasBlock()) {
((Enderman) normalEntity).setCarriedMaterial(((MyEnderman) myPet).getBlock().getData());
}
} else if (myPet instanceof MyIronGolem) {
((IronGolem) normalEntity).setPlayerCreated(true);
} else if (myPet instanceof MyMagmaCube) {
((MagmaCube) normalEntity).setSize(((MyMagmaCube) myPet).getSize());
} else if (myPet instanceof MyPig) {
((Pig) normalEntity).setSaddle(((MyPig) myPet).hasSaddle());
} else if (myPet instanceof MySheep) {
((Sheep) normalEntity).setSheared(((MySheep) myPet).isSheared());
((Sheep) normalEntity).setColor(((MySheep) myPet).getColor());
} else if (myPet instanceof MyVillager) {
MyVillager villagerPet = (MyVillager) myPet;
Villager villagerEntity = ((Villager) normalEntity);
Villager.Profession profession = Villager.Profession.values()[villagerPet.getProfession()];
Villager.Type type = Villager.Type.values()[villagerPet.getType().ordinal()];
villagerEntity.setVillagerType(type);
villagerEntity.setProfession(profession);
villagerEntity.setVillagerLevel(villagerPet.getVillagerLevel());
if (villagerPet.hasOriginalData()) {
TagCompound villagerTag = villagerPet.getOriginalData();
net.minecraft.world.entity.npc.Villager entityVillager = ((CraftVillager) villagerEntity).getHandle();
try {
if (villagerTag.containsKey("Offers")) {
TagCompound offersTag = villagerTag.get("Offers");
CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(offersTag);
entityVillager.setOffers(new MerchantOffers(vanillaNBT));
}
if (villagerTag.containsKey("Inventory")) {
TagList inventoryTag = villagerTag.get("Inventory");
ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
for (int i = 0; i < vanillaNBT.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.of(vanillaNBT.getCompound(i));
ItemStack item = CraftItemStack.asCraftMirror(itemstack);
if (!itemstack.isEmpty()) {
Villager vill = ((Villager) Bukkit.getServer().getEntity(normalEntity.getUniqueId()));
vill.getInventory().addItem(item);
}
}
}
if (villagerTag.containsKey("FoodLevel")) {
byte foodLevel = villagerTag.getAs("FoodLevel", TagByte.class).getByteData();
// Field: foodLevel
ReflectionUtil.setFieldValue("cq", entityVillager, foodLevel);
}
if (villagerTag.containsKey("Gossips")) {
TagList inventoryTag = villagerTag.get("Gossips");
ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
// This might be useful for later/following versions
// ((GossipContainer) ReflectionUtil.getFieldValue(net.minecraft.world.entity.npc.Villager.class, entityVillager, "cr")) //Field: gossips
entityVillager.getGossips().update(new Dynamic<>(NbtOps.INSTANCE, vanillaNBT));
}
if (villagerTag.containsKey("LastRestock")) {
long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData();
// Field: lastRestockGameTime
ReflectionUtil.setFieldValue("cv", entityVillager, lastRestock);
}
if (villagerTag.containsKey("LastGossipDecay")) {
long lastGossipDecay = villagerTag.getAs("LastGossipDecay", TagLong.class).getLongData();
// Field: lastGossipDecayTime
ReflectionUtil.setFieldValue("ct", entityVillager, lastGossipDecay);
}
if (villagerTag.containsKey("RestocksToday")) {
int restocksToday = villagerTag.getAs("RestocksToday", TagInt.class).getIntData();
// Field: numberOfRestocksToday
ReflectionUtil.setFieldValue("cw", entityVillager, restocksToday);
}
// Field: AssignProfessionWhenSpawned
ReflectionUtil.setFieldValue("cy", entityVillager, true);
} catch (Exception e) {
e.printStackTrace();
}
if (villagerTag.containsKey("Xp")) {
int xp = villagerTag.getAs("Xp", TagInt.class).getIntData();
entityVillager.setVillagerXp(xp);
}
}
} else if (myPet instanceof MySlime) {
((Slime) normalEntity).setSize(((MySlime) myPet).getSize());
} else if (myPet instanceof MyZombieVillager) {
Villager.Profession profession = Villager.Profession.values()[((MyZombieVillager) myPet).getProfession()];
net.minecraft.world.entity.monster.ZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle();
nmsEntity.setVillagerData(nmsEntity.getVillagerData().setType(Registry.VILLAGER_TYPE.get(new ResourceLocation(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))).setLevel(((MyZombieVillager) myPet).getTradingLevel()).setProfession(Registry.VILLAGER_PROFESSION.get(new ResourceLocation(profession.name().toLowerCase(Locale.ROOT)))));
} else if (myPet instanceof MyWitherSkeleton) {
normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD));
} else if (myPet instanceof MySkeleton) {
normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
} else if (myPet instanceof MyHorse) {
Horse.Style style = Horse.Style.values()[(((MyHorse) myPet).getVariant() >>> 8)];
Horse.Color color = Horse.Color.values()[(((MyHorse) myPet).getVariant() & 0xFF)];
((Horse) normalEntity).setColor(color);
((Horse) normalEntity).setStyle(style);
if (((MyHorse) myPet).hasSaddle()) {
((Horse) normalEntity).getInventory().setSaddle(((MyHorse) myPet).getSaddle().clone());
}
if (((MyHorse) myPet).hasArmor()) {
((Horse) normalEntity).getInventory().setArmor(((MyHorse) myPet).getArmor().clone());
}
((Horse) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MySkeletonHorse) {
((SkeletonHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MyZombieHorse) {
((ZombieHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MyLlama) {
((Llama) normalEntity).setColor(Llama.Color.values()[Math.max(0, Math.min(3, ((MyLlama) myPet).getVariant()))]);
((Llama) normalEntity).setCarryingChest(((MyLlama) myPet).hasChest());
if (((MyLlama) myPet).hasDecor()) {
((Llama) normalEntity).getInventory().setDecor(((MyLlama) myPet).getDecor());
}
((Llama) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MyRabbit) {
((Rabbit) normalEntity).setRabbitType(((MyRabbit) myPet).getVariant().getBukkitType());
} else if (myPet instanceof MyParrot) {
((Parrot) normalEntity).setVariant(Parrot.Variant.values()[((MyParrot) myPet).getVariant()]);
} else if (myPet instanceof MyAxolotl) {
((Axolotl) normalEntity).setVariant(Axolotl.Variant.values()[((MyAxolotl) myPet).getVariant()]);
} else if (myPet instanceof MyTropicalFish) {
((CraftTropicalFish) normalEntity).getHandle().setVariant(((MyTropicalFish) myPet).getVariant());
} else if (myPet instanceof MyPufferfish) {
((PufferFish) normalEntity).setPuffState(((MyPufferfish) myPet).getPuffState().ordinal());
} else if (myPet instanceof MyPhantom) {
((Phantom) normalEntity).setSize(((MyPhantom) myPet).getSize());
} else if (myPet instanceof MyCat) {
((Cat) normalEntity).setCatType(((MyCat) myPet).getCatType());
((Cat) normalEntity).setCollarColor(((MyCat) myPet).getCollarColor());
} else if (myPet instanceof MyMooshroom) {
((MushroomCow) normalEntity).setVariant(MushroomCow.Variant.values()[((MyMooshroom) myPet).getType().ordinal()]);
} else if (myPet instanceof MyPanda) {
((Panda) normalEntity).setMainGene(((MyPanda) myPet).getMainGene());
((Panda) normalEntity).setHiddenGene(((MyPanda) myPet).getHiddenGene());
} else if (myPet instanceof WanderingTrader) {
MyWanderingTrader traderPet = (MyWanderingTrader) myPet;
if (traderPet.hasOriginalData()) {
TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(normalEntity);
for (String key : traderPet.getOriginalData().getCompoundData().keySet()) {
villagerTag.put(key, traderPet.getOriginalData().get(key));
}
MyPetApi.getPlatformHelper().applyTagToEntity(villagerTag, normalEntity);
}
} else if (myPet instanceof MyBee) {
((Bee) normalEntity).setHasNectar(((MyBee) myPet).hasNectar());
((Bee) normalEntity).setHasStung(((MyBee) myPet).hasStung());
}
if (myPet instanceof MyPetBaby && normalEntity instanceof Ageable) {
if (((MyPetBaby) myPet).isBaby()) {
((Ageable) normalEntity).setBaby();
} else {
((Ageable) normalEntity).setAdult();
}
}
}
use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.
the class EntityMyZombieVillager method updateVisuals.
@Override
public void updateVisuals() {
getEntityData().set(BABY_WATCHER, getMyPet().isBaby());
String professionKey = MyVillager.Profession.values()[getMyPet().getProfession()].getKey();
VillagerProfession profession = Registry.VILLAGER_PROFESSION.get(new ResourceLocation(professionKey));
// TODO
VillagerType type = Registry.VILLAGER_TYPE.get(new ResourceLocation(getMyPet().getType().getKey()));
getEntityData().set(PROFESSION_WATCHER, new VillagerData(type, profession, getMyPet().getTradingLevel()));
Bukkit.getScheduler().runTaskLater(MyPetApi.getPlugin(), () -> {
if (getMyPet().getStatus() == MyPet.PetState.Here) {
for (EquipmentSlot slot : EquipmentSlot.values()) {
setPetEquipment(slot, CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)));
}
}
}, 5L);
}
use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.
the class ConfigItem method load.
@Override
public void load(MaterialHolder material, String data) {
ResourceLocation key = new ResourceLocation(material.getId());
Item item = Registry.ITEM.get(key);
// TODO AIR now?
if (item == null) {
Block block = Registry.BLOCK.get(key);
item = block.asItem();
}
if (item == null) {
return;
}
net.minecraft.world.item.ItemStack is = new net.minecraft.world.item.ItemStack(item, 1);
if (data != null) {
CompoundTag tag = null;
String nbtString = data.trim();
if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
try {
tag = TagParser.parseTag(nbtString);
} catch (Exception e) {
MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
MyPetApi.getLogger().warning(item.getDescriptionId() + " " + nbtString);
}
if (tag != null) {
is.setTag(tag);
}
}
}
this.item = CraftItemStack.asCraftMirror(is);
}
Aggregations