- 51
- 8
- 5
Помогите, пожалуйста, мне надо в методе tryEnterExoskeleton при телепортации игрока на позицию сущности, с которой взаимодействовал игрок, поворачивать тело и голову игрока так, как это было у сущности, но я не знаю, как это сделать
Java:
package com.afp.utils;
import com.afp.entities.EntityExoskeleton;
import com.afp.items.ArmorExo;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World;
public class EntityExoskeletonHandler {
private static final SoundEvent EXO_CLICK_SOUND = SoundEvent.REGISTRY.getObject(new net.minecraft.util.ResourceLocation("afp", "exo_click"));
private static final SoundEvent POWERON_SOUND = SoundEvent.REGISTRY.getObject(new net.minecraft.util.ResourceLocation("afp", "poweron"));
private static final EntityEquipmentSlot[] ARMOR_SLOTS = {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
public static void handleInteraction(World world, EntityPlayer player, EnumHand hand, EntityExoskeleton.Exoskeleton entity, EntityEquipmentSlot clickedSlot) {
ItemStack heldStack = player.getHeldItem(hand);
if (!heldStack.isEmpty()) {
tryInstallPart(world, player, hand, entity, clickedSlot, heldStack);
} else {
tryUninstallPart(world, player, hand, entity, clickedSlot);
}
}
private static void tryInstallPart(World world, EntityPlayer player, EnumHand hand, EntityExoskeleton.Exoskeleton entity, EntityEquipmentSlot slot, ItemStack heldStack) {
String itemId = heldStack.getItem().getRegistryName().toString();
int colonIndex = itemId.indexOf(':');
if (colonIndex == -1) return;
String itemPath = itemId.substring(colonIndex + 1);
int underscoreIndex = itemPath.indexOf('_');
if (underscoreIndex == -1) return;
String armorType = itemPath.substring(0, underscoreIndex);
String armorPart = itemPath.substring(underscoreIndex + 1);
if (!getSlotPart(slot).equals(armorPart)) return;
ItemStack currentArmor = entity.getItemStackFromSlot(slot);
if (currentArmor.isEmpty() || !isBaseExoArmor(currentArmor, slot)) return;
if (!checkArmorCompatibility(entity, armorType)) return;
ItemStack newArmor = heldStack.copy();
newArmor.setCount(1);
entity.setItemStackToSlot(slot, newArmor);
if (!player.isCreative()) {
heldStack.shrink(1);
if (heldStack.isEmpty()) {
player.setHeldItem(hand, ItemStack.EMPTY);
}
}
world.playSound(null, entity.posX, entity.posY, entity.posZ, EXO_CLICK_SOUND, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
private static void tryUninstallPart(World world, EntityPlayer player, EnumHand hand, EntityExoskeleton.Exoskeleton entity, EntityEquipmentSlot slot) {
ItemStack currentArmor = entity.getItemStackFromSlot(slot);
ItemStack chestArmor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (isBaseExoArmor(currentArmor, slot)) return;
if (!isSealed(chestArmor)) {
if (slot == EntityEquipmentSlot.CHEST) {
tryEnterExoskeleton(world, player, entity);
}
return;
}
player.setHeldItem(hand, currentArmor.copy());
entity.setItemStackToSlot(slot, getBaseArmorForSlot(slot));
world.playSound(null, entity.posX, entity.posY, entity.posZ, EXO_CLICK_SOUND, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
private static void tryEnterExoskeleton(World world, EntityPlayer player, EntityExoskeleton.Exoskeleton entity) {
for (EntityEquipmentSlot slot : ARMOR_SLOTS) {
if (!player.getItemStackFromSlot(slot).isEmpty()) {
return;
}
}
for (EntityEquipmentSlot slot : ARMOR_SLOTS) {
ItemStack armorStack = entity.getItemStackFromSlot(slot);
if (!isBaseExoArmor(armorStack, slot) && !armorStack.isEmpty()) {
player.setItemStackToSlot(slot, armorStack.copy());
entity.setItemStackToSlot(slot, getBaseArmorForSlot(slot));
}
}
world.playSound(null, entity.posX, entity.posY, entity.posZ, POWERON_SOUND, SoundCategory.PLAYERS, 1.0F, 1.0F);
if (isCore(entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST))) {
world.playSound(null, entity.posX, entity.posY, entity.posZ, POWERON_SOUND, SoundCategory.PLAYERS, 1.0F, 1.0F);
}
if (player.isRiding()) {
player.dismountRidingEntity();
}
player.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
entity.setDead();
}
private static boolean isBaseExoArmor(ItemStack stack, EntityEquipmentSlot slot) {
Item item = stack.getItem();
switch(slot) {
case HEAD: return item == ArmorExo.helmet;
case CHEST: return item == ArmorExo.body;
case LEGS: return item == ArmorExo.legs;
case FEET: return item == ArmorExo.boots;
default: return false;
}
}
private static boolean isSealed(ItemStack stack) {
if (stack.isEmpty()) return false;
NBTTagCompound tag = stack.getTagCompound();
return tag != null && tag.getBoolean("sealed");
}
private static boolean isCore(ItemStack stack) {
if (stack.isEmpty()) return false;
NBTTagCompound tag = stack.getTagCompound();
return tag != null && tag.getBoolean("core");
}
private static String getSlotPart(EntityEquipmentSlot slot) {
switch(slot) {
case HEAD: return "helmet";
case CHEST: return "chestplate";
case LEGS: return "leggings";
case FEET: return "boots";
default: return "";
}
}
private static ItemStack getBaseArmorForSlot(EntityEquipmentSlot slot) {
switch(slot) {
case HEAD: return new ItemStack(ArmorExo.helmet);
case CHEST: return new ItemStack(ArmorExo.body);
case LEGS: return new ItemStack(ArmorExo.legs);
case FEET: return new ItemStack(ArmorExo.boots);
default: return ItemStack.EMPTY;
}
}
private static boolean checkArmorCompatibility(EntityExoskeleton.Exoskeleton entity, String newType) {
for (EntityEquipmentSlot slot : ARMOR_SLOTS) {
ItemStack armorStack = entity.getItemStackFromSlot(slot);
if (armorStack.isEmpty() || isBaseExoArmor(armorStack, slot)) continue;
String armorId = armorStack.getItem().getRegistryName().toString();
int colonIndex = armorId.indexOf(':');
if (colonIndex == -1) continue;
String armorPath = armorId.substring(colonIndex + 1);
int underscoreIndex = armorPath.indexOf('_');
if (underscoreIndex == -1) continue;
String armorType = armorPath.substring(0, underscoreIndex);
if (!armorType.equals(newType)) return false;
}
return true;
}
}