use of net.minecraft.world.WorldServer in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class AttackEntity method attackTargetEntityWithCurrentItem.
/**
* Slightly modified {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)} for off hand
* @param player The player
* @param targetEntity The entity to attack
*/
public void attackTargetEntityWithCurrentItem(EntityPlayer player, Entity targetEntity) {
if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget(player, targetEntity))
return;
if (targetEntity.canBeAttackedWithItem()) {
if (!targetEntity.hitByEntity(player)) {
// float f = (float)player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
float f = DamageCalculation.getStrengthDamage(player, (ItemKeyblade) player.getHeldItemOffhand().getItem());
// f += (float)(player.getCapability(ModCapabilities.PLAYER_STATS, null).getStrength() + ((ItemKeyblade)player.getHeldItemOffhand().getItem()).getStrength());
float f1;
if (targetEntity instanceof EntityLivingBase) {
f1 = EnchantmentHelper.getModifierForCreature(player.getHeldItemOffhand(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
} else {
f1 = EnchantmentHelper.getModifierForCreature(player.getHeldItemOffhand(), EnumCreatureAttribute.UNDEFINED);
}
if (player.getHeldItemMainhand().getItem() instanceof ItemKeyblade) {
// f -= 3;
}
// player.getCooledAttackStrength(0.5F);
float f2 = 1;
f = f * (0.2F + f2 * f2 * 0.8F);
f1 = f1 * f2;
player.resetCooldown();
if (f > 0.0F || f1 > 0.0F) {
boolean flag = f2 > 0.9F;
boolean flag1 = false;
int i = 0;
i = i + EnchantmentHelper.getKnockbackModifier(player);
if (player.isSprinting() && flag) {
player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, player.getSoundCategory(), 1.0F, 1.0F);
++i;
flag1 = true;
}
boolean flag2 = flag && player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(MobEffects.BLINDNESS) && !player.isRiding() && targetEntity instanceof EntityLivingBase;
flag2 = flag2 && !player.isSprinting();
if (flag2) {
f *= 1.5F;
}
f = f + f1;
boolean flag3 = false;
double d0 = (double) (player.distanceWalkedModified - player.prevDistanceWalkedModified);
if (flag && !flag2 && !flag1 && player.onGround && d0 < (double) player.getAIMoveSpeed()) {
ItemStack itemstack = player.getHeldItem(EnumHand.OFF_HAND);
if (itemstack.getItem() instanceof ItemKeyblade) {
flag3 = true;
}
}
float f4 = 0.0F;
boolean flag4 = false;
int j = EnchantmentHelper.getFireAspectModifier(player);
if (targetEntity instanceof EntityLivingBase) {
f4 = ((EntityLivingBase) targetEntity).getHealth();
if (j > 0 && !targetEntity.isBurning()) {
flag4 = true;
targetEntity.setFire(1);
}
}
double d1 = targetEntity.motionX;
double d2 = targetEntity.motionY;
double d3 = targetEntity.motionZ;
DamageSource playerDamage = DamageSource.causePlayerDamage(player);
playerDamage.damageType = EnumHand.OFF_HAND.name();
boolean flag5 = targetEntity.attackEntityFrom(playerDamage, f);
if (flag5) {
if (i > 0) {
if (targetEntity instanceof EntityLivingBase) {
((EntityLivingBase) targetEntity).knockBack(player, (float) i * 0.5F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F)));
} else {
targetEntity.addVelocity((double) (-MathHelper.sin(player.rotationYaw * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(player.rotationYaw * 0.017453292F) * (float) i * 0.5F));
}
player.motionX *= 0.6D;
player.motionZ *= 0.6D;
player.setSprinting(false);
}
if (flag3) {
float f3 = 1.0F + EnchantmentHelper.getSweepingDamageRatio(player) * f;
for (EntityLivingBase entitylivingbase : player.world.getEntitiesWithinAABB(EntityLivingBase.class, targetEntity.getEntityBoundingBox().grow(1.0D, 0.25D, 1.0D))) {
if (entitylivingbase != player && entitylivingbase != targetEntity && !player.isOnSameTeam(entitylivingbase) && player.getDistanceSqToEntity(entitylivingbase) < 9.0D) {
entitylivingbase.knockBack(player, 0.4F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F)));
entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(player), f3);
}
}
player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, player.getSoundCategory(), 1.0F, 1.0F);
player.spawnSweepParticles();
}
if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
((EntityPlayerMP) targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
targetEntity.velocityChanged = false;
targetEntity.motionX = d1;
targetEntity.motionY = d2;
targetEntity.motionZ = d3;
}
if (flag2) {
player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, player.getSoundCategory(), 1.0F, 1.0F);
player.onCriticalHit(targetEntity);
}
if (!flag2 && !flag3) {
if (flag) {
player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, player.getSoundCategory(), 1.0F, 1.0F);
} else {
player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, player.getSoundCategory(), 1.0F, 1.0F);
}
}
if (f1 > 0.0F) {
player.onEnchantmentCritical(targetEntity);
}
player.setLastAttackedEntity(targetEntity);
if (targetEntity instanceof EntityLivingBase) {
EnchantmentHelper.applyThornEnchantments((EntityLivingBase) targetEntity, player);
}
EnchantmentHelper.applyArthropodEnchantments(player, targetEntity);
ItemStack itemstack1 = player.getHeldItemOffhand();
Entity entity = targetEntity;
if (targetEntity instanceof MultiPartEntityPart) {
IEntityMultiPart ientitymultipart = ((MultiPartEntityPart) targetEntity).parent;
if (ientitymultipart instanceof EntityLivingBase) {
entity = (EntityLivingBase) ientitymultipart;
}
}
if (!itemstack1.isEmpty() && entity instanceof EntityLivingBase) {
ItemStack beforeHitCopy = itemstack1.copy();
itemstack1.hitEntity((EntityLivingBase) entity, player);
if (itemstack1.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, beforeHitCopy, EnumHand.OFF_HAND);
player.setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY);
}
}
if (targetEntity instanceof EntityLivingBase) {
float f5 = f4 - ((EntityLivingBase) targetEntity).getHealth();
player.addStat(StatList.DAMAGE_DEALT, Math.round(f5 * 10.0F));
if (j > 0) {
targetEntity.setFire(j * 4);
}
if (player.world instanceof WorldServer && f5 > 2.0F) {
int k = (int) ((double) f5 * 0.5D);
((WorldServer) player.world).spawnParticle(EnumParticleTypes.DAMAGE_INDICATOR, targetEntity.posX, targetEntity.posY + (double) (targetEntity.height * 0.5F), targetEntity.posZ, k, 0.1D, 0.0D, 0.1D, 0.2D);
}
}
player.addExhaustion(0.1F);
} else {
player.world.playSound((EntityPlayer) null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, player.getSoundCategory(), 1.0F, 1.0F);
if (flag4) {
targetEntity.extinguish();
}
}
}
}
}
}
use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class FindBlockAction method performServer.
@Override
public void performServer(EntityPlayer player, World world, @Nullable BlockPos pos, boolean extended) {
if (pos != null) {
// If we come here we know that on client side we couldn't find a suitable block in the players inventory.
List<ItemStack> inventory = Collections.unmodifiableList(player.inventory.mainInventory);
IBlockState state = world.getBlockState(pos);
ItemStack result = state.getBlock().getItem(world, pos, state);
if (result == null || result.isEmpty()) {
return;
}
ItemStack storage = ItemStack.EMPTY;
for (ItemStack stack : inventory) {
if (!stack.isEmpty()) {
if (stack.getItem() == ModularStorageSetup.storageModuleTabletItem) {
// Found!
storage = stack;
break;
}
}
}
if (storage.isEmpty()) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "No storage tablet in inventory!"), false);
return;
}
NBTTagCompound tagCompound = storage.getTagCompound();
if (tagCompound == null || !tagCompound.hasKey("childDamage")) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "No storage module in tablet!"), false);
return;
}
int firstEmptyStack = player.inventory.getFirstEmptyStack();
if (firstEmptyStack < 0) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "No room in inventory for block!"), false);
return;
}
int moduleDamage = tagCompound.getInteger("childDamage");
ItemStack extracted = ItemStack.EMPTY;
if (moduleDamage == META_FOR_SCANNER) {
if (tagCompound.hasKey("monitorx")) {
int monitordim = tagCompound.getInteger("monitordim");
int monitorx = tagCompound.getInteger("monitorx");
int monitory = tagCompound.getInteger("monitory");
int monitorz = tagCompound.getInteger("monitorz");
BlockPos mpos = new BlockPos(monitorx, monitory, monitorz);
WorldServer w = DimensionManager.getWorld(monitordim);
if (w == null || !RFToolsTools.chunkLoaded(w, mpos)) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Storage scanner is out of range!"), false);
} else {
TileEntity te = w.getTileEntity(mpos);
if (te instanceof StorageScannerTileEntity) {
StorageScannerTileEntity scanner = (StorageScannerTileEntity) te;
extracted = scanner.requestItem(result, result.getMaxStackSize(), true, false);
if (extracted.isEmpty()) {
extracted = scanner.requestItem(result, result.getMaxStackSize(), true, true);
}
}
}
} else {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Storage module is not linked to a storage scanner!"), false);
}
} else if (moduleDamage == StorageModuleItem.STORAGE_REMOTE) {
if (!tagCompound.hasKey("id")) {
Logging.message(player, TextFormatting.YELLOW + "This remote storage module is not linked!");
} else {
RemoteStorageItemInventory storageInv = new RemoteStorageItemInventory(player, storage);
for (int i = 0; i < storageInv.getSizeInventory(); i++) {
ItemStack s = storageInv.getStackInSlot(i);
if (!s.isEmpty() && stackEqualExact(result, s)) {
extracted = s;
storageInv.setInventorySlotContents(i, ItemStack.EMPTY);
break;
}
}
}
} else {
ModularStorageItemInventory storageInv = new ModularStorageItemInventory(player, storage);
for (int i = 0; i < storageInv.getSizeInventory(); i++) {
ItemStack s = storageInv.getStackInSlot(i);
if (!s.isEmpty() && stackEqualExact(result, s)) {
extracted = s;
storageInv.setInventorySlotContents(i, ItemStack.EMPTY);
break;
}
}
}
if (!extracted.isEmpty()) {
int currentItem = player.inventory.currentItem;
if (currentItem == firstEmptyStack) {
player.inventory.setInventorySlotContents(currentItem, extracted);
} else {
player.inventory.setInventorySlotContents(firstEmptyStack, inventory.get(currentItem));
player.inventory.setInventorySlotContents(currentItem, extracted);
}
player.openContainer.detectAndSendChanges();
}
}
}
use of net.minecraft.world.WorldServer in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class UsernameHandler method ServerChat.
@SubscribeEvent
public void ServerChat(ServerChatEvent event) {
if (event.getPlayer() != null) {
if (this.usernamePropsRegistry.containsKey(event.getUsername())) {
EntityPlayer player = event.getPlayer();
event.setCanceled(true);
String nameFormat = "\u00A7f";
String chatFormat = "\u00A7f";
String prefixFormat = "\u00A7f";
String prefix = "";
String prefixWithFormat = "";
if (this.usernamePropsRegistry.get(event.getUsername()).containsKey("nameformat"))
nameFormat = this.usernamePropsRegistry.get(event.getUsername()).get("nameformat");
if (this.usernamePropsRegistry.get(event.getUsername()).containsKey("chatformat"))
chatFormat = this.usernamePropsRegistry.get(event.getUsername()).get("chatformat");
if (this.usernamePropsRegistry.get(event.getUsername()).containsKey("prefixformat"))
prefixFormat = this.usernamePropsRegistry.get(event.getUsername()).get("prefixformat");
if (this.usernamePropsRegistry.get(event.getUsername()).containsKey("prefix"))
prefix = this.usernamePropsRegistry.get(event.getUsername()).get("prefix");
if (!prefix.isEmpty())
prefixWithFormat = "[" + prefixFormat + prefix + TextFormatting.WHITE + "] ";
String nameWithFormat = TextFormatting.WHITE + "<" + nameFormat + player.getDisplayNameString() + TextFormatting.WHITE + "> ";
TextComponentTranslation message = new TextComponentTranslation(prefixWithFormat + nameWithFormat + chatFormat + event.getMessage().replaceAll("%", "%%"));
List<EntityPlayer> players = null;
for (WorldServer world : DimensionManager.getWorlds()) {
for (EntityPlayer target : world.playerEntities) {
target.sendMessage(message);
}
}
LogManager.getLogger().info(message.getUnformattedText());
}
}
}
use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class StorageTools method returnStorageInfo.
public static void returnStorageInfo(EntityPlayer player, int dimension, BlockPos pos) {
WorldServer world = DimensionManager.getWorld(dimension);
int cnt = -1;
String nameModule = "";
if (world != null) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof ModularStorageTileEntity) {
ModularStorageTileEntity modularStorageTileEntity = (ModularStorageTileEntity) te;
cnt = modularStorageTileEntity.getNumStacks();
ItemStack storageModule = modularStorageTileEntity.getStackInSlot(ModularStorageContainer.SLOT_STORAGE_MODULE);
if (!storageModule.isEmpty() && storageModule.getTagCompound().hasKey("display")) {
nameModule = storageModule.getDisplayName();
}
}
}
RFToolsMessages.sendToClient(player, ClientCommandHandler.CMD_RETURN_STORAGE_INFO, Arguments.builder().value(cnt).value(nameModule));
}
use of net.minecraft.world.WorldServer in project RFTools by McJty.
the class DialingDeviceTileEntity method changeFavorite.
// Server side only.
private void changeFavorite(String playerName, BlockPos receiver, int dimension, boolean favorite) {
List<EntityPlayerMP> list = ((WorldServer) getWorld()).getMinecraftServer().getPlayerList().getPlayers();
for (EntityPlayerMP entityplayermp : list) {
if (playerName.equals(entityplayermp.getName())) {
FavoriteDestinationsProperties favoriteDestinations = PlayerExtendedProperties.getFavoriteDestinations(entityplayermp);
favoriteDestinations.setDestinationFavorite(new GlobalCoordinate(receiver, dimension), favorite);
return;
}
}
}
Aggregations