Пример #1
0
 private TileEntityTombstone placeTombstone(EntityPlayer player) {
   Optional<ChunkCoordinates> chunkCoordinate = findValidTombstoneLocation(player);
   if (chunkCoordinate.isPresent()) {
     /* Place a Tombstone */
     player.worldObj.setBlock(
         chunkCoordinate.get().posX,
         chunkCoordinate.get().posY,
         chunkCoordinate.get().posZ,
         BlockList.tombstone.get());
     TileEntity tileEntity =
         player.worldObj.getTileEntity(
             chunkCoordinate.get().posX, chunkCoordinate.get().posY, chunkCoordinate.get().posZ);
     StringBuilder sb = new StringBuilder();
     sb.append("Tombstone summoned to mark the 'passing' of ")
         .append(player.getCommandSenderName())
         .append(" at [");
     sb.append(chunkCoordinate.get().posX).append(", ");
     sb.append(chunkCoordinate.get().posY).append(", ");
     sb.append(chunkCoordinate.get().posZ).append("]");
     player.addChatMessage(new ChatComponentText(sb.toString()));
     if (tileEntity != null && tileEntity instanceof TileEntityTombstone) {
       ProjectZuluLog.debug(Level.INFO, sb.toString());
       return (TileEntityTombstone) tileEntity;
     }
   }
   ProjectZuluLog.warning(
       "Failed to find location to place tombstone at player location {X:%s, Y:%s, Z:%s}",
       player.posX, player.posY, player.posZ);
   return null;
 }
Пример #2
0
 private boolean createGameruleIfAbsent(GameRules gameRule, String gameruleName, boolean value) {
   boolean added = false;
   if (!gameRule.hasRule(gameruleName)) {
     gameRule.addGameRule(gameruleName, Boolean.toString(value));
     added = true;
   }
   ProjectZuluLog.info(
       "Gamerule %s is set to %s", gameruleName, gameRule.getGameRuleBooleanValue(gameruleName));
   return added;
 }
Пример #3
0
  @SubscribeEvent
  public void onPlayerDeath(LivingDeathEvent event) {
    if (event.entity instanceof EntityPlayerMP) {
      GameRules gameRules = event.entity.worldObj.getGameRules();
      boolean dropInventory = gameRules.getGameRuleBooleanValue("dropInventory");
      boolean dropHotbar = gameRules.getGameRuleBooleanValue("dropHotbar");
      boolean dropArmor = gameRules.getGameRuleBooleanValue("dropArmor");
      boolean dropXP = gameRules.getGameRuleBooleanValue("dropXP");

      EntityPlayer player = (EntityPlayer) event.entity;

      TileEntityTombstone tombstone = tombstoneOnDeath ? placeTombstone(player) : null;
      if (tombstone != null) {
        tombstone.setSignString(event.source.func_151519_b((EntityPlayer) event.entity).toString());
      }

      if (!dropInventory && !dropHotbar && !dropArmor && !dropXP) {
        return;
      }

      player.captureDrops = true;
      player.capturedDrops.clear();

      /* Get items/XP to drop and clear them from Player */
      int xpDropped = 0;
      if (dropXP) {
        if (!player.worldObj.isRemote) {
          xpDropped = player.experienceTotal;
          xpDropped = xpDropped > maxDropXP ? maxDropXP : xpDropped;
          int keptXp = (player.experienceTotal - xpDropped) * percKeptXp / 100;
          redistributor.addExpereince(player, keptXp >= 0 ? keptXp : 0);
          player.experienceLevel = 0;
          player.experienceTotal = 0;
          player.experience = 0;
        }
      }

      List<ItemStack> itemsToDrop = new ArrayList<ItemStack>();
      if (dropArmor) {
        itemsToDrop.addAll(dropArmor(player));
      }

      if (dropInventory) {
        itemsToDrop.addAll(dropInventory(player));
      }

      if (dropHotbar) {
        itemsToDrop.addAll(dropHotbar(player));
      }

      dropItems(player, itemsToDrop);
      boolean isCancelled = false;
      if (doDropEvent) {
        PlayerDropsEvent dropEvent = createPlayerDropEvent(player, event.source);
        isCancelled = MinecraftForge.EVENT_BUS.post(dropEvent);
      }
      player.captureDrops = false;
      if (!isCancelled) {
        /* Handler actually Dropping Items or Placing them in Tombstone */
        if (tombstoneAbsorbDrops && tombstone != null) {
          for (EntityItem entityItem : player.capturedDrops) {
            tombstone.addDrop(entityItem.getEntityItem());
          }
          tombstone.experience = xpDropped;
        } else {
          if (tombstoneAbsorbDrops) {
            ProjectZuluLog.warning("Tombstone could not be placed so items dropping normally.");
          }
          while (xpDropped > 0) {
            int j = EntityXPOrb.getXPSplit(xpDropped);
            xpDropped -= j;
            player.worldObj.spawnEntityInWorld(
                new EntityXPOrb(player.worldObj, player.posX, player.posY, player.posZ, j));
          }
          for (EntityItem item : player.capturedDrops) {
            player.joinEntityItemWithWorld(item);
          }
        }
      } else {
        ProjectZuluLog.warning(
            "Player drop event was cancelled, so items will not be dropped per convention."
                + "Results may not desireable, consider disabling 'doDropEvent' in the config.");
      }
    }
  }