예제 #1
0
 /** 当实体走过方块时调用此方法。 */
 @Override
 public void onEntityWalking(World world, int posX, int posY, int posZ, Entity entity) {
   super.onEntityWalking(world, posX, posY, posZ, entity);
   TileEntityTrap tile = (TileEntityTrap) world.getTileEntity(posX, posY, posZ);
   if (entity instanceof EntityPlayer
       && ((EntityPlayer) entity).getDisplayName().equals(tile.ownerName)) {
     if (!world.isRemote) {
       ((EntityPlayer) entity)
           .addChatComponentMessage(
               new ChatComponentText(StatCollector.translateToLocal("keycraft.prompt.yourtrap")));
     }
   } else {
     world.removeTileEntity(posX, posY, posZ);
     world.setBlock(posX, posY, posZ, Blocks.cactus);
   }
 }
예제 #2
0
 /** 当方块被放置时调用此方法。 */
 @Override
 public void onBlockPlacedBy(
     World world, int posX, int posY, int posZ, EntityLivingBase entity, ItemStack stack) {
   super.onBlockPlacedBy(world, posX, posY, posZ, entity, stack);
   if (entity instanceof EntityPlayer) {
     EntityPlayer player = (EntityPlayer) entity;
     if (!RewriteHelper.hasSkill(player, RewriteHelper.TrapProficient.id)) {
       world.setBlockToAir(posX, posY, posZ);
       stack.stackSize++;
       if (!world.isRemote) {
         player.addChatComponentMessage(
             new ChatComponentText(StatCollector.translateToLocal("keycraft.prompt.notrapskill")));
       }
     }
   }
 }